Set pointers to const where possible in API

This commit is contained in:
Stephen Seo 2020-01-10 20:28:08 +09:00
parent f588d409c9
commit b41639c568
3 changed files with 19 additions and 14 deletions

View file

@ -446,7 +446,7 @@ void UDPC_client_initiate_connection(
* \param size The size in bytes of the data to be sent
*/
void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
int isChecked, void *data, uint32_t size);
int isChecked, const void *data, uint32_t size);
/*!
* \brief Gets the size of the data structure holding queued packets
@ -475,6 +475,11 @@ unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx);
* UDPC_update() will lock this mutex, regardless of whether or not the context
* is using threaded update).
*
* If \p exists is a non-null pointer to an \p int, and a connection to a peer
* identified by \p id exists, then the value of \p exists will be set to
* non-zero, otherwise a non-existing peer will set the value of \p exists to
* zero.
*
* \return The size of a connection's queue
*/
unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists);
@ -625,15 +630,15 @@ UDPC_Event UDPC_get_event(UDPC_HContext ctx, unsigned long *remaining);
UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining);
int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk);
int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk);
int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk);
int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk);
int UDPC_unset_libsodium_keys(UDPC_HContext ctx);
int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
int UDPC_remove_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
int UDPC_clear_whitelist(UDPC_HContext ctx);
int UDPC_get_auth_policy(UDPC_HContext ctx);

View file

@ -84,7 +84,7 @@ struct IPV6_Hasher {
struct PKContainer {
PKContainer();
PKContainer(unsigned char *pk);
PKContainer(const unsigned char *pk);
unsigned char pk[crypto_sign_PUBLICKEYBYTES];

View file

@ -69,7 +69,7 @@ UDPC::PKContainer::PKContainer() {
std::memset(pk, 0, crypto_sign_PUBLICKEYBYTES);
}
UDPC::PKContainer::PKContainer(unsigned char *pk) {
UDPC::PKContainer::PKContainer(const unsigned char *pk) {
std::memcpy(this->pk, pk, crypto_sign_PUBLICKEYBYTES);
}
@ -2117,7 +2117,7 @@ void UDPC_client_initiate_connection(
}
void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
int isChecked, void *data, uint32_t size) {
int isChecked, const void *data, uint32_t size) {
if(size == 0 || !data) {
return;
}
@ -2325,7 +2325,7 @@ UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining) {
}
}
int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk) {
int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c || !c->flags.test(2)) {
return 0;
@ -2338,7 +2338,7 @@ int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char
return 1;
}
int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk) {
int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk) {
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
if(crypto_sign_ed25519_sk_to_pk(pk, sk) != 0) {
return 0;
@ -2358,7 +2358,7 @@ int UDPC_unset_libsodium_keys(UDPC_HContext ctx) {
return 1;
}
int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c || !c->flags.test(2)) {
return 0;
@ -2372,7 +2372,7 @@ int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
return 0;
}
int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c || !c->flags.test(2)) {
return 0;
@ -2385,7 +2385,7 @@ int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
return 0;
}
int UDPC_remove_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c || !c->flags.test(2)) {
return 0;