summaryrefslogtreecommitdiffstats
path: root/widget/android/Base64UtilsSupport.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /widget/android/Base64UtilsSupport.h
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--widget/android/Base64UtilsSupport.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/widget/android/Base64UtilsSupport.h b/widget/android/Base64UtilsSupport.h
new file mode 100644
index 0000000000..8ac4347aaa
--- /dev/null
+++ b/widget/android/Base64UtilsSupport.h
@@ -0,0 +1,52 @@
+/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef Base64UtilsSupport_h__
+#define Base64UtilsSupport_h__
+
+#include "mozilla/Base64.h"
+#include "mozilla/java/Base64UtilsNatives.h"
+
+namespace mozilla {
+namespace widget {
+
+class Base64UtilsSupport final
+ : public java::Base64Utils::Natives<Base64UtilsSupport> {
+ public:
+ static jni::ByteArray::LocalRef Decode(jni::String::Param data) {
+ if (!data) {
+ return nullptr;
+ }
+
+ FallibleTArray<uint8_t> bytes;
+ if (NS_FAILED(Base64URLDecode(
+ data->ToCString(), Base64URLDecodePaddingPolicy::Ignore, bytes))) {
+ return nullptr;
+ }
+
+ return jni::ByteArray::New((const signed char*)bytes.Elements(),
+ bytes.Length());
+ }
+
+ static jni::String::LocalRef Encode(jni::ByteArray::Param data) {
+ if (!data) {
+ return nullptr;
+ }
+
+ nsTArray<int8_t> bytes = data->GetElements();
+ nsCString result;
+ if (NS_FAILED(
+ Base64URLEncode(data->Length(), (const uint8_t*)bytes.Elements(),
+ Base64URLEncodePaddingPolicy::Omit, result))) {
+ return nullptr;
+ }
+ return jni::StringParam(result);
+ }
+};
+
+} // namespace widget
+} // namespace mozilla
+
+#endif // Base64UtilsSupport_h__