-
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.
Merge pull request #193 from dajiaji/introduce-aead-interface
Add AeadInterface for CipherSuiteParams.
- Loading branch information
Showing
12 changed files
with
184 additions
and
140 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
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,18 +1,21 @@ | ||
import { chacha20_poly1305 } from "npm:@noble/[email protected]/chacha"; | ||
|
||
import { Algorithm } from "../algorithm.ts"; | ||
import type { AeadKey } from "../interfaces/aeadKey.ts"; | ||
import type { AeadInterface } from "../interfaces/aeadInterface.ts"; | ||
|
||
import { Algorithm } from "../algorithm.ts"; | ||
import { AeadId } from "../identifiers.ts"; | ||
|
||
export class Chacha20Poly1305Key extends Algorithm implements AeadKey { | ||
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; | ||
private _key: Uint8Array; | ||
private _api: SubtleCrypto; | ||
|
||
public constructor(key: ArrayBuffer) { | ||
super(); | ||
public constructor(api: SubtleCrypto, key: ArrayBuffer) { | ||
this._api = api; | ||
this._key = new Uint8Array(key); | ||
} | ||
|
||
|
@@ -62,3 +65,14 @@ export class Chacha20Poly1305Key extends Algorithm implements AeadKey { | |
}); | ||
} | ||
} | ||
|
||
export class Chacha20Poly1305 extends Algorithm implements AeadInterface { | ||
public readonly id: AeadId = AeadId.Chacha20Poly1305; | ||
public readonly keySize: number = 32; | ||
public readonly nonceSize: number = 12; | ||
public readonly tagSize: number = 16; | ||
|
||
public createAeadKey(key: ArrayBuffer): AeadKey { | ||
return new Chacha20Poly1305Key(this._api as SubtleCrypto, 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,20 @@ | ||
import type { AeadKey } from "../interfaces/aeadKey.ts"; | ||
import type { AeadInterface } from "../interfaces/aeadInterface.ts"; | ||
|
||
import { Algorithm } from "../algorithm.ts"; | ||
import { AeadId } from "../identifiers.ts"; | ||
|
||
import { NotSupportedError } from "../errors.ts"; | ||
|
||
export class ExportOnly extends Algorithm implements AeadInterface { | ||
public readonly id: AeadId = AeadId.ExportOnly; | ||
public readonly keySize: number = 0; | ||
public readonly nonceSize: number = 0; | ||
public readonly tagSize: number = 0; | ||
|
||
public createAeadKey(_key: ArrayBuffer): AeadKey { | ||
throw new NotSupportedError( | ||
"createAeadKey() is not supported on ExportOnly", | ||
); | ||
} | ||
} |
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.