Skip to content

armgit / ente

Public Imported from GitHub
0

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

Abstract

Manav Rathie29c9288c08f
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index c1244a6853..704e41d7f8 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -1,42 +1,43 @@
/** Careful when adding add other imports! */
import * as libsodium from "./libsodium";
-import type { DecryptB64, EncryptBytes, EncryptJSON } from "./types";
+import type {
+ DecryptB64,
+ EncryptBytes,
+ EncryptedB64,
+ EncryptedBytes,
+ EncryptJSON,
+} from "./types";
+
+const EncryptedBytesToB64 = async ({
+ encryptedData,
+ decryptionHeaderB64,
+}: EncryptedBytes): Promise<EncryptedB64> => ({
+ encryptedDataB64: await libsodium.toB64(encryptedData),
+ decryptionHeaderB64,
+});
export const _encryptAssociatedData = libsodium.encryptChaChaOneShot;
export const _encryptThumbnail = _encryptAssociatedData;
-export const _encryptFileEmbedding = async (r: EncryptBytes) => {
- const { encryptedData, decryptionHeaderB64 } =
- await _encryptAssociatedData(r);
- return {
- encryptedDataB64: await libsodium.toB64(encryptedData),
- decryptionHeaderB64,
- };
-};
+export const _encryptFileEmbedding = (r: EncryptBytes) =>
+ _encryptAssociatedData(r).then(EncryptedBytesToB64);
export const _encryptMetadata = async ({ jsonValue, keyB64 }: EncryptJSON) => {
const data = new TextEncoder().encode(JSON.stringify(jsonValue));
-
- const { encryptedData, decryptionHeaderB64 } = await _encryptAssociatedData(
- { data, keyB64 },
- );
- return {
- encryptedDataB64: await libsodium.toB64(encryptedData),
- decryptionHeaderB64,
- };
+ return EncryptedBytesToB64(await _encryptAssociatedData({ data, keyB64 }));
};
export const _decryptAssociatedData = libsodium.decryptChaChaOneShot;
export const _decryptThumbnail = _decryptAssociatedData;
-export const _decryptFileEmbedding = async ({
+export const _decryptMetadataBytes = async ({
encryptedDataB64,
decryptionHeaderB64,
keyB64,
}: DecryptB64) =>
- _decryptAssociatedData({
+ await _decryptAssociatedData({
encryptedData: await libsodium.fromB64(encryptedDataB64),
decryptionHeaderB64,
keyB64,
@@ -47,13 +48,4 @@ export const _decryptMetadata = async (r: DecryptB64) =>
new TextDecoder().decode(await _decryptMetadataBytes(r)),
) as unknown;
-export const _decryptMetadataBytes = async ({
- encryptedDataB64,
- decryptionHeaderB64,
- keyB64,
-}: DecryptB64) =>
- await _decryptAssociatedData({
- encryptedData: await libsodium.fromB64(encryptedDataB64),
- decryptionHeaderB64,
- keyB64,
- });
+export const _decryptFileEmbedding = _decryptMetadataBytes;