]> git.seodisparate.com - UDPConnection/commitdiff
Add set_libsodium_key_easy(), fixes/refactorings
authorStephen Seo <seo.disparate@gmail.com>
Wed, 27 Nov 2019 10:41:38 +0000 (19:41 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 27 Nov 2019 10:41:38 +0000 (19:41 +0900)
src/UDPConnection.cpp
src/UDPConnection.h

index 1d28083d8ea347820959b5896c1c214e8da39252..d57cdac1d2dc55fcf12c3758fa535a92b2c12bf9 100644 (file)
@@ -2103,16 +2103,25 @@ UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining) {
     return UDPC::get_empty_pinfo();
 }
 
-void UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk) {
+int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c || !c->flags.test(2)) {
-        return;
+        return 0;
     }
 
     std::lock_guard<std::mutex> lock(c->mutex);
     std::memcpy(c->sk, sk, crypto_sign_SECRETKEYBYTES);
     std::memcpy(c->pk, pk, crypto_sign_PUBLICKEYBYTES);
     c->keysSet.store(true);
+    return 1;
+}
+
+int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk) {
+    unsigned char pk[crypto_sign_PUBLICKEYBYTES];
+    if(crypto_sign_ed25519_sk_to_pk(pk, sk) != 0) {
+        return 0;
+    }
+    return UDPC_set_libsodium_keys(ctx, sk, pk);
 }
 
 void UDPC_unset_libsodium_keys(UDPC_HContext ctx) {
index 3180681dc3f1c9c94eb46105a02b85b2af43c1fc..eb95ef63b59b4ac721b725cf808af34c1df975aa 100644 (file)
@@ -184,7 +184,9 @@ UDPC_Event UDPC_get_event(UDPC_HContext ctx, unsigned long *remaining);
 
 UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining);
 
-void UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk);
+int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk);
+
+int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk);
 
 void UDPC_unset_libsodium_keys(UDPC_HContext ctx);