2019-01-25 10:43:13 +00:00
|
|
|
import { JsonProp } from "@peculiar/json-schema";
|
|
|
|
import * as core from "webcrypto-core";
|
|
|
|
import { JsonBase64UrlConverter } from "../../converters";
|
|
|
|
import { SymmetricKey } from "../../keys";
|
|
|
|
|
|
|
|
export class AesCryptoKey extends SymmetricKey {
|
|
|
|
|
2022-03-02 18:35:31 +00:00
|
|
|
public override algorithm!: AesKeyAlgorithm;
|
2019-01-25 10:43:13 +00:00
|
|
|
|
|
|
|
@JsonProp({name: "k", converter: JsonBase64UrlConverter})
|
2022-03-02 18:35:31 +00:00
|
|
|
public override data!: Buffer;
|
2019-01-25 10:43:13 +00:00
|
|
|
|
2021-01-11 10:01:50 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
2019-01-25 10:43:13 +00:00
|
|
|
public get alg() {
|
|
|
|
switch (this.algorithm.name.toUpperCase()) {
|
|
|
|
case "AES-CBC":
|
|
|
|
return `A${this.algorithm.length}CBC`;
|
|
|
|
case "AES-CTR":
|
|
|
|
return `A${this.algorithm.length}CTR`;
|
|
|
|
case "AES-GCM":
|
|
|
|
return `A${this.algorithm.length}GCM`;
|
2019-03-02 04:40:35 +00:00
|
|
|
case "AES-KW":
|
|
|
|
return `A${this.algorithm.length}KW`;
|
2019-08-20 09:21:56 +00:00
|
|
|
case "AES-CMAC":
|
|
|
|
return `A${this.algorithm.length}CMAC`;
|
2019-10-12 07:33:10 +00:00
|
|
|
case "AES-ECB":
|
|
|
|
return `A${this.algorithm.length}ECB`;
|
2019-01-25 10:43:13 +00:00
|
|
|
default:
|
|
|
|
throw new core.AlgorithmError("Unsupported algorithm name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 18:35:31 +00:00
|
|
|
public override set alg(value: string) {
|
2019-01-25 10:43:13 +00:00
|
|
|
// nothing, cause set is needed for json-schema, but is not used by module
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|