diff --git a/crypto.cc b/crypto.cc index 89fa86c..16f49b5 100644 --- a/crypto.cc +++ b/crypto.cc @@ -130,11 +130,11 @@ std::ostream& CryptoBase::LogFatal(void *obj) { } -CryptoConnBase::CryptoConnBase(const std::string& secret_key) +CryptoPubConnBase::CryptoPubConnBase(const std::string& secret_key) : secret_key_(secret_key), state_(AWAITING_HANDSHAKE) {} -std::unique_ptr CryptoConnBase::BuildSecureHandshake() { +std::unique_ptr CryptoPubConnBase::BuildSecureHandshake() { std::string ephemeral_public_key; CryptoUtil::GenKeyPair(&ephemeral_secret_key_, &ephemeral_public_key); @@ -143,7 +143,7 @@ std::unique_ptr CryptoConnBase::BuildSecureHandshake() { return CryptoUtil::EncodeEncrypt(secret_key_, peer_public_key_, secure_handshake); } -bool CryptoConnBase::HandleSecureHandshake(const TLVNode& node) { +bool CryptoPubConnBase::HandleSecureHandshake(const TLVNode& node) { assert(node.GetType() == TLV_TYPE_ENCRYPTED); std::unique_ptr decrypted(CryptoUtil::DecryptDecode(secret_key_, peer_public_key_, node)); @@ -165,12 +165,12 @@ bool CryptoConnBase::HandleSecureHandshake(const TLVNode& node) { return true; } -void CryptoConnBase::OnReadable_(struct bufferevent* bev, void* this__) { - auto this_ = (CryptoConnBase*)this__; +void CryptoPubConnBase::OnReadable_(struct bufferevent* bev, void* this__) { + auto this_ = (CryptoPubConnBase*)this__; this_->OnReadable(); } -void CryptoConnBase::OnReadable() { +void CryptoPubConnBase::OnReadable() { char buf[UINT16_MAX]; int bytes = bufferevent_read(bev_, buf, UINT16_MAX); const std::string input(buf, bytes); @@ -249,7 +249,7 @@ void CryptoPubServer::Loop() { CryptoPubServerConnection::CryptoPubServerConnection(struct bufferevent* bev, const std::string& secret_key) - : CryptoConnBase(secret_key) { + : CryptoPubConnBase(secret_key) { bev_ = bev; } @@ -315,7 +315,7 @@ void CryptoPubServerConnection::OnError(const short what) { CryptoPubClient::CryptoPubClient(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key, const std::list& channel_bitrates) - : CryptoConnBase(secret_key), + : CryptoPubConnBase(secret_key), event_base_(event_base_new()), channel_bitrates_(channel_bitrates) { bev_ = bufferevent_socket_new(event_base_, -1, BEV_OPT_CLOSE_ON_FREE); diff --git a/crypto.h b/crypto.h index 64c554e..cad01f2 100644 --- a/crypto.h +++ b/crypto.h @@ -26,9 +26,9 @@ class CryptoBase { std::ostream& LogFatal(void *obj=nullptr); }; -class CryptoConnBase : public CryptoBase { +class CryptoPubConnBase : public CryptoBase { protected: - CryptoConnBase(const std::string& secret_key); + CryptoPubConnBase(const std::string& secret_key); std::unique_ptr BuildSecureHandshake(); bool HandleSecureHandshake(const TLVNode& node); @@ -69,7 +69,7 @@ class CryptoPubServer : public CryptoBase { const std::string secret_key_; }; -class CryptoPubServerConnection : public CryptoConnBase { +class CryptoPubServerConnection : public CryptoPubConnBase { public: CryptoPubServerConnection(struct bufferevent* bev, const std::string& secret_key); ~CryptoPubServerConnection(); @@ -86,7 +86,7 @@ class CryptoPubServerConnection : public CryptoConnBase { friend CryptoPubServer; }; -class CryptoPubClient : public CryptoConnBase { +class CryptoPubClient : public CryptoPubConnBase { public: CryptoPubClient(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key, const std::list& channel_bitrates); ~CryptoPubClient();