diff options
author | Neel Chauhan <neel@neelc.org> | 2016-11-09 20:01:26 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2016-11-10 11:00:50 -0500 |
commit | 9f74f8f732113ff1c63ed971e13229c523ed5a51 (patch) | |
tree | 42dfe33898fbf2632174a2a7e1aa33c82b0d9970 /src/or/torcert.c | |
parent | 0980787f91cfc420f02dead3fea99882ab8c2ada (diff) | |
download | tor-9f74f8f732113ff1c63ed971e13229c523ed5a51.tar.gz tor-9f74f8f732113ff1c63ed971e13229c523ed5a51.zip |
Move encode_cert to torcert.c and rename it to tor_cert_encode_ed22519()
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/torcert.c')
-rw-r--r-- | src/or/torcert.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/or/torcert.c b/src/or/torcert.c index 852def9ef6..856076844b 100644 --- a/src/or/torcert.c +++ b/src/or/torcert.c @@ -647,3 +647,44 @@ or_handshake_certs_check_both(int severity, } } +/* === ENCODING === */ + +/* Encode the ed25519 certificate <b>cert</b> and put the newly allocated + * string in <b>cert_str_out</b>. Return 0 on success else a negative value. */ +int +tor_cert_encode_ed22519(const tor_cert_t *cert, char **cert_str_out) +{ + int ret = -1; + char *ed_cert_b64 = NULL; + size_t ed_cert_b64_len; + + tor_assert(cert); + tor_assert(cert_str_out); + + /* Get the encoded size and add the NUL byte. */ + ed_cert_b64_len = base64_encode_size(cert->encoded_len, + BASE64_ENCODE_MULTILINE) + 1; + ed_cert_b64 = tor_malloc_zero(ed_cert_b64_len); + + /* Base64 encode the encoded certificate. */ + if (base64_encode(ed_cert_b64, ed_cert_b64_len, + (const char *) cert->encoded, cert->encoded_len, + BASE64_ENCODE_MULTILINE) < 0) { + log_err(LD_BUG, "Couldn't base64-encode ed22519 cert!"); + goto err; + } + + /* Put everything together in a NUL terminated string. */ + tor_asprintf(cert_str_out, + "-----BEGIN ED25519 CERT-----\n" + "%s" + "-----END ED25519 CERT-----", + ed_cert_b64); + /* Success! */ + ret = 0; + + err: + tor_free(ed_cert_b64); + return ret; +} + |