This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
webcrypto/packages/core/test/des.spec.ts

91 lines
2.6 KiB
TypeScript
Raw Permalink Normal View History

import * as types from "@peculiar/webcrypto-types";
import * as core from "@peculiar/webcrypto-core";
import * as assert from "assert";
class DesTestProvider extends core.DesProvider {
public keySizeBits = 64;
public ivSize = 8;
public name = "DES-TEST";
2022-05-24 12:05:52 +00:00
public onGenerateKey(algorithm: types.DesKeyGenParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented.");
}
2022-05-23 21:09:47 +00:00
public onExportKey(format: types.KeyFormat, key: core.CryptoKey): Promise<types.JsonWebKey | ArrayBuffer> {
throw new Error("Method not implemented.");
}
2022-05-24 12:05:52 +00:00
public onImportKey(format: types.KeyFormat, keyData: types.JsonWebKey | ArrayBuffer, algorithm: types.DesImportParams, extractable: boolean, keyUsages: types.KeyUsage[]): Promise<core.CryptoKey> {
throw new Error("Method not implemented.");
}
2022-05-24 12:05:52 +00:00
public onEncrypt(algorithm: types.DesParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented.");
}
2022-05-24 12:05:52 +00:00
public onDecrypt(algorithm: types.DesParams, key: core.CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
throw new Error("Method not implemented.");
}
}
context("DES", () => {
const provider = new DesTestProvider();
context("checkAlgorithmParams", () => {
it("error if `iv` is not present", () => {
assert.throws(() => {
provider.checkAlgorithmParams({
} as any);
}, Error);
});
it("error if `iv` has wrong type", () => {
assert.throws(() => {
provider.checkAlgorithmParams({
iv: "wrong type",
} as any);
}, TypeError);
});
it("error if `iv` has wrong length", () => {
assert.throws(() => {
provider.checkAlgorithmParams({
iv: new ArrayBuffer(9),
} as any);
}, TypeError);
});
it("correct `iv` length", () => {
provider.checkAlgorithmParams({
iv: new Uint8Array(8),
} as any);
});
});
context("checkGenerateKeyParams", () => {
it("error if `length` is not present", () => {
assert.throws(() => {
provider.checkGenerateKeyParams({} as any);
}, Error);
});
it("error if `length` has wrong type", () => {
assert.throws(() => {
provider.checkGenerateKeyParams({ length: "8" } as any);
}, TypeError);
});
it("error if `length` has wrong value", () => {
assert.throws(() => {
provider.checkGenerateKeyParams({ length: 8 } as any);
}, core.OperationError);
});
it("correct value", () => {
provider.checkGenerateKeyParams({ length: 64 } as any);
});
});
});