UNPKG

@gaonengwww/jose

Version:

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

75 lines (71 loc) 2.2 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/lib/iv.ts var iv_exports = {}; __export(iv_exports, { bitLength: () => bitLength, default: () => iv_default }); module.exports = __toCommonJS(iv_exports); // 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/iv.ts function bitLength(alg) { switch (alg) { case "A128GCM": case "A128GCMKW": case "A192GCM": case "A192GCMKW": case "A256GCM": case "A256GCMKW": return 96; case "A128CBC-HS256": case "A192CBC-HS384": case "A256CBC-HS512": return 128; default: throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`); } } var iv_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3)); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { bitLength });