Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

The other way

Manav Rathi485614166d0d
diff --git a/web/packages/shared/crypto/internal/libsodium.ts b/web/packages/shared/crypto/internal/libsodium.ts
index ee0c5feff0..1c18052e56 100644
--- a/web/packages/shared/crypto/internal/libsodium.ts
+++ b/web/packages/shared/crypto/internal/libsodium.ts
@@ -398,16 +398,35 @@ export async function toB64(input: Uint8Array) {
return sodium.to_base64(input, sodium.base64_variants.ORIGINAL);
}
+/** Convert a {@link Uint8Array} to a URL safe Base64 encoded string. */
export const toB64URLSafe = async (input: Uint8Array) => {
await sodium.ready;
return sodium.to_base64(input, sodium.base64_variants.URLSAFE);
};
+/**
+ * Convert a {@link Uint8Array} to a URL safe Base64 encoded string.
+ *
+ * This differs from {@link toB64URLSafe} in that it does not append any
+ * trailing padding character(s) "=" to make the resultant string's length be an
+ * integer multiple of 4.
+ */
export const toB64URLSafeNoPadding = async (input: Uint8Array) => {
await sodium.ready;
return sodium.to_base64(input, sodium.base64_variants.URLSAFE_NO_PADDING);
};
+/**
+ * Convert a Base64 encoded string to a {@link Uint8Array}.
+ *
+ * This is the converse of {@link toB64URLSafeNoPadding}, and does not expect
+ * its input string's length to be a an integer multiple of 4.
+ */
+export const fromB64URLSafeNoPadding = async (input: string) => {
+ await sodium.ready;
+ return sodium.from_base64(input, sodium.base64_variants.URLSAFE_NO_PADDING);
+};
+
export async function fromUTF8(input: string) {
await sodium.ready;
return sodium.from_string(input);