Files
funstraw/crypto.h

47 lines
1.2 KiB
C
Raw Normal View History

#include <event2/bufferevent.h>
#include <event2/event.h>
#include <event2/listener.h>
2015-02-05 16:36:25 +00:00
2015-02-05 12:55:48 +00:00
#include <string>
class CryptoBase {
public:
virtual ~CryptoBase() {};
2015-02-05 16:36:25 +00:00
static void GenKey(std::string* key);
static void GenKeyPair(std::string* secret_key, std::string* public_key);
2015-02-05 16:36:25 +00:00
};
class CryptoPubServerConnection : public CryptoBase {
2015-02-05 16:36:25 +00:00
public:
CryptoPubServerConnection(struct bufferevent* bev, const std::string secret_key);
~CryptoPubServerConnection();
static void OnReadable(struct bufferevent* bev, void* this__);
static void OnError(struct bufferevent* bev, const short what, void* this__);
2015-02-05 16:36:25 +00:00
private:
struct bufferevent* bev_;
2015-02-05 16:36:25 +00:00
const std::string secret_key_;
const std::string ephemeral_secret_key_;
const std::string client_public_key_;
enum {
AWAITING_HANDSHAKE,
READY,
} state_;
2015-02-05 16:36:25 +00:00
};
class CryptoPubServer : public CryptoBase {
public:
CryptoPubServer(const std::string secret_key);
2015-02-05 16:36:25 +00:00
~CryptoPubServer();
static void OnNewConn(struct evconnlistener* listener, int fd, struct sockaddr* client_addr, int client_addrlen, void* this__);
2015-02-05 16:36:25 +00:00
void Loop();
private:
struct event_base *event_base_;
struct evconnlistener *listener_;
2015-02-05 16:36:25 +00:00
const std::string secret_key_;
2015-02-05 12:55:48 +00:00
};