Skip to content

armgit / ente

Public Imported from GitHub
0

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

Rearrange

Manav Rathi95cfdc4eaacc
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index 704e41d7f8..40521055a1 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -20,13 +20,16 @@ export const _encryptAssociatedData = libsodium.encryptChaChaOneShot;
export const _encryptThumbnail = _encryptAssociatedData;
-export const _encryptFileEmbedding = (r: EncryptBytes) =>
+export const _encryptMetadataBytes = (r: EncryptBytes) =>
_encryptAssociatedData(r).then(EncryptedBytesToB64);
-export const _encryptMetadata = async ({ jsonValue, keyB64 }: EncryptJSON) => {
- const data = new TextEncoder().encode(JSON.stringify(jsonValue));
- return EncryptedBytesToB64(await _encryptAssociatedData({ data, keyB64 }));
-};
+export const _encryptFileEmbedding = _encryptMetadataBytes;
+
+export const _encryptMetadataJSON = ({ jsonValue, keyB64 }: EncryptJSON) =>
+ _encryptMetadataBytes({
+ data: new TextEncoder().encode(JSON.stringify(jsonValue)),
+ keyB64,
+ });
export const _decryptAssociatedData = libsodium.decryptChaChaOneShot;
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.ts
index 3fe281d776..e3f99dcfa9 100644
--- a/web/packages/base/crypto/ente.ts
+++ b/web/packages/base/crypto/ente.ts
@@ -86,17 +86,25 @@ export const encryptAssociatedData = (r: EncryptBytes) =>
* Encrypt the thumbnail for a file.
*
* This is just an alias for {@link encryptAssociatedData}.
+ *
+ * Use {@link decryptFileEmbedding} to decrypt the result.
*/
export const encryptThumbnail = (r: EncryptBytes) =>
assertInWorker(ei._encryptThumbnail(r));
+/**
+ * A variant of {@link encryptAssociatedData} that returns the encrypted data in
+ * the result as a base64 string instead of its bytes.
+ *
+ * Use {@link decryptMetadata} to decrypt the result.
+ */
+export const encryptMetadataBytes = (r: EncryptBytes) =>
+ assertInWorker(ei._encryptMetadataBytes(r));
+
/**
* Encrypted the embedding associated with a file using the file's key.
*
- * This as a variant of {@link encryptAssociatedData} tailored for
- * encrypting the embeddings (a.k.a. derived data) associated with a file. In
- * particular, it returns the encrypted data in the result as a base64 string
- * instead of its bytes.
+ * This is just an alias for {@link encryptMetadataBytes}.
*
* Use {@link decryptFileEmbedding} to decrypt the result.
*/
@@ -104,7 +112,7 @@ export const encryptFileEmbedding = async (r: EncryptBytes) =>
assertInWorker(ei._encryptFileEmbedding(r));
/**
- * Encrypt the metadata associated with an Ente object (file, collection or
+ * Encrypt the JSON metadata associated with an Ente object (file, collection or
* entity) using the object's key.
*
* This is a variant of {@link encryptAssociatedData} tailored for encrypting
@@ -118,8 +126,8 @@ export const encryptFileEmbedding = async (r: EncryptBytes) =>
*
* Use {@link decryptMetadata} to decrypt the result.
*/
-export const encryptMetadata = async (r: EncryptJSON) =>
- assertInWorker(ei._encryptMetadata(r));
+export const encryptMetadataJSON = async (r: EncryptJSON) =>
+ assertInWorker(ei._encryptMetadataJSON(r));
/**
* Decrypt arbitrary data associated with an Ente object (file, collection or