This commit is contained in:
Manav Rathi
2024-08-17 21:02:34 +05:30
parent 68e5d842e5
commit 757ff5cd9a
3 changed files with 31 additions and 1 deletions

View File

@@ -1,6 +1,11 @@
/** Careful when adding add other imports! */
import * as libsodium from "./libsodium";
import type { BytesOrB64, DecryptBlobB64, EncryptJSON } from "./types";
import type {
BytesOrB64,
DecryptBlobB64,
EncryptedBlob_2,
EncryptJSON,
} from "./types";
export const _encryptBoxB64 = libsodium.encryptBoxB64;
@@ -55,6 +60,14 @@ export const _decryptAssociatedDataB64 = async ({
keyB64,
});
export const _decryptMetadataJSON_New = async (
blob: EncryptedBlob_2,
key: BytesOrB64,
) =>
JSON.parse(
new TextDecoder().decode(await _decryptBlob(blob, key)),
) as unknown;
export const _decryptMetadataJSON = async (r: DecryptBlobB64) =>
JSON.parse(
new TextDecoder().decode(await _decryptAssociatedDataB64(r)),

View File

@@ -183,6 +183,22 @@ export const decryptBlobB64 = (blob: EncryptedBlob_2, key: BytesOrB64) =>
export const decryptThumbnail = (blob: EncryptedBlob_2, key: BytesOrB64) =>
assertInWorker(ei._decryptThumbnail(blob, key));
/**
* Decrypt the metadata JSON encrypted using {@link encryptMetadataJSON}.
*
* @returns The decrypted JSON value. Since TypeScript does not have a native
* JSON type, we need to return it as an `unknown`.
*/
export const decryptMetadataJSON_New = (
blob: EncryptedBlob_2,
key: BytesOrB64,
) =>
inWorker()
? ei._decryptMetadataJSON_New(blob, key)
: sharedCryptoWorker().then((w) =>
w.decryptMetadataJSON_New(blob, key),
);
/**
* Decrypt the metadata JSON associated with an Ente object.
*

View File

@@ -19,6 +19,7 @@ export class CryptoWorker {
decryptBoxB64 = ei._decryptBoxB64;
decryptBlobB64 = ei._decryptBlobB64;
decryptThumbnail = ei._decryptThumbnail;
decryptMetadataJSON_New = ei._decryptMetadataJSON_New;
decryptMetadataJSON = ei._decryptMetadataJSON;
// TODO: -- AUDIT BELOW --