diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-07-02 17:47:34 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2019-07-03 18:42:46 +0200 |
commit | 24c52f1c2e6a9726142bc816a79339e99bebd862 (patch) | |
tree | 5fe17d79f91e3dc08229284661ff42e2ed74fe8c /core/math/crypto_core.cpp | |
parent | 6c512e21a981cbbad93cc0ed6ec718105876f367 (diff) | |
download | redot-engine-24c52f1c2e6a9726142bc816a79339e99bebd862.tar.gz |
Add b64 to string helper in CryptoCore
Diffstat (limited to 'core/math/crypto_core.cpp')
-rw-r--r-- | core/math/crypto_core.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/math/crypto_core.cpp b/core/math/crypto_core.cpp index 6449d94db8..d7ba54e469 100644 --- a/core/math/crypto_core.cpp +++ b/core/math/crypto_core.cpp @@ -120,6 +120,17 @@ Error CryptoCore::AESContext::decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst } // CryptoCore +String CryptoCore::b64_encode_str(const uint8_t *p_src, int p_src_len) { + int b64len = p_src_len / 3 * 4 + 4 + 1; + PoolVector<uint8_t> b64buff; + b64buff.resize(b64len); + PoolVector<uint8_t>::Write w64 = b64buff.write(); + size_t strlen = 0; + int ret = b64_encode(&w64[0], b64len, &strlen, p_src, p_src_len); + w64[strlen] = 0; + return ret ? String() : (const char *)&w64[0]; +} + Error CryptoCore::b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len) { int ret = mbedtls_base64_encode(r_dst, p_dst_len, r_len, p_src, p_src_len); return ret ? FAILED : OK; |