From: Stephen Seo Date: Thu, 21 Nov 2019 03:23:40 +0000 (+0900) Subject: Add unset_libsodium_keys() X-Git-Tag: 1.0~120 X-Git-Url: https://git.seodisparate.com/stephenseo/search/main.js?a=commitdiff_plain;h=c24273ea6528cc7109658cd856f0e31b2e24fe0b;p=UDPConnection Add unset_libsodium_keys() Still untested --- diff --git a/src/UDPConnection.cpp b/src/UDPConnection.cpp index d5f10bd..1f84798 100644 --- a/src/UDPConnection.cpp +++ b/src/UDPConnection.cpp @@ -2084,11 +2084,22 @@ void UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char return; } + std::lock_guard lock(c->mutex); std::memcpy(c->sk, sk, crypto_sign_SECRETKEYBYTES); std::memcpy(c->pk, pk, crypto_sign_PUBLICKEYBYTES); c->keysSet.store(true); } +void UDPC_unset_libsodium_keys(UDPC_HContext ctx) { + UDPC::Context *c = UDPC::verifyContext(ctx); + if(!c || !c->flags.test(2)) { + return; + } + + std::lock_guard lock(c->mutex); + c->keysSet.store(false); +} + const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId) { return UDPC_atostr(ctx, connectionId.addr); } diff --git a/src/UDPConnection.h b/src/UDPConnection.h index 0a229cd..3180681 100644 --- a/src/UDPConnection.h +++ b/src/UDPConnection.h @@ -186,6 +186,8 @@ 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); +void UDPC_unset_libsodium_keys(UDPC_HContext ctx); + const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId); const char *UDPC_atostr(UDPC_HContext ctx, UDPC_IPV6_ADDR_TYPE addr);