@nfen/webcrypto-ts
Version:
Enforced Webcrypto wrapper
69 lines • 2.06 kB
JavaScript
/**
* Key usages and allowed formats
* @module
*/
import { Alg as AES } from "./aes/shared.js";
import { Alg as EC } from "./ec/shared.js";
import { Alg as Authentication } from "./hmac/index.js";
import { Alg as KDF } from "./kdf/shared.js";
import { Alg as RSA } from "./rsa/shared.js";
export var KeyFormats;
(function (KeyFormats) {
KeyFormats["raw"] = "raw";
KeyFormats["pkcs8"] = "pkcs8";
KeyFormats["spki"] = "spki";
KeyFormats["jwk"] = "jwk";
})(KeyFormats || (KeyFormats = {}));
export var KeyUsages;
(function (KeyUsages) {
KeyUsages["encrypt"] = "encrypt";
KeyUsages["decrypt"] = "decrypt";
KeyUsages["sign"] = "sign";
KeyUsages["verify"] = "verify";
KeyUsages["deriveKey"] = "deriveKey";
KeyUsages["deriveBits"] = "deriveBits";
KeyUsages["wrapKey"] = "wrapKey";
KeyUsages["unwrapKey"] = "unwrapKey";
})(KeyUsages || (KeyUsages = {}));
export const EncryptionKeyUsagePair = [
KeyUsages.encrypt,
KeyUsages.decrypt,
];
export const SigningKeyUsagePair = [
KeyUsages.sign,
KeyUsages.verify,
];
export const WrappingKeyUsagePair = [
KeyUsages.wrapKey,
KeyUsages.unwrapKey,
];
export const DeriveKeyUsagePair = [
KeyUsages.deriveKey,
KeyUsages.deriveBits,
];
/**
* Given a algorithm, return the _most likely_ key usage pair.
*/
export function getKeyUsagePairsByAlg(alg) {
switch (alg) {
case AES.Mode.AES_CBC:
case AES.Mode.AES_CTR:
case AES.Mode.AES_GCM:
case RSA.Variant.RSA_OAEP:
return EncryptionKeyUsagePair;
case Authentication.Code.HMAC:
case EC.Variant.ECDSA:
case RSA.Variant.RSA_PSS:
case RSA.Variant.RSASSA_PKCS1_v1_5:
return SigningKeyUsagePair;
case EC.Variant.ECDH:
case KDF.Variant.HKDF:
case KDF.Variant.PBKDF2:
return DeriveKeyUsagePair;
case AES.Mode.AES_KW:
return WrappingKeyUsagePair;
default:
throw new Error(`Invalid alg ${alg}`);
}
}
//# sourceMappingURL=key_usages.js.map