Phase 5 red: collection and file decryption tests
10 tests covering decryptCollection (key + name decryption from raw server JSON, type mapping, isShared, missing name, wrong key) and decryptFile (key + metadata decryption, fileType number-to-string mapping, file/thumbnail header passthrough, wrong key). Adds src/model/types.ts with both raw (server) and decrypted (library) type definitions. src/model/decrypt.ts has throwing stubs.
This commit is contained in:
23
src/model/decrypt.ts
Normal file
23
src/model/decrypt.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Stub: see the README "Development workflow" section for TDD policy.
|
||||
|
||||
import type {
|
||||
Collection,
|
||||
EnteFile,
|
||||
RawCollection,
|
||||
RawEnteFile,
|
||||
} from "./types.js";
|
||||
|
||||
export const decryptCollection = (
|
||||
_raw: RawCollection,
|
||||
_masterKey: Uint8Array,
|
||||
_currentUserID?: number,
|
||||
): Collection => {
|
||||
throw new Error("model.decryptCollection not implemented");
|
||||
};
|
||||
|
||||
export const decryptFile = (
|
||||
_raw: RawEnteFile,
|
||||
_collectionKey: Uint8Array,
|
||||
): EnteFile => {
|
||||
throw new Error("model.decryptFile not implemented");
|
||||
};
|
||||
12
src/model/index.ts
Normal file
12
src/model/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export { decryptCollection, decryptFile } from "./decrypt.js";
|
||||
export type {
|
||||
Collection,
|
||||
CollectionType,
|
||||
EnteFile,
|
||||
FileBlob,
|
||||
FileMetadata,
|
||||
FileType,
|
||||
Microseconds,
|
||||
RawCollection,
|
||||
RawEnteFile,
|
||||
} from "./types.js";
|
||||
74
src/model/types.ts
Normal file
74
src/model/types.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
export type Microseconds = number;
|
||||
|
||||
export type CollectionType =
|
||||
| "album"
|
||||
| "folder"
|
||||
| "favorites"
|
||||
| "uncategorized"
|
||||
| "unknown";
|
||||
|
||||
export interface Collection {
|
||||
id: number;
|
||||
ownerID: number;
|
||||
key: Uint8Array;
|
||||
name: string;
|
||||
type: CollectionType;
|
||||
updationTime: Microseconds;
|
||||
isShared: boolean;
|
||||
}
|
||||
|
||||
export type FileType = "image" | "video" | "livePhoto" | "unknown";
|
||||
|
||||
export interface FileMetadata {
|
||||
title: string;
|
||||
fileType: FileType;
|
||||
creationTime: Microseconds;
|
||||
modificationTime: Microseconds;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
hash?: string;
|
||||
}
|
||||
|
||||
export interface FileBlob {
|
||||
decryptionHeader: string;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export interface EnteFile {
|
||||
id: number;
|
||||
collectionID: number;
|
||||
ownerID: number;
|
||||
key: Uint8Array;
|
||||
metadata: FileMetadata;
|
||||
file: FileBlob;
|
||||
thumbnail: FileBlob;
|
||||
updationTime: Microseconds;
|
||||
}
|
||||
|
||||
// Raw shapes as they arrive from the Ente API, before decryption.
|
||||
|
||||
export interface RawCollection {
|
||||
id: number;
|
||||
owner: { id: number };
|
||||
encryptedKey: string;
|
||||
keyDecryptionNonce: string;
|
||||
encryptedName?: string;
|
||||
nameDecryptionNonce?: string;
|
||||
type: string;
|
||||
updationTime: number;
|
||||
isDeleted?: boolean;
|
||||
}
|
||||
|
||||
export interface RawEnteFile {
|
||||
id: number;
|
||||
collectionID: number;
|
||||
ownerID: number;
|
||||
encryptedKey: string;
|
||||
keyDecryptionNonce: string;
|
||||
metadata: { encryptedData: string; decryptionHeader: string };
|
||||
info?: { fileSize?: number; thumbSize?: number };
|
||||
file: { decryptionHeader: string };
|
||||
thumbnail: { decryptionHeader: string };
|
||||
updationTime: number;
|
||||
isDeleted?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user