Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv and simplify

Manav Rathi7c0450c36408
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 3a046ab4cb..f25ab63afa 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -74,7 +74,10 @@ const createCollection = async (
const { encryptedData: encryptedKey, nonce: keyDecryptionNonce } =
await cryptoWorker.encryptBox(collectionKey, encryptionKey);
const { encryptedData: encryptedName, nonce: nameDecryptionNonce } =
- await cryptoWorker.encryptBoxUTF8(collectionName, collectionKey);
+ await cryptoWorker.encryptBox(
+ new TextEncoder().encode(collectionName),
+ collectionKey,
+ );
let encryptedMagicMetadata: EncryptedMagicMetadata;
if (magicMetadataProps) {
@@ -477,7 +480,10 @@ export const renameCollection = async (
const token = getToken();
const cryptoWorker = await sharedCryptoWorker();
const { encryptedData: encryptedName, nonce: nameDecryptionNonce } =
- await cryptoWorker.encryptBoxUTF8(newCollectionName, collection.key);
+ await cryptoWorker.encryptBox(
+ new TextEncoder().encode(newCollectionName),
+ collection.key,
+ );
const collectionRenameRequest = {
collectionID: collection.id,
encryptedName,
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index b391ef5d9e..a1e07bccfc 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -13,7 +13,6 @@ export const _fromHex = libsodium.fromHex;
export const _generateKey = libsodium.generateKey;
export const _generateBlobOrStreamKey = libsodium.generateBlobOrStreamKey;
export const _encryptBox = libsodium.encryptBox;
-export const _encryptBoxUTF8 = libsodium.encryptBoxUTF8;
export const _encryptBlob = libsodium.encryptBlob;
export const _encryptBlobBytes = libsodium.encryptBlobBytes;
export const _encryptMetadataJSON = libsodium.encryptMetadataJSON;
diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.ts
index ed644d1fd5..cfb2717521 100644
--- a/web/packages/base/crypto/index.ts
+++ b/web/packages/base/crypto/index.ts
@@ -62,26 +62,24 @@
*
* There are two primary types used when exchanging data with these functions:
*
- * 1. Base64 strings. Unqualified strings are taken as base64 encoded
- * representations of the underlying data. Usually, the unqualified "base"
- * function deals with Base64 strings, since they also are the data type in
- * which we usually send the encryted data etc to remote.
+ * 1. Base64 strings. Unless stated otherwise, all strings are taken as base64
+ * encoded representations of the underlying data. Usually, the unqualified
+ * function deals with base64 strings, since they also are the data type in
+ * which we usually store and send the data.
*
* 2. Raw bytes. Uint8Arrays are byte arrays. The functions that deal with bytes
- * are indicated by a *Bytes suffix in their name.
+ * are usually indicated by a *Bytes suffix in their name, but not always
+ * since it might also be the natural choice for functions that deal with
+ * larger amounts of data.
*
- * Where possible and useful, functions also accept a union of these two - a
+ * Where relevant and useful, functions also accept a union of these two - a
* {@link BytesOrB64} where the implementation will automatically convert
* to/from base64 to bytes if needed, thus saving on unnecessary conversions at
* the caller side.
*
- * Apart from these two, there are other secondary and one off types.
+ * Apart from these two, there are other secondary, one off types.
*
- * 1. "Regular" JavaScript strings. These are indicated by the *UTF8 suffix on
- * the function that deals with them. These strings will be obtained by UTF-8
- * encoding (or decoding) the underlying bytes.
- *
- * 2. Hex representations of the bytes. These are indicated by the *Hex suffix
+ * 1. Hex representations of the bytes. These are indicated by the *Hex suffix
* on the functions dealing with them.
*
* 2. JSON values. These are indicated by the *JSON suffix on the functions
@@ -208,18 +206,6 @@ export const encryptBox = (
? ei._encryptBox(data, key)
: sharedWorker().then((w) => w.encryptBox(data, key));
-/**
- * A variant of {@link encryptBox} that first UTF-8 encodes the input string to
- * obtain bytes, which it then encrypts.
- */
-export const encryptBoxUTF8 = (
- data: string,
- key: BytesOrB64,
-): Promise<EncryptedBoxB64> =>
- inWorker()
- ? ei._encryptBoxUTF8(data, key)
- : sharedWorker().then((w) => w.encryptBoxUTF8(data, key));
-
/**
* Encrypt the given data, returning a blob containing the encrypted data and a
* decryption header as base64 strings.
diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.ts
index 3871fdd169..c627db171e 100644
--- a/web/packages/base/crypto/libsodium.ts
+++ b/web/packages/base/crypto/libsodium.ts
@@ -287,18 +287,6 @@ export const encryptBox = async (
};
};
-/**
- * A variant of {@link encryptBox} that first converts the input string into
- * bytes using a UTF-8 encoding, and then encrypts those bytes.
- */
-export const encryptBoxUTF8 = async (
- data: string,
- key: BytesOrB64,
-): Promise<EncryptedBoxB64> => {
- await sodium.ready;
- return encryptBox(sodium.from_string(data), key);
-};
-
/**
* Encrypt the given data using libsodium's secretstream APIs without chunking.
*
@@ -550,7 +538,7 @@ export const decryptBlob = (
/**
* Decrypt the result of {@link encryptMetadataJSON} and return the JSON value
- * obtained by parsing the decrypted JSON string (which is obtained by utf-8
+ * obtained by parsing the decrypted JSON string (which is obtained by UTF-8
* decoding the decrypted bytes).
*
* Since TypeScript doesn't currently have a native JSON type, the returned
diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts
index 330a9b09e3..82f4400bf8 100644
--- a/web/packages/base/crypto/worker.ts
+++ b/web/packages/base/crypto/worker.ts
@@ -21,7 +21,6 @@ export class CryptoWorker {
generateKey = ei._generateKey;
generateBlobOrStreamKey = ei._generateBlobOrStreamKey;
encryptBox = ei._encryptBox;
- encryptBoxUTF8 = ei._encryptBoxUTF8;
encryptBlob = ei._encryptBlob;
encryptBlobBytes = ei._encryptBlobBytes;
encryptMetadataJSON = ei._encryptMetadataJSON;