aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-04-25 05:29:43 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-04-25 05:29:49 +0200
commitd71fe129b83f34b46136070fcf9a64865203be14 (patch)
treebd5d6bb47274f4a1e6e89a29f06498689e470505 /tests
parent13718f15767db6774dbf562b6798838ad9058984 (diff)
Store opendht identity in storage file (cached)
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index d509972..3f23b32 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include <chrono>
#include <thread>
+#include <opendht.h>
using namespace std;
using namespace chrono_literals;
@@ -108,9 +109,30 @@ void testEncryption()
assertEquals(0, strncmp(message, (const char*)decryption.getDecryptedText().data, messageLength));
}
+void testCachedIdentity()
+{
+ pair<shared_ptr<dht::crypto::PrivateKey>, shared_ptr<dht::crypto::Certificate>> identity = dht::crypto::generateIdentity();
+ dht::Blob privateKeyData = identity.first->serialize();
+ printf("Private key size: %d, serialized data: %s\n", privateKeyData.size(), Hash(privateKeyData.data(), privateKeyData.size()).toString().c_str());
+
+ dht::crypto::PrivateKey privateKeyDeserialized(privateKeyData);
+ privateKeyData = identity.first->serialize();
+ printf("Private key size: %d, serialized data: %s\n", privateKeyData.size(), Hash(privateKeyData.data(), privateKeyData.size()).toString().c_str());
+
+ dht::Blob certificateData;
+ identity.second->pack(certificateData);
+ printf("Certificate data size: %d, serialized data: %s\n", certificateData.size(), Hash(certificateData.data(), certificateData.size()).toString().c_str());
+
+ dht::crypto::Certificate certificateDeserialized(certificateData);
+ certificateData.clear();
+ identity.second->pack(certificateData);
+ printf("Certificate data size: %d, serialized data: %s\n", certificateData.size(), Hash(certificateData.data(), certificateData.size()).toString().c_str());
+}
+
int main()
{
Log::debug("Starting tests...");
+ testCachedIdentity();
testBinHexConvert();
testHash();
testEncryption();