This commit is contained in:
Manav Rathi
2024-08-05 15:03:39 +05:30
parent 219cc405da
commit d599a6dcfa
3 changed files with 23 additions and 19 deletions

View File

@@ -1124,10 +1124,14 @@ const encryptFile = async (
worker,
);
const encryptedThumbnail = await worker.encryptThumbnail(
file.thumbnail,
fileKey,
);
const {
encryptedData: thumbEncryptedData,
decryptionHeaderB64: thumbDecryptionHeader,
} = await worker.encryptThumbnail(file.thumbnail, fileKey);
const encryptedThumbnail = {
encryptedData: thumbEncryptedData,
decryptionHeader: thumbDecryptionHeader,
};
const encryptedMetadata = await worker.encryptMetadata2(
file.metadata,

View File

@@ -37,6 +37,20 @@ import * as libsodium from "@ente/shared/crypto/internal/libsodium";
*/
export const encryptAssociatedData = libsodium.encryptChaChaOneShot;
/**
* Encrypt the thumbnail for a file.
*
* This is just an alias for {@link encryptAssociatedData}.
*
* @param data The thumbnail's data.
*
* @param keyB64 The key associated with the file whose thumbnail this is.
*
* @returns The encrypted thumbnail, and the associated decryption header
* (Base64 encoded).
*/
export const encryptThumbnail = encryptAssociatedData;
/**
* Encrypted the embedding associated with a file using the file's key.
*

View File

@@ -32,22 +32,8 @@ export class DedicatedCryptoWorker {
);
}
/**
* Encrypt the thumbnail associated with a file.
*
* This defers to {@link encryptChaChaOneShot}.
*
* @param data The thumbnail's data.
*
* @param keyB64 The key associated with the file whose thumbnail this is.
*
* @returns The encrypted thumbnail, and the associated decryption header
* (Base64 encoded).
*/
async encryptThumbnail(data: Uint8Array, keyB64: string) {
const { encryptedData, decryptionHeaderB64: decryptionHeader } =
await libsodium.encryptChaChaOneShot(data, keyB64);
return { encryptedData, decryptionHeader };
return ente.encryptThumbnail(data, keyB64);
}
async encryptFile(fileData: Uint8Array) {