Remove unnessecary functions in SSLObj, add comments to SSLObj and update docs

This commit is contained in:
Noah Laptop 2019-08-14 11:12:06 -07:00
parent c6ac76be27
commit c832294902
55 changed files with 1669 additions and 345 deletions

View file

@ -12,7 +12,7 @@ struct ssl_pem_decode_state {
size_t index = 0;
};
static void ssl_pem_decode(void *dest_ctx, const void *src, size_t len) {
static void ssl_pem_decode_callback(void *dest_ctx, const void *src, size_t len) {
ssl_pem_decode_state* ctx = static_cast<ssl_pem_decode_state*>(dest_ctx);
for (size_t i = 0; i < len; i++) ctx->vect->emplace_back(static_cast<const unsigned char*>(src)[i]);
// update index
@ -31,7 +31,7 @@ const std::vector<unsigned char> SSLObj::make_vector_pem(const char* data, const
state.vect = &temp;
state.index = 0;
// set the byte reciever
br_pem_decoder_setdest(&pctx, &ssl_pem_decode, &state);
br_pem_decoder_setdest(&pctx, &ssl_pem_decode_callback, &state);
// start decoding!
int br_state = 0;
size_t index = 0;
@ -52,14 +52,4 @@ const std::vector<unsigned char> SSLObj::make_vector_pem(const char* data, const
}
// else we're good!
return temp;
}
const std::vector<unsigned char> SSLObj::make_vector_der(const char* data, const size_t len) {
if (data == nullptr || len == 0) return {};
// create a temporary vector
std::vector<unsigned char> temp(len);
// copy the elements over
for (size_t i = 0; i < len; i++) temp[i] = data[i];
// return the new SSLObj
return temp;
}

View file

@ -41,13 +41,23 @@
* which allow BearSSL use client certificates when creating a TLS connection. Since
* most certificates are transmitted over the internet in PEM format, a certificate can
* be provided in PEM or DER format, and will be converted internally to DER format for
* later use. A PEM file provided to this class MUST CONTAIN the `----BEGIN ... -----`
* header in order to be parsed correctly.
* later use.
*/
namespace SSLObj {
/**
* @brief Convert a PEM buffer into a vector of raw DER bytes
*
* This function takes a PEM buffer (e.g. `----BEGIN CERTIFICATE...`) and converts
* it into a vector of raw bytes. The bytes given to this function must:
* * Contain both the `-----BEGIN XXX-----` and `-----END XXX-----` strings. These are
* removed during processing.
* * Have a base64 encoded body
* * Only contain a single object (certificate, private key, etc.).
*
* @returns The raw bytes decoded from the PEM file.
*/
const std::vector<unsigned char> make_vector_pem(const char* data, const size_t len);
const std::vector<unsigned char> make_vector_der(const char* data, const size_t len);
}
#endif