summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2022-06-10 20:20:26 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-06-13 21:49:39 +0000
commitb8544e962b698979bb81ef06f4a8e3dcdf654a35 (patch)
tree4cd83753209875ad3c2dab8d352da335ab5d61c0 /include
parent606ff61be661ec90e16110360790dd1abb13e205 (diff)
downloadchrome-ec-b8544e962b698979bb81ef06f4a8e3dcdf654a35.tar.gz
base64: add implementation for encoding binary into base64
In the Cr50 tree there is no really output devices other than console where base64 encoding output could be sent, and there is no use for decoding function yet. Add the encoding function implementation, make it possible to send output to console by default and optionally to a passed in function. Add test to verify proper encoding. BUG=b:234745585 TEST='make run-base64' succeeds. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: Ibc10681632bc649320d602e319e4f634b4b3a1d1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3701141 Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/base64.h24
-rw-r--r--include/config.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/include/base64.h b/include/base64.h
new file mode 100644
index 0000000000..f64c78ebee
--- /dev/null
+++ b/include/base64.h
@@ -0,0 +1,24 @@
+#ifndef __CR50_INCLUDE_B64_H
+#define __CR50_INCLUDE_B64_H
+/* Copyright 2022 The Chromium OS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+
+#include "util.h"
+
+/*
+ * A function to print base64 encoding of a binary blob on the console.
+ *
+ * For testing purposed an alternative output function could be supplied.
+ *
+ * @param data - pointer to data to encode.
+ * @param size - size of the data area
+ * @param func - optional, function to pass to the characters to print. If
+ * NULL the output is printed on the console.
+ */
+void base64_encode_to_console(const uint8_t *data, size_t size,
+ void (*func)(char c));
+
+#endif /* ! __CR50_INCLUDE_B64_H */
diff --git a/include/config.h b/include/config.h
index f48a640d68..19a4552f2a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -323,6 +323,9 @@
/* Support base32 text encoding */
#undef CONFIG_BASE32
+/* Support base64 text encoding */
+#undef CONFIG_BASE64
+
/*****************************************************************************/
/* Battery config */