From 89f58d0a7ac546a95d3f5358dc8c2f0d122c1bd7 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 19 Sep 2014 19:25:40 -0400 Subject: [PATCH] read extended indentities from hosts.txt --- AddressBook.cpp | 10 +++------- Identity.cpp | 27 ++++++++++++++------------- Identity.h | 6 +++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index a61cc96c..948d7a0c 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -87,13 +87,9 @@ namespace data std::string name = s.substr(0, pos++); std::string addr = s.substr(pos); - Identity ident; - if (!ident.FromBase64(addr)) - { - LogPrint ("hosts.txt: ignore ", name); - continue; - } - m_Addresses[name] = ident.Hash(); + IdentityEx ident; + ident.FromBase64(addr); + m_Addresses[name] = ident.GetIdentHash (); numAddresses++; } } diff --git a/Identity.cpp b/Identity.cpp index a238bccf..f06176a7 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -22,18 +22,19 @@ namespace data return *this; } - bool Identity::FromBase64 (const std::string& s) - { - size_t count = Base64ToByteStream (s.c_str(), s.length(), publicKey, DEFAULT_IDENTITY_SIZE); - return count == DEFAULT_IDENTITY_SIZE; - } - size_t Identity::FromBuffer (const uint8_t * buf, size_t len) { memcpy (publicKey, buf, DEFAULT_IDENTITY_SIZE); return DEFAULT_IDENTITY_SIZE; } + IdentHash Identity::Hash () const + { + IdentHash hash; + CryptoPP::SHA256().CalculateDigest(hash, publicKey, DEFAULT_IDENTITY_SIZE); + return hash; + } + IdentityEx::IdentityEx (): m_Verifier (nullptr), m_ExtendedLen (0), m_ExtendedBuffer (nullptr) { @@ -151,6 +152,13 @@ namespace data memcpy (buf + DEFAULT_IDENTITY_SIZE, m_ExtendedBuffer, m_ExtendedLen); return GetFullLen (); } + + size_t IdentityEx::FromBase64(const std::string& s) + { + uint8_t buf[512]; + auto len = Base64ToByteStream (s.c_str(), s.length(), buf, 512); + return FromBuffer (buf, len); + } size_t IdentityEx::GetSigningPublicKeyLen () const { @@ -194,13 +202,6 @@ namespace data LogPrint ("Signing key type ", (int)keyType, " is not supported"); } } - - IdentHash Identity::Hash() const - { - IdentHash hash; - CryptoPP::SHA256().CalculateDigest(hash, publicKey, DEFAULT_IDENTITY_SIZE); - return hash; - } PrivateKeys& PrivateKeys::operator=(const Keys& keys) { diff --git a/Identity.h b/Identity.h index f2ccdc82..e352ddb5 100644 --- a/Identity.h +++ b/Identity.h @@ -101,9 +101,8 @@ namespace data Identity () = default; Identity (const Keys& keys) { *this = keys; }; Identity& operator=(const Keys& keys); - bool FromBase64(const std::string& ); size_t FromBuffer (const uint8_t * buf, size_t len); - IdentHash Hash() const; + IdentHash Hash () const; }; const size_t DEFAULT_IDENTITY_SIZE = sizeof (Identity); // 387 bytes @@ -124,7 +123,8 @@ namespace data ~IdentityEx (); IdentityEx& operator=(const IdentityEx& other); IdentityEx& operator=(const Identity& standard); - + + size_t FromBase64(const std::string& s); size_t FromBuffer (const uint8_t * buf, size_t len); size_t ToBuffer (uint8_t * buf, size_t len) const; const Identity& GetStandardIdentity () const { return m_StandardIdentity; };