Add mud_get_key()

This commit is contained in:
angt
2016-04-26 06:50:04 +00:00
parent 3b7853c9ba
commit 7e5c487951
2 changed files with 15 additions and 1 deletions

14
mud.c
View File

@@ -521,9 +521,21 @@ int mud_bind (struct mud *mud, const char *name)
return 0; return 0;
} }
int mud_get_key (struct mud *mud, unsigned char *key, size_t size)
{
if (size < MUD_KEY_SIZE) {
errno = EINVAL;
return -1;
}
memcpy(key, mud->crypto.key, MUD_KEY_SIZE);
return 0;
}
int mud_set_key (struct mud *mud, unsigned char *key, size_t size) int mud_set_key (struct mud *mud, unsigned char *key, size_t size)
{ {
if (size != MUD_KEY_SIZE) { if (size < MUD_KEY_SIZE) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }

2
mud.h
View File

@@ -8,6 +8,8 @@ struct mud *mud_create (const char *, int, int);
void mud_delete (struct mud *); void mud_delete (struct mud *);
int mud_set_key (struct mud *, unsigned char *, size_t); int mud_set_key (struct mud *, unsigned char *, size_t);
int mud_get_key (struct mud *, unsigned char *, size_t);
int mud_get_fd (struct mud *); int mud_get_fd (struct mud *);
void mud_set_send_timeout_msec (struct mud *, unsigned); void mud_set_send_timeout_msec (struct mud *, unsigned);