summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-07-04 15:55:33 +0200
committerGitHub <noreply@github.com>2019-07-04 15:55:33 +0200
commit550f436f8fbea86984a845c821270fba78189143 (patch)
tree93985664212af0602cea06547273015ee580acc2 /core/math
parent7b569e91c0c6b84965cad416b8e86dcfdacbcfc4 (diff)
parent3380dc963895d1f97d4f06c3a71fe15d1c04d9fe (diff)
Merge pull request #30263 from Faless/ws/wslay_pr
Use wslay as a WebSocket library
Diffstat (limited to 'core/math')
-rw-r--r--core/math/crypto_core.cpp11
-rw-r--r--core/math/crypto_core.h1
2 files changed, 12 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;
diff --git a/core/math/crypto_core.h b/core/math/crypto_core.h
index 1cb3c86e18..e28cb5a792 100644
--- a/core/math/crypto_core.h
+++ b/core/math/crypto_core.h
@@ -79,6 +79,7 @@ public:
Error decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]);
};
+ static String b64_encode_str(const uint8_t *p_src, int p_src_len);
static Error b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);
static Error b64_decode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);