-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Kem/Kdf/Aead algorithm constructor.
- Loading branch information
Showing
21 changed files
with
399 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { chacha20_poly1305 } from "npm:@noble/[email protected]/chacha"; | ||
|
||
import { Algorithm } from "../algorithm.ts"; | ||
import type { AeadKey } from "../interfaces/aeadKey.ts"; | ||
|
||
import { Aead } from "../identifiers.ts"; | ||
|
||
export class Chacha20Poly1305Key implements AeadKey { | ||
export class Chacha20Poly1305Key extends Algorithm implements AeadKey { | ||
public readonly id: Aead = Aead.Chacha20Poly1305; | ||
public readonly keySize: number = 32; | ||
public readonly nonceSize: number = 12; | ||
public readonly tagSize: number = 16; | ||
private _key: Uint8Array; | ||
|
||
public constructor(key: ArrayBuffer) { | ||
super(); | ||
this._key = new Uint8Array(key); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as consts from "./consts.ts"; | ||
|
||
export class AlgorithmBase { | ||
protected _api: SubtleCrypto | undefined = undefined; | ||
|
||
constructor() {} | ||
|
||
protected checkInit(): void { | ||
if (typeof this._api === "undefined") { | ||
throw new Error("Not initialized. Call init()"); | ||
} | ||
} | ||
} | ||
|
||
export class Algorithm extends AlgorithmBase { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
public init(api: SubtleCrypto): void { | ||
this._api = api; | ||
} | ||
} | ||
|
||
export class KdfAlgorithm extends AlgorithmBase { | ||
protected _suiteId: Uint8Array = consts.EMPTY; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
public init(api: SubtleCrypto, suiteId: Uint8Array): void { | ||
this._api = api; | ||
this._suiteId = suiteId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.