Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reduce API surface

Manav Rathi37b52b5cb550
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts
index 1969cdd9c3..97cb19537d 100644
--- a/web/packages/base/crypto/ente-impl.ts
+++ b/web/packages/base/crypto/ente-impl.ts
@@ -1,6 +1,6 @@
/** Careful when adding add other imports! */
import * as libsodium from "./libsodium";
-import type { BytesOrB64, EncryptedBlob, EncryptedFile } from "./types";
+import type { BytesOrB64, EncryptedBlob } from "./types";
export const _toB64 = libsodium.toB64;
@@ -22,20 +22,6 @@ export const _encryptBlob = libsodium.encryptBlob;
export const _encryptBlobBytes = libsodium.encryptBlobBytes;
-export const _encryptThumbnail = async (
- data: BytesOrB64,
- key: BytesOrB64,
-): Promise<EncryptedFile> => {
- const { encryptedData, decryptionHeader } = await _encryptBlobBytes(
- data,
- key,
- );
- return {
- encryptedData,
- decryptionHeader: await libsodium.toB64(decryptionHeader),
- };
-};
-
export const _encryptStreamBytes = libsodium.encryptStreamBytes;
export const _initChunkEncryption = libsodium.initChunkEncryption;
@@ -68,8 +54,6 @@ export const _decryptBlobBytes = libsodium.decryptBlobBytes;
export const _decryptBlob = libsodium.decryptBlob;
-export const _decryptThumbnail = _decryptBlobBytes;
-
export const _decryptStreamBytes = libsodium.decryptStreamBytes;
export const _initChunkDecryption = libsodium.initChunkDecryption;
diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.ts
index 73ced28f53..d8b6665e77 100644
--- a/web/packages/base/crypto/index.ts
+++ b/web/packages/base/crypto/index.ts
@@ -202,20 +202,6 @@ export const encryptBlob = (data: BytesOrB64, key: BytesOrB64) =>
export const encryptBlobBytes = (data: BytesOrB64, key: BytesOrB64) =>
assertInWorker(ei._encryptBlobBytes(data, key));
-/**
- * Encrypt the thumbnail for a file.
- *
- * This is midway variant of {@link encryptBlobBytes} and {@link encryptBlob}
- * that returns the decryption header as a base64 string, but leaves the data
- * unchanged.
- *
- * Use {@link decryptThumbnail} to decrypt the result.
- */
-export const encryptThumbnail = (data: BytesOrB64, key: BytesOrB64) =>
- inWorker()
- ? ei._encryptThumbnail(data, key)
- : sharedWorker().then((w) => w.encryptThumbnail(data, key));
-
/**
* Encrypt the given data using chunked streaming encryption, but process all
* the chunks in one go.
@@ -319,14 +305,6 @@ export const decryptBlobBytes = (blob: EncryptedBlob, key: BytesOrB64) =>
? ei._decryptBlobBytes(blob, key)
: sharedWorker().then((w) => w.decryptBlobBytes(blob, key));
-/**
- * Decrypt the thumbnail encrypted using {@link encryptThumbnail}.
- */
-export const decryptThumbnail = (blob: EncryptedBlob, key: BytesOrB64) =>
- inWorker()
- ? ei._decryptThumbnail(blob, key)
- : sharedWorker().then((w) => w.decryptThumbnail(blob, key));
-
/**
* Decrypt the result of {@link encryptStreamBytes}.
*/
diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts
index 81b7571be6..a0373edcbc 100644
--- a/web/packages/base/crypto/worker.ts
+++ b/web/packages/base/crypto/worker.ts
@@ -21,7 +21,7 @@ export class CryptoWorker {
generateKey = ei._generateKey;
generateBlobOrStreamKey = ei._generateBlobOrStreamKey;
encryptBox = ei._encryptBox;
- encryptThumbnail = ei._encryptThumbnail;
+ encryptBlobBytes = ei._encryptBlobBytes;
encryptBlob = ei._encryptBlob;
encryptStreamBytes = ei._encryptStreamBytes;
initChunkEncryption = ei._initChunkEncryption;
@@ -32,7 +32,6 @@ export class CryptoWorker {
decryptBox = ei._decryptBox;
decryptBlobBytes = ei._decryptBlobBytes;
decryptBlob = ei._decryptBlob;
- decryptThumbnail = ei._decryptThumbnail;
decryptStreamBytes = ei._decryptStreamBytes;
initChunkDecryption = ei._initChunkDecryption;
decryptStreamChunk = ei._decryptStreamChunk;
diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.ts
index 82f3dc1686..3da489fd90 100644
--- a/web/packages/gallery/services/download.ts
+++ b/web/packages/gallery/services/download.ts
@@ -1,8 +1,8 @@
import { blobCache, type BlobCache } from "ente-base/blob-cache";
import {
+ decryptBlobBytes,
decryptStreamBytes,
decryptStreamChunk,
- decryptThumbnail,
initChunkDecryption,
} from "ente-base/crypto";
import {
@@ -295,7 +295,7 @@ class DownloadManager {
this._downloadThumbnail(file),
);
const decryptionHeader = file.thumbnail.decryptionHeader;
- return decryptThumbnail({ encryptedData, decryptionHeader }, file.key);
+ return decryptBlobBytes({ encryptedData, decryptionHeader }, file.key);
};
private async _downloadThumbnail(file: EnteFile) {
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index 9377266374..3582450db8 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -1426,10 +1426,15 @@ const encryptFile = async (
? await worker.encryptStreamBytes(fileStreamOrData, fileKey)
: await encryptFileStream(fileStreamOrData, fileKey, worker);
- const encryptedThumbnail = await worker.encryptThumbnail(
- thumbnail,
- fileKey,
- );
+ const {
+ encryptedData: encryptedThumbnailData,
+ decryptionHeader: thumbnailDecryptionHeaderBytes,
+ } = await worker.encryptBlobBytes(thumbnail, fileKey);
+
+ const encryptedThumbnail = {
+ encryptedData: encryptedThumbnailData,
+ decryptionHeader: await worker.toB64(thumbnailDecryptionHeaderBytes),
+ };
const encryptedMetadata = await worker.encryptMetadataJSON({
jsonValue: metadata,