Add unset_libsodium_keys()

Still untested
This commit is contained in:
Stephen Seo 2019-11-21 12:23:40 +09:00
parent 240ed9821f
commit c24273ea65
2 changed files with 13 additions and 0 deletions

View file

@ -2084,11 +2084,22 @@ void UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char
return;
}
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);
}
void UDPC_unset_libsodium_keys(UDPC_HContext ctx) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c || !c->flags.test(2)) {
return;
}
std::lock_guard<std::mutex> lock(c->mutex);
c->keysSet.store(false);
}
const char *UDPC_atostr_cid(UDPC_HContext ctx, UDPC_ConnectionId connectionId) {
return UDPC_atostr(ctx, connectionId.addr);
}

View file

@ -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);