From 69256839ac3b2c8a00a2c08efb0acded3ca17a00 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 27 Nov 2019 20:12:57 +0900 Subject: [PATCH] Minor fixes/refactorings --- src/UDPConnection.cpp | 11 ++++++++--- src/UDPConnection.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/UDPConnection.cpp b/src/UDPConnection.cpp index b8ddc83..f82901e 100644 --- a/src/UDPConnection.cpp +++ b/src/UDPConnection.cpp @@ -1879,6 +1879,7 @@ void UDPC_destroy(UDPC_HContext ctx) { delete[] optE.value().v.pk; } } + UDPC_ctx->_contextIdentifier = 0; delete UDPC_ctx; } } @@ -1977,7 +1978,8 @@ int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting) { if(!c) { return 0; } - return c->isAcceptNewConnections.exchange(isAccepting == 0 ? false : true); + return c->isAcceptNewConnections.exchange(isAccepting == 0 ? false : true) + ? 1 : 0; } void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr) { @@ -2131,14 +2133,17 @@ int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk) { return UDPC_set_libsodium_keys(ctx, sk, pk); } -void UDPC_unset_libsodium_keys(UDPC_HContext ctx) { +int UDPC_unset_libsodium_keys(UDPC_HContext ctx) { UDPC::Context *c = UDPC::verifyContext(ctx); if(!c || !c->flags.test(2)) { - return; + return 0; } std::lock_guard lock(c->mutex); c->keysSet.store(false); + std::memset(c->pk, 0, crypto_sign_PUBLICKEYBYTES); + std::memset(c->sk, 0, crypto_sign_SECRETKEYBYTES); + return 1; } const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId) { diff --git a/src/UDPConnection.h b/src/UDPConnection.h index b96873e..0257729 100644 --- a/src/UDPConnection.h +++ b/src/UDPConnection.h @@ -190,7 +190,7 @@ int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk); -void UDPC_unset_libsodium_keys(UDPC_HContext ctx); +int UDPC_unset_libsodium_keys(UDPC_HContext ctx); const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId);