Implement _getdns_decode_base64() for GnuTLS.

Use primitives in libnettle.
This commit is contained in:
Jim Hague 2018-12-12 15:00:03 +00:00
parent 0dec4a6f21
commit b51c7384e6
1 changed files with 14 additions and 1 deletions

View File

@ -32,6 +32,8 @@
*/ */
#include "context.h" #include "context.h"
#include <nettle/base64.h>
#include "types-internal.h" #include "types-internal.h"
#include "pubkey-pinning.h" #include "pubkey-pinning.h"
@ -49,5 +51,16 @@ _getdns_associate_upstream_with_connection(_getdns_tls_connection *conn,
getdns_return_t _getdns_decode_base64(const char* str, uint8_t* res, size_t res_size) getdns_return_t _getdns_decode_base64(const char* str, uint8_t* res, size_t res_size)
{ {
return GETDNS_RETURN_GENERIC_ERROR; struct base64_decode_ctx ctx;
uint8_t* lim = res + res_size;
base64_decode_init(&ctx);
for(; *str != '\0' && res < lim; ++str) {
int r = base64_decode_single(&ctx, res, *str);
if (r == -1 )
return GETDNS_RETURN_GENERIC_ERROR;
res += r;
}
return (res == lim) ? GETDNS_RETURN_GOOD : GETDNS_RETURN_GENERIC_ERROR;
} }