UNPKG

@gaonengwww/jose

Version:

JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes

48 lines (46 loc) 1.17 kB
// src/util/errors.ts var JOSEError = class extends Error { /** * A unique error code for the particular error subclass. * * @ignore */ static code = "ERR_JOSE_GENERIC"; /** A unique error code for {@link JOSEError}. */ code = "ERR_JOSE_GENERIC"; /** @ignore */ constructor(message, options) { super(message, options); this.name = this.constructor.name; Error.captureStackTrace?.(this, this.constructor); } }; var JOSENotSupported = class extends JOSEError { /** @ignore */ static code = "ERR_JOSE_NOT_SUPPORTED"; /** A unique error code for {@link JOSENotSupported}. */ code = "ERR_JOSE_NOT_SUPPORTED"; }; // src/lib/cek.ts function bitLength(alg) { switch (alg) { case "A128GCM": return 128; case "A192GCM": return 192; case "A256GCM": case "A128CBC-HS256": return 256; case "A192CBC-HS384": return 384; case "A256CBC-HS512": return 512; default: throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); } } var cek_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3)); export { bitLength, cek_default as default };