We need both

This commit is contained in:
Manav Rathi
2024-08-17 18:49:41 +05:30
parent 890ed7dd4b
commit d1b7177a53
4 changed files with 21 additions and 8 deletions

View File

@@ -31,6 +31,8 @@ export const _encryptMetadataJSON = ({ jsonValue, keyB64 }: EncryptJSON) =>
keyB64,
});
export const _decryptBox = libsodium.decryptBox2;
export const _decryptBoxB64 = libsodium.decryptBoxB64;
export const _decryptAssociatedData = libsodium.decryptBlob;

View File

@@ -142,8 +142,15 @@ export const encryptMetadataJSON = async (r: EncryptJSON) =>
: sharedCryptoWorker().then((w) => w.encryptMetadataJSON(r));
/**
* Decrypt a box encrypted using {@link encryptBoxB64}, and return the result as
* a base64 string.
* Decrypt a box encrypted using {@link encryptBoxB64}.
*/
export const decryptBox = (box: EncryptedBox2, key: BytesOrB64) =>
inWorker()
? ei._decryptBox(box, key)
: sharedCryptoWorker().then((w) => w.decryptBox(box, key));
/**
* Variant of {@link decryptBoxlink} that returns the result as a base64 string.
*/
export const decryptBoxB64 = (box: EncryptedBox2, key: BytesOrB64) =>
inWorker()

View File

@@ -380,12 +380,7 @@ export const decryptBox = async ({
/**
* Decrypt the result of {@link encryptBoxB64}.
*/
export const decryptBoxB64 = (
box: EncryptedBox2,
key: BytesOrB64,
): Promise<string> => _decryptBox(box, key).then(toB64);
export const _decryptBox = async (
export const decryptBox2 = async (
{ encryptedData, nonce }: EncryptedBox2,
key: BytesOrB64,
): Promise<Uint8Array> => {
@@ -397,6 +392,14 @@ export const _decryptBox = async (
);
};
/**
* Variant of {@link decryptBox} that returns the data as a base64 string.
*/
export const decryptBoxB64 = (
box: EncryptedBox2,
key: BytesOrB64,
): Promise<string> => decryptBox2(box, key).then(toB64);
/**
* Decrypt the result of {@link encryptBlob}.
*/

View File

@@ -15,6 +15,7 @@ export class CryptoWorker {
encryptBoxB64 = ei._encryptBoxB64;
encryptThumbnail = ei._encryptThumbnail;
encryptMetadataJSON = ei._encryptMetadataJSON;
decryptBox = ei._decryptBox;
decryptBoxB64 = ei._decryptBoxB64;
decryptThumbnail = ei._decryptThumbnail;
decryptAssociatedDataB64 = ei._decryptAssociatedDataB64;