Skip to content

Commit

Permalink
Merge branch 'tim/decrypt_empty' into 'master'
Browse files Browse the repository at this point in the history
feat: Clarify error message when trying to decrypt empty buffer

See merge request TankerHQ/sdk-js!1023
  • Loading branch information
tux3 committed Jun 3, 2024
2 parents 4740fb6 + 63bf845 commit 089b93a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/crypto/src/EncryptionFormats/EncryptionFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ import { EncryptionV9, EncryptionV10, EncryptionV11 } from './TransparentEncrypt

export interface EncryptionFormatReporter {
getClearSize(encryptedSize: number): number

getEncryptedSize(clearSize: number): number
}

export type SimpleEncryptor = typeof EncryptionV1 | typeof EncryptionV2 | typeof EncryptionV3 | typeof EncryptionV5 | typeof EncryptionV6 | typeof EncryptionV7;
export type SimpleEncryptor =
typeof EncryptionV1
| typeof EncryptionV2
| typeof EncryptionV3
| typeof EncryptionV5
| typeof EncryptionV6
| typeof EncryptionV7;
export type StreamEncryptor = typeof EncryptionV4 | typeof EncryptionV8;
export type TransparentSessionEncryptor = typeof EncryptionV9 | typeof EncryptionV10;
export type TransparentSessionStreamEncryptor = typeof EncryptionV11;
export type Encryptor = SimpleEncryptor | StreamEncryptor | TransparentSessionEncryptor | TransparentSessionStreamEncryptor;
export type Encryptor =
SimpleEncryptor
| StreamEncryptor
| TransparentSessionEncryptor
| TransparentSessionStreamEncryptor;

const encryptionFormats = [undefined, EncryptionV1, EncryptionV2, EncryptionV3, EncryptionV4, EncryptionV5, EncryptionV6, EncryptionV7, EncryptionV8, EncryptionV9, EncryptionV10, EncryptionV11] as const;

Expand All @@ -46,7 +57,7 @@ export const getClearSize = (encryptionFormatDescription: EncryptionFormatDescri

export const extractEncryptionFormat = (encryptedData: Uint8Array) => {
if (encryptedData.length < 1)
throw new InvalidArgument('Could not decode encryption version from encryptedData');
throw new InvalidArgument('Could not decode encryption version because the encrypted data is empty');
const version = encryptedData[0]!;

const encryption = encryptionFormats[version];
Expand Down

0 comments on commit 089b93a

Please sign in to comment.