Skip to content

Commit

Permalink
Merge pull request #214 from dajiaji/breaking-changes-for-1_0_0
Browse files Browse the repository at this point in the history
Breaking changes for 1.0.0
  • Loading branch information
dajiaji authored Jul 29, 2023
2 parents fd9ecdc + 6fe00c8 commit e475a45
Show file tree
Hide file tree
Showing 27 changed files with 2,832 additions and 1,418 deletions.
4 changes: 1 addition & 3 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type { AeadEncryptionContext } from "./src/interfaces/aeadEncryptionContext.ts";
export type { AeadInterface } from "./src/interfaces/aeadInterface.ts";
export type { AeadKey } from "./src/interfaces/aeadKey.ts";
export type { CipherSuiteParams } from "./src/interfaces/cipherSuiteParams.ts";
export type { KdfInterface } from "./src/interfaces/kdfInterface.ts";
export type { KemInterface } from "./src/interfaces/kemInterface.ts";
Expand All @@ -17,13 +17,11 @@ export * from "./src/errors.ts";

export { Aead, AeadId, Kdf, KdfId, Kem, KemId } from "./src/identifiers.ts";
export { CipherSuite } from "./src/cipherSuite.ts";

export { DhkemP256HkdfSha256 } from "./src/kems/dhkemP256.ts";
export { DhkemP384HkdfSha384 } from "./src/kems/dhkemP384.ts";
export { DhkemP521HkdfSha512 } from "./src/kems/dhkemP521.ts";
export { DhkemX25519HkdfSha256 } from "./src/kems/dhkemX25519.ts";
export { DhkemX448HkdfSha512 } from "./src/kems/dhkemX448.ts";

export { HkdfSha256 } from "./src/kdfs/hkdfSha256.ts";
export { HkdfSha384 } from "./src/kdfs/hkdfSha384.ts";
export { HkdfSha512 } from "./src/kdfs/hkdfSha512.ts";
Expand Down
30 changes: 6 additions & 24 deletions src/aeads/aesGcm.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import type { AeadKey } from "../interfaces/aeadKey.ts";
import type { AeadEncryptionContext } from "../interfaces/aeadEncryptionContext.ts";
import type { AeadInterface } from "../interfaces/aeadInterface.ts";

import { Algorithm } from "../algorithm.ts";
import { AeadId } from "../identifiers.ts";
import * as consts from "../consts.ts";

export class AesGcmKey implements AeadKey {
public readonly id: AeadId = AeadId.Aes128Gcm;
public readonly keySize: number = 0;
public readonly nonceSize: number = 0;
public readonly tagSize: number = 0;
export class AesGcmContext implements AeadEncryptionContext {
private _rawKey: ArrayBuffer;
private _key: CryptoKey | undefined = undefined;
private _api: SubtleCrypto;
Expand Down Expand Up @@ -74,29 +70,15 @@ export class AesGcmKey implements AeadKey {
}
}

export class Aes128GcmKey extends AesGcmKey {
public readonly id: AeadId = AeadId.Aes128Gcm;
public readonly keySize: number = 16;
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;
}

export class Aes256GcmKey extends AesGcmKey {
public readonly id: AeadId = AeadId.Aes256Gcm;
public readonly keySize: number = 32;
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;
}

export class Aes128Gcm extends Algorithm implements AeadInterface {
public readonly id: AeadId = AeadId.Aes128Gcm;
public readonly keySize: number = 16;
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;

public createAeadKey(key: ArrayBuffer): AeadKey {
public createEncryptionContext(key: ArrayBuffer): AeadEncryptionContext {
this.checkInit();
return new Aes128GcmKey(this._api as SubtleCrypto, key);
return new AesGcmContext(this._api as SubtleCrypto, key);
}
}

Expand All @@ -106,8 +88,8 @@ export class Aes256Gcm extends Algorithm implements AeadInterface {
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;

public createAeadKey(key: ArrayBuffer): AeadKey {
public createEncryptionContext(key: ArrayBuffer): AeadEncryptionContext {
this.checkInit();
return new Aes256GcmKey(this._api as SubtleCrypto, key);
return new AesGcmContext(this._api as SubtleCrypto, key);
}
}
12 changes: 4 additions & 8 deletions src/aeads/chacha20Poly1305.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { chacha20_poly1305 } from "npm:@noble/[email protected]/chacha";

import type { AeadKey } from "../interfaces/aeadKey.ts";
import type { AeadEncryptionContext } from "../interfaces/aeadEncryptionContext.ts";
import type { AeadInterface } from "../interfaces/aeadInterface.ts";

import { Algorithm } from "../algorithm.ts";
import { AeadId } from "../identifiers.ts";

export class Chacha20Poly1305Key implements AeadKey {
public readonly id: AeadId = AeadId.Chacha20Poly1305;
public readonly keySize: number = 32;
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;
export class Chacha20Poly1305Context implements AeadEncryptionContext {
private _key: Uint8Array;
private _api: SubtleCrypto;

Expand Down Expand Up @@ -72,7 +68,7 @@ export class Chacha20Poly1305 extends Algorithm implements AeadInterface {
public readonly nonceSize: number = 12;
public readonly tagSize: number = 16;

public createAeadKey(key: ArrayBuffer): AeadKey {
return new Chacha20Poly1305Key(this._api as SubtleCrypto, key);
public createEncryptionContext(key: ArrayBuffer): AeadEncryptionContext {
return new Chacha20Poly1305Context(this._api as SubtleCrypto, key);
}
}
6 changes: 3 additions & 3 deletions src/aeads/exportOnly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AeadKey } from "../interfaces/aeadKey.ts";
import type { AeadEncryptionContext } from "../interfaces/aeadEncryptionContext.ts";
import type { AeadInterface } from "../interfaces/aeadInterface.ts";

import { Algorithm } from "../algorithm.ts";
Expand All @@ -12,9 +12,9 @@ export class ExportOnly extends Algorithm implements AeadInterface {
public readonly nonceSize: number = 0;
public readonly tagSize: number = 0;

public createAeadKey(_key: ArrayBuffer): AeadKey {
public createEncryptionContext(_key: ArrayBuffer): AeadEncryptionContext {
throw new NotSupportedError(
"createAeadKey() is not supported on ExportOnly",
"createEncryptionContext() is not supported on ExportOnly",
);
}
}
Loading

0 comments on commit e475a45

Please sign in to comment.