micro509 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +165 -6
  2. package/dist/crypto/crypto.d.ts +12 -4
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +8 -2
  6. package/dist/der/der.d.ts +14 -4
  7. package/dist/der/der.js +19 -19
  8. package/dist/der/der.js.map +1 -1
  9. package/dist/der.d.ts +26 -2
  10. package/dist/der.js +4 -4
  11. package/dist/index.d.ts +84 -16
  12. package/dist/index.js +19 -19
  13. package/dist/internal/asn1/asn1.d.ts +1 -2
  14. package/dist/internal/asn1/asn1.js +10 -2
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js.map +1 -1
  17. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  18. package/dist/internal/asn1/der.d.ts +1 -2
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +71 -353
  21. package/dist/internal/asn1/oids.js.map +1 -1
  22. package/dist/internal/asn1/oids.json.js +357 -0
  23. package/dist/internal/asn1/oids.json.js.map +1 -0
  24. package/dist/internal/crypto/algorithm-names.js +1 -1
  25. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  26. package/dist/internal/crypto/ecdsa.js.map +1 -1
  27. package/dist/internal/crypto/hash.js.map +1 -1
  28. package/dist/internal/crypto/pbes2.d.ts +1 -2
  29. package/dist/internal/crypto/pbes2.js +70 -70
  30. package/dist/internal/crypto/pbes2.js.map +1 -1
  31. package/dist/internal/crypto/prime-ec.js +37 -0
  32. package/dist/internal/crypto/prime-ec.js.map +1 -0
  33. package/dist/internal/crypto/rsa-pss.js +50 -50
  34. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  35. package/dist/internal/crypto/sig-verify.d.ts +41 -2
  36. package/dist/internal/crypto/sig-verify.js +125 -38
  37. package/dist/internal/crypto/sig-verify.js.map +1 -1
  38. package/dist/internal/crypto/signing.d.ts +1 -2
  39. package/dist/internal/crypto/signing.js +26 -26
  40. package/dist/internal/crypto/signing.js.map +1 -1
  41. package/dist/internal/jose/base64url.js.map +1 -1
  42. package/dist/internal/jose/json-data.js +108 -0
  43. package/dist/internal/jose/json-data.js.map +1 -0
  44. package/dist/internal/jose/strict-json.d.ts +1 -2
  45. package/dist/internal/jose/strict-json.js.map +1 -1
  46. package/dist/internal/shared/base64.js.map +1 -1
  47. package/dist/internal/shared/dn.d.ts +1 -2
  48. package/dist/internal/shared/dn.js +1 -1
  49. package/dist/internal/shared/dn.js.map +1 -1
  50. package/dist/internal/shared/idna.js.map +1 -1
  51. package/dist/internal/shared/ip.d.ts +1 -2
  52. package/dist/internal/shared/ip.js.map +1 -1
  53. package/dist/internal/shared/mailbox.js.map +1 -1
  54. package/dist/internal/shared/punycode.js.map +1 -1
  55. package/dist/internal/shared/uri-host.js.map +1 -1
  56. package/dist/internal/verify/name-constraints-engine.js +64 -64
  57. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  58. package/dist/internal/verify/policy-engine.js +1 -1
  59. package/dist/internal/verify/policy-engine.js.map +1 -1
  60. package/dist/internal/verify/spki-distrust.js.map +1 -1
  61. package/dist/internal/verify/verify-path.d.ts +1 -2
  62. package/dist/internal/verify/verify-path.js +234 -128
  63. package/dist/internal/verify/verify-path.js.map +1 -1
  64. package/dist/internal/x509/directory-name.js +10 -10
  65. package/dist/internal/x509/directory-name.js.map +1 -1
  66. package/dist/internal/x509/extension-bits.js.map +1 -1
  67. package/dist/internal/x509/extension-errors.d.ts +1 -2
  68. package/dist/internal/x509/extension-errors.js.map +1 -1
  69. package/dist/internal/x509/extension-registry.js +18 -18
  70. package/dist/internal/x509/extension-registry.js.map +1 -1
  71. package/dist/internal/x509/general-name-profile.js +9 -9
  72. package/dist/internal/x509/general-name-profile.js.map +1 -1
  73. package/dist/internal/x509/general-name.js +32 -32
  74. package/dist/internal/x509/general-name.js.map +1 -1
  75. package/dist/internal/x509/name-fields.js +1 -1
  76. package/dist/internal/x509/name-fields.js.map +1 -1
  77. package/dist/internal/x509/or-address.js.map +1 -1
  78. package/dist/jose/base64url.d.ts +4 -0
  79. package/dist/jose/base64url.js +14 -0
  80. package/dist/jose/base64url.js.map +1 -0
  81. package/dist/jose/errors.d.ts +9 -3
  82. package/dist/jose/errors.js.map +1 -1
  83. package/dist/jose/jwe.d.ts +64 -0
  84. package/dist/jose/jwe.js +188 -0
  85. package/dist/jose/jwe.js.map +1 -0
  86. package/dist/jose/jwks.d.ts +38 -10
  87. package/dist/jose/jwks.js +156 -96
  88. package/dist/jose/jwks.js.map +1 -1
  89. package/dist/jose/jws.d.ts +8 -6
  90. package/dist/jose/jws.js +216 -170
  91. package/dist/jose/jws.js.map +1 -1
  92. package/dist/jose/jwt.d.ts +8 -2
  93. package/dist/jose/jwt.js +98 -98
  94. package/dist/jose/jwt.js.map +1 -1
  95. package/dist/jose/remote-jwks.d.ts +1 -2
  96. package/dist/jose/remote-jwks.js +106 -108
  97. package/dist/jose/remote-jwks.js.map +1 -1
  98. package/dist/jose.d.ts +15 -4
  99. package/dist/jose.js +7 -5
  100. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  101. package/dist/kdf/argon2-core.js.map +1 -1
  102. package/dist/kdf/argon2-memory.js.map +1 -1
  103. package/dist/kdf/argon2-portable.js.map +1 -1
  104. package/dist/kdf/argon2.d.ts +7 -2
  105. package/dist/kdf/argon2.js.map +1 -1
  106. package/dist/kdf.d.ts +6 -0
  107. package/dist/keys/keys.d.ts +31 -6
  108. package/dist/keys/keys.js +315 -233
  109. package/dist/keys/keys.js.map +1 -1
  110. package/dist/keys.d.ts +11 -2
  111. package/dist/keys.js +2 -2
  112. package/dist/pem/pem.d.ts +1 -2
  113. package/dist/pem/pem.js +40 -25
  114. package/dist/pem/pem.js.map +1 -1
  115. package/dist/pem.d.ts +6 -0
  116. package/dist/pkcs/pfx.d.ts +2 -3
  117. package/dist/pkcs/pfx.js +142 -142
  118. package/dist/pkcs/pfx.js.map +1 -1
  119. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  120. package/dist/pkcs/pkcs12-mac.js +122 -122
  121. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  122. package/dist/pkcs/pkcs7.d.ts +24 -3
  123. package/dist/pkcs/pkcs7.js +294 -256
  124. package/dist/pkcs/pkcs7.js.map +1 -1
  125. package/dist/pkcs.d.ts +10 -1
  126. package/dist/pkcs.js +4 -4
  127. package/dist/result/result.d.ts +1 -2
  128. package/dist/result/result.js.map +1 -1
  129. package/dist/result.d.ts +6 -0
  130. package/dist/revocation/chain.d.ts +69 -16
  131. package/dist/revocation/chain.js +431 -303
  132. package/dist/revocation/chain.js.map +1 -1
  133. package/dist/revocation/crl.d.ts +67 -14
  134. package/dist/revocation/crl.js +656 -366
  135. package/dist/revocation/crl.js.map +1 -1
  136. package/dist/revocation/ocsp.d.ts +78 -24
  137. package/dist/revocation/ocsp.js +622 -436
  138. package/dist/revocation/ocsp.js.map +1 -1
  139. package/dist/revocation/revocation.d.ts +68 -14
  140. package/dist/revocation/revocation.js +195 -74
  141. package/dist/revocation/revocation.js.map +1 -1
  142. package/dist/revocation.d.ts +14 -5
  143. package/dist/revocation.js +4 -4
  144. package/dist/ssh/ssh.d.ts +2 -3
  145. package/dist/ssh/ssh.js +165 -170
  146. package/dist/ssh/ssh.js.map +1 -1
  147. package/dist/ssh/wire.d.ts +1 -2
  148. package/dist/ssh/wire.js +10 -10
  149. package/dist/ssh/wire.js.map +1 -1
  150. package/dist/ssh.d.ts +8 -0
  151. package/dist/verify/identity.d.ts +3 -4
  152. package/dist/verify/identity.js +33 -33
  153. package/dist/verify/identity.js.map +1 -1
  154. package/dist/verify/name-constraints.d.ts +9 -2
  155. package/dist/verify/policy.d.ts +9 -2
  156. package/dist/verify/verify.d.ts +85 -34
  157. package/dist/verify/verify.js +276 -226
  158. package/dist/verify/verify.js.map +1 -1
  159. package/dist/verify.d.ts +12 -2
  160. package/dist/x509/certificate.d.ts +4 -5
  161. package/dist/x509/certificate.js +40 -40
  162. package/dist/x509/certificate.js.map +1 -1
  163. package/dist/x509/csr.d.ts +3 -4
  164. package/dist/x509/csr.js +15 -15
  165. package/dist/x509/csr.js.map +1 -1
  166. package/dist/x509/extensions.d.ts +1 -2
  167. package/dist/x509/extensions.js +165 -165
  168. package/dist/x509/extensions.js.map +1 -1
  169. package/dist/x509/fingerprint.d.ts +1 -2
  170. package/dist/x509/fingerprint.js.map +1 -1
  171. package/dist/x509/name-text.d.ts +1 -2
  172. package/dist/x509/name-text.js.map +1 -1
  173. package/dist/x509/name.d.ts +1 -2
  174. package/dist/x509/name.js +15 -15
  175. package/dist/x509/name.js.map +1 -1
  176. package/dist/x509/parse.d.ts +9 -6
  177. package/dist/x509/parse.js +394 -394
  178. package/dist/x509/parse.js.map +1 -1
  179. package/dist/x509.d.ts +17 -4
  180. package/dist/x509.js +8 -8
  181. package/package.json +32 -33
  182. package/dist/internal/asn1/oids2.js +0 -75
  183. package/dist/internal/asn1/oids2.js.map +0 -1
package/dist/pkcs/pfx.js CHANGED
@@ -1,14 +1,14 @@
1
- import { DECODE_REFUSAL_CODES as e, failureResult as t, rethrowIfInvariant as n, throwMicro509Error as r } from "../result/result.js";
2
- import { DECODE_LIMIT_CODES as i, decodeRefusalOf as a } from "../internal/asn1/decode-refusal.js";
3
- import { bmpString as o, explicitContext as s, integerFromNumber as c, objectIdentifier as l, octetString as u, readElement as d, readRootElement as f, sequence as p, setOf as m, tlv as h } from "../internal/asn1/der.js";
4
- import { decodeIntegerNumber as g, decodeObjectIdentifier as _, decodeString as v, toHex as y } from "../internal/asn1/asn1.js";
5
- import { OIDS as b } from "../internal/asn1/oids2.js";
6
- import { createKdfBudget as x, decryptPbes2 as S, encryptPbes2 as C, isKdfIterationLimitError as w, isWrongPasswordError as T } from "../internal/crypto/pbes2.js";
7
- import { base64Encode as E } from "../internal/shared/base64.js";
8
- import { pemEncode as D, splitPemBlocksOrThrow as O } from "../pem/pem.js";
1
+ import { decodeIntegerNumber as e, decodeObjectIdentifier as t, decodeString as n, toHex as r } from "../internal/asn1/asn1.js";
2
+ import { berEncoding as i, berPrimitiveContent as a, berSequenceChildren as o, berStringContent as s, berToDefiniteLength as c, readBerRoot as l } from "../internal/asn1/ber.js";
3
+ import { DECODE_LIMIT_CODES as u, decodeRefusalOf as d } from "../internal/asn1/decode-refusal.js";
4
+ import { bmpString as f, explicitContext as p, integerFromNumber as m, objectIdentifier as h, octetString as g, readElement as _, readRootElement as v, sequence as y, setOf as b, tlv as x } from "../internal/asn1/der.js";
5
+ import { OIDS as S } from "../internal/asn1/oids.js";
6
+ import { createKdfBudget as C, decryptPbes2 as w, encryptPbes2 as T, isKdfIterationLimitError as E, isWrongPasswordError as D } from "../internal/crypto/pbes2.js";
7
+ import { base64Encode as O } from "../internal/shared/base64.js";
9
8
  import { exportPkcs8Der as k } from "../keys/keys.js";
10
- import { berEncoding as A, berPrimitiveContent as j, berSequenceChildren as M, berStringContent as N, berToDefiniteLength as P, readBerRoot as F } from "../internal/asn1/ber.js";
11
- import { createPkcs12MacData as I, parsePkcs12MacData as L } from "./pkcs12-mac.js";
9
+ import { pemEncode as A, splitPemBlocksOrThrow as j } from "../pem/pem.js";
10
+ import { createPkcs12MacData as M, parsePkcs12MacData as N } from "./pkcs12-mac.js";
11
+ import { DECODE_REFUSAL_CODES as P, failureResult as F, rethrowIfInvariant as I, throwMicro509Error as L } from "../result/result.js";
12
12
  import { parseCertificateDerOrThrow as R } from "../x509/parse.js";
13
13
  // src/pkcs/pfx.ts
14
14
  /**
@@ -66,12 +66,12 @@ async function createPfx(e) {
66
66
  }
67
67
  for (let t of e.privateKeys ?? []) n.push(createPrivateKeyBag(await normalizePrivateKey(t.privateKey), t.attributes));
68
68
  let r = [];
69
- if (t.length > 0 && r.push(createDataContentInfo(p(t))), n.length > 0) {
70
- let t = p(n);
69
+ if (t.length > 0 && r.push(createDataContentInfo(y(t))), n.length > 0) {
70
+ let t = y(n);
71
71
  r.push(e.encryption === void 0 ? createDataContentInfo(t) : await createEncryptedDataContentInfo(t, e.encryption));
72
72
  }
73
- let i = p(r), a = e.mac === void 0 ? void 0 : await I(i, e.mac), o = p([
74
- c(3),
73
+ let i = y(r), a = e.mac === void 0 ? void 0 : await M(i, e.mac), o = y([
74
+ m(3),
75
75
  createDataContentInfo(i),
76
76
  ...a === void 0 ? [] : [a.der]
77
77
  ]);
@@ -79,14 +79,14 @@ async function createPfx(e) {
79
79
  ok: !0,
80
80
  value: {
81
81
  der: o,
82
- pem: D("PKCS12", o),
83
- base64: E(o)
82
+ pem: A("PKCS12", o),
83
+ base64: O(o)
84
84
  }
85
85
  };
86
86
  }
87
87
  /** Shorthand for constructing a PFX creation failure result. */
88
- function pfxCreationFailure(e, n) {
89
- return t(e, n);
88
+ function pfxCreationFailure(e, t) {
89
+ return F(e, t);
90
90
  }
91
91
  /**
92
92
  * Decodes a BER- or DER-encoded PKCS#12/PFX container into its constituent bags.
@@ -111,41 +111,41 @@ function pfxCreationFailure(e, n) {
111
111
  * ```
112
112
  */
113
113
  async function parsePfxDer(e, t) {
114
- return await parsePfxDerWithBudget(e, t, x(t));
114
+ return await parsePfxDerWithBudget(e, t, C(t));
115
115
  }
116
- async function parsePfxDerWithBudget(t, r, i) {
116
+ async function parsePfxDerWithBudget(t, n, r) {
117
117
  try {
118
- let e = M(F(t));
119
- if (e.length < 2 || e.length > 3) return pfxFailure("malformed", "Malformed PFX structure");
120
- let n = e[0], a = e[1];
121
- if (n === void 0 || a === void 0) return pfxFailure("malformed", "Malformed PFX structure");
122
- if (g(j(t, n, 2)) !== 3) return pfxFailure("malformed", "Unsupported PFX version");
123
- let o = extractContentInfoData(t, a), s = e[2], c;
124
- if (s !== void 0) {
125
- let e = await verifyPfxMacData(P(t, s), o, r);
118
+ let i = o(l(t));
119
+ if (i.length < 2 || i.length > 3) return pfxFailure("malformed", "Malformed PFX structure");
120
+ let s = i[0], u = i[1];
121
+ if (s === void 0 || u === void 0) return pfxFailure("malformed", "Malformed PFX structure");
122
+ if (e(a(t, s, 2)) !== 3) return pfxFailure("malformed", "Unsupported PFX version");
123
+ let d = extractContentInfoData(t, u), f = i[2], p;
124
+ if (f !== void 0) {
125
+ let e = await verifyPfxMacData(c(t, f), d, n);
126
126
  if (e.error !== void 0) return e.error;
127
- c = e.macData;
127
+ p = e.macData;
128
128
  }
129
- let l = [];
130
- for (let e of M(F(o))) {
131
- let t = await extractSafeContents(o, e, r, i);
129
+ let m = [];
130
+ for (let e of o(l(d))) {
131
+ let t = await extractSafeContents(d, e, n, r);
132
132
  if (t.error !== void 0) return t.error;
133
- let n = t.data;
134
- for (let e of M(t.root)) l.push(parseSafeBag(n, e));
133
+ let i = t.data;
134
+ for (let e of o(t.root)) m.push(parseSafeBag(i, e));
135
135
  }
136
136
  return {
137
137
  ok: !0,
138
138
  value: {
139
- bags: l,
140
- certificates: l.flatMap((e) => e.kind === "certificate" ? [e.certificate] : []),
141
- privateKeys: l.flatMap((e) => e.kind === "privateKey" ? [e.pkcs8Der] : []),
142
- ...c === void 0 ? {} : { macData: c }
139
+ bags: m,
140
+ certificates: m.flatMap((e) => e.kind === "certificate" ? [e.certificate] : []),
141
+ privateKeys: m.flatMap((e) => e.kind === "privateKey" ? [e.pkcs8Der] : []),
142
+ ...p === void 0 ? {} : { macData: p }
143
143
  }
144
144
  };
145
- } catch (t) {
146
- n(t);
147
- let r = a(t, e);
148
- return r === void 0 ? pfxFailure("malformed", "Malformed PFX structure") : pfxFailure(r.code, r.message);
145
+ } catch (e) {
146
+ I(e);
147
+ let t = d(e, P);
148
+ return t === void 0 ? pfxFailure("malformed", "Malformed PFX structure") : pfxFailure(t.code, t.message);
149
149
  }
150
150
  }
151
151
  /**
@@ -164,9 +164,9 @@ async function parsePfxDerWithBudget(t, r, i) {
164
164
  * ```
165
165
  */
166
166
  async function parsePfxPem(e, t) {
167
- let n = x(t), r;
167
+ let n = C(t), r;
168
168
  try {
169
- let t = O(e).filter((e) => e.label === "PKCS12"), n = t[0];
169
+ let t = j(e).filter((e) => e.label === "PKCS12"), n = t[0];
170
170
  if (n === void 0 || t.length !== 1) return pfxFailure("malformed", "Expected exactly one PKCS12 PEM block");
171
171
  r = n.bytes;
172
172
  } catch {
@@ -175,171 +175,171 @@ async function parsePfxPem(e, t) {
175
175
  return await parsePfxDerWithBudget(r, t, n);
176
176
  }
177
177
  /** Shorthand for constructing a PFX parse failure result. */
178
- function pfxFailure(e, n) {
179
- return t(e, n);
178
+ function pfxFailure(e, t) {
179
+ return F(e, t);
180
180
  }
181
181
  /** Unwraps a `data` ContentInfo to its inner OCTET STRING payload. */
182
182
  function extractContentInfoData(e, t) {
183
183
  let { oid: n, content: r } = readContentInfo(e, t);
184
- if (n !== b.pkcs7Data) throw Error("Only passwordless data ContentInfo is supported");
184
+ if (n !== S.pkcs7Data) throw Error("Only passwordless data ContentInfo is supported");
185
185
  return extractContextOctetString(e, r);
186
186
  }
187
- function readContentInfo(e, t) {
188
- let n = M(t), r = n[0], i = n[1];
189
- if (r === void 0 || i === void 0 || n.length !== 2) throw Error("Malformed ContentInfo");
187
+ function readContentInfo(e, n) {
188
+ let r = o(n), i = r[0], s = r[1];
189
+ if (i === void 0 || s === void 0 || r.length !== 2) throw Error("Malformed ContentInfo");
190
190
  return {
191
- oid: _(j(e, r, 6)),
192
- content: i
191
+ oid: t(a(e, i, 6)),
192
+ content: s
193
193
  };
194
194
  }
195
195
  /** Extracts SafeContents bytes from a ContentInfo, decrypting if EncryptedData. */
196
- async function extractSafeContents(e, t, r, o) {
197
- let s, c;
196
+ async function extractSafeContents(e, t, n, r) {
197
+ let i, a;
198
198
  try {
199
- ({oid: s, content: c} = readContentInfo(e, t));
199
+ ({oid: i, content: a} = readContentInfo(e, t));
200
200
  } catch (e) {
201
- n(e);
202
- let t = a(e, i);
201
+ I(e);
202
+ let t = d(e, u);
203
203
  return { error: t === void 0 ? pfxFailure("malformed", "Malformed ContentInfo") : pfxFailure(t.code, t.message) };
204
204
  }
205
- if (s === b.pkcs7Data) {
206
- let t = extractContextOctetString(e, c);
205
+ if (i === S.pkcs7Data) {
206
+ let t = extractContextOctetString(e, a);
207
207
  return {
208
208
  data: t,
209
- root: F(t)
209
+ root: l(t)
210
210
  };
211
211
  }
212
- if (s !== b.pkcs7EncryptedData) return { error: pfxFailure("malformed", "Unsupported PFX ContentInfo type") };
213
- if (r?.password === void 0) return { error: pfxFailure("password_required", "Password required for encrypted PFX content") };
214
- let l = extractContextChild(c), u;
212
+ if (i !== S.pkcs7EncryptedData) return { error: pfxFailure("malformed", "Unsupported PFX ContentInfo type") };
213
+ if (n?.password === void 0) return { error: pfxFailure("password_required", "Password required for encrypted PFX content") };
214
+ let s = extractContextChild(a), c;
215
215
  try {
216
- u = await decryptEncryptedData(e, l, r.password, o);
216
+ c = await decryptEncryptedData(e, s, n.password, r);
217
217
  } catch (e) {
218
- if (n(e), T(e)) return { error: pfxFailure("invalid_password", "Invalid PFX password or encrypted content") };
219
- if (w(e)) return { error: pfxFailure("kdf_iterations_exceeded", e.message) };
220
- let t = a(e, i);
218
+ if (I(e), D(e)) return { error: pfxFailure("invalid_password", "Invalid PFX password or encrypted content") };
219
+ if (E(e)) return { error: pfxFailure("kdf_iterations_exceeded", e.message) };
220
+ let t = d(e, u);
221
221
  return { error: t === void 0 ? pfxFailure("malformed", "Malformed PFX encrypted content") : pfxFailure(t.code, t.message) };
222
222
  }
223
223
  try {
224
- let e = F(u);
225
- return M(e), {
226
- data: u,
224
+ let e = l(c);
225
+ return o(e), {
226
+ data: c,
227
227
  root: e
228
228
  };
229
229
  } catch (e) {
230
- n(e);
231
- let t = a(e, i);
230
+ I(e);
231
+ let t = d(e, u);
232
232
  return t === void 0 ? { error: pfxFailure("invalid_password", "Invalid PFX password or encrypted content") } : { error: pfxFailure(t.code, t.message) };
233
233
  }
234
234
  }
235
235
  /** Encodes a certBag SafeBag wrapping a DER certificate with optional attributes. */
236
236
  function createCertificateBag(e, t) {
237
- let n = p([l(b.x509CertificateBagType), s(0, u(e))]);
238
- return p([
239
- l(b.pkcs12CertBag),
240
- s(0, n),
237
+ let n = y([h(S.x509CertificateBagType), p(0, g(e))]);
238
+ return y([
239
+ h(S.pkcs12CertBag),
240
+ p(0, n),
241
241
  ...encodeBagAttributes(t)
242
242
  ]);
243
243
  }
244
244
  /** Encodes a keyBag SafeBag wrapping PKCS#8 DER with optional attributes. */
245
245
  function createPrivateKeyBag(e, t) {
246
- return p([
247
- l(b.pkcs12KeyBag),
248
- s(0, e),
246
+ return y([
247
+ h(S.pkcs12KeyBag),
248
+ p(0, e),
249
249
  ...encodeBagAttributes(t)
250
250
  ]);
251
251
  }
252
252
  /** Wraps raw bytes in a `pkcs7-data` ContentInfo SEQUENCE. */
253
253
  function createDataContentInfo(e) {
254
- return p([l(b.pkcs7Data), s(0, u(e))]);
254
+ return y([h(S.pkcs7Data), p(0, g(e))]);
255
255
  }
256
256
  /** PBES2-encrypts data and wraps it in a `pkcs7-encryptedData` ContentInfo. */
257
257
  async function createEncryptedDataContentInfo(e, t) {
258
- let n = await C(e, t), r = p([c(0), p([
259
- l(b.pkcs7Data),
258
+ let n = await T(e, t), r = y([m(0), y([
259
+ h(S.pkcs7Data),
260
260
  n.algorithmIdentifierDer,
261
- h(128, n.encryptedData)
261
+ x(128, n.encryptedData)
262
262
  ])]);
263
- return p([l(b.pkcs7EncryptedData), s(0, r)]);
263
+ return y([h(S.pkcs7EncryptedData), p(0, r)]);
264
264
  }
265
265
  /** DER-encodes optional friendlyName / localKeyId into a SET OF SEQUENCE. */
266
266
  function encodeBagAttributes(e) {
267
267
  if (e === void 0) return [];
268
268
  let t = [];
269
- return e.friendlyName !== void 0 && t.push(p([l(b.friendlyName), m([encodeFriendlyName(e.friendlyName)])])), e.localKeyId !== void 0 && t.push(p([l(b.localKeyId), m([u(e.localKeyId)])])), t.length === 0 ? [] : [m(t)];
269
+ return e.friendlyName !== void 0 && t.push(y([h(S.friendlyName), b([encodeFriendlyName(e.friendlyName)])])), e.localKeyId !== void 0 && t.push(y([h(S.localKeyId), b([g(e.localKeyId)])])), t.length === 0 ? [] : [b(t)];
270
270
  }
271
271
  function encodeFriendlyName(e) {
272
- let refuse = () => r("invalid_friendly_name", "friendlyName must be a BMPString of 1 to 255 characters, none of them a surrogate, U+FFFE or U+FFFF");
272
+ let refuse = () => L("invalid_friendly_name", "friendlyName must be a BMPString of 1 to 255 characters, none of them a surrogate, U+FFFE or U+FFFF");
273
273
  if (e.length === 0 || e.length > 255) return refuse();
274
274
  try {
275
- return o(e);
275
+ return f(e);
276
276
  } catch {
277
277
  return refuse();
278
278
  }
279
279
  }
280
280
  /** Decodes a single SafeBag into a {@linkcode ParsedPfxBag} discriminated union. */
281
- function parseSafeBag(e, t) {
282
- let n = M(t), r = n[0], i = n[1], a = n[2];
283
- if (r === void 0 || i === void 0 || n.length > 3) throw Error("Malformed SafeBag");
284
- let o = _(j(e, r, 6)), s = parseBagAttributes(e, a), c = extractContextChild(i);
285
- if (o === b.pkcs12CertBag) {
286
- let t = M(c), n = t[0], r = t[1];
287
- if (n === void 0 || r === void 0 || t.length !== 2 || _(j(e, n, 6)) !== b.x509CertificateBagType) throw Error("Malformed certBag");
281
+ function parseSafeBag(e, n) {
282
+ let r = o(n), s = r[0], l = r[1], u = r[2];
283
+ if (s === void 0 || l === void 0 || r.length > 3) throw Error("Malformed SafeBag");
284
+ let d = t(a(e, s, 6)), f = parseBagAttributes(e, u), p = extractContextChild(l);
285
+ if (d === S.pkcs12CertBag) {
286
+ let n = o(p), r = n[0], i = n[1];
287
+ if (r === void 0 || i === void 0 || n.length !== 2 || t(a(e, r, 6)) !== S.x509CertificateBagType) throw Error("Malformed certBag");
288
288
  return {
289
289
  kind: "certificate",
290
- bagId: o,
291
- attributes: s,
292
- certificate: R(extractContextOctetString(e, r))
290
+ bagId: d,
291
+ attributes: f,
292
+ certificate: R(extractContextOctetString(e, i))
293
293
  };
294
294
  }
295
- if (o === b.pkcs12KeyBag) {
296
- let t = A(e, c);
297
- return f(t), {
295
+ if (d === S.pkcs12KeyBag) {
296
+ let t = i(e, p);
297
+ return v(t), {
298
298
  kind: "privateKey",
299
- bagId: o,
300
- attributes: s,
299
+ bagId: d,
300
+ attributes: f,
301
301
  pkcs8Der: t
302
302
  };
303
303
  }
304
304
  return {
305
305
  kind: "unknown",
306
- bagId: o,
307
- attributes: s,
308
- valueDer: P(e, c)
306
+ bagId: d,
307
+ attributes: f,
308
+ valueDer: c(e, p)
309
309
  };
310
310
  }
311
311
  /** Decodes the SET OF attributes attached to a SafeBag. */
312
- function parseBagAttributes(e, t) {
313
- if (t === void 0) return { entries: [] };
314
- if (t.tag !== 49) throw Error("Malformed PFX bag attributes");
315
- let n = [], r, i;
316
- for (let a of t.children) {
317
- let t = M(a), o = t[0], s = t[1];
318
- if (o === void 0 || s === void 0 || t.length !== 2 || s.tag !== 49) throw Error("Malformed PFX bag attribute");
319
- let c = _(j(e, o, 6)), l = s.children.map((t) => P(e, t));
320
- if (n.push({
321
- oid: c,
322
- valuesHex: l.map((e) => y(e))
323
- }), c === b.friendlyName) {
324
- let e = l[0];
325
- if (r !== void 0 || l.length !== 1 || e === void 0) throw Error("Malformed friendlyName attribute");
326
- r = decodeFriendlyName(e);
327
- } else if (c === b.localKeyId) {
328
- let e = l[0];
329
- if (i !== void 0 || l.length !== 1 || e === void 0) throw Error("Malformed localKeyId attribute");
330
- i = decodeLocalKeyId(e);
312
+ function parseBagAttributes(e, n) {
313
+ if (n === void 0) return { entries: [] };
314
+ if (n.tag !== 49) throw Error("Malformed PFX bag attributes");
315
+ let i = [], s, l;
316
+ for (let u of n.children) {
317
+ let n = o(u), d = n[0], f = n[1];
318
+ if (d === void 0 || f === void 0 || n.length !== 2 || f.tag !== 49) throw Error("Malformed PFX bag attribute");
319
+ let p = t(a(e, d, 6)), m = f.children.map((t) => c(e, t));
320
+ if (i.push({
321
+ oid: p,
322
+ valuesHex: m.map((e) => r(e))
323
+ }), p === S.friendlyName) {
324
+ let e = m[0];
325
+ if (s !== void 0 || m.length !== 1 || e === void 0) throw Error("Malformed friendlyName attribute");
326
+ s = decodeFriendlyName(e);
327
+ } else if (p === S.localKeyId) {
328
+ let e = m[0];
329
+ if (l !== void 0 || m.length !== 1 || e === void 0) throw Error("Malformed localKeyId attribute");
330
+ l = decodeLocalKeyId(e);
331
331
  }
332
332
  }
333
333
  return {
334
- entries: n,
335
- ...r === void 0 ? {} : { friendlyName: r },
336
- ...i === void 0 ? {} : { localKeyId: i }
334
+ entries: i,
335
+ ...s === void 0 ? {} : { friendlyName: s },
336
+ ...l === void 0 ? {} : { localKeyId: l }
337
337
  };
338
338
  }
339
339
  function decodeLocalKeyId(e) {
340
- let t = d(e);
340
+ let t = _(e);
341
341
  if (t.tag !== 4) throw Error("localKeyId must use OCTET STRING");
342
- return y(t.value);
342
+ return r(t.value);
343
343
  }
344
344
  /** Exports a `CryptoKey` to PKCS#8 DER, or passes raw bytes through. */
345
345
  function normalizePrivateKey(e) {
@@ -348,7 +348,7 @@ function normalizePrivateKey(e) {
348
348
  /** Extracts DER bytes from a PEM string, or passes raw DER through. */
349
349
  function normalizeCertificate(e) {
350
350
  if (typeof e == "string") {
351
- let t = O(e).find((e) => e.label === "CERTIFICATE");
351
+ let t = j(e).find((e) => e.label === "CERTIFICATE");
352
352
  if (t === void 0) throw Error("Certificate PEM required");
353
353
  return new Uint8Array(t.bytes);
354
354
  }
@@ -356,20 +356,20 @@ function normalizeCertificate(e) {
356
356
  }
357
357
  /** Parses the MacData block and verifies it against the AuthenticatedSafe when a password is given. */
358
358
  async function verifyPfxMacData(e, t, n) {
359
- let r = await L(e, t, n?.macPassword ?? n?.password, n);
359
+ let r = await N(e, t, n?.macPassword ?? n?.password, n);
360
360
  return r.ok ? r.value.verification === "invalid" ? { error: pfxFailure("invalid_password", "Invalid PFX MAC password or corrupted content") } : { macData: r.value } : { error: r.code === "malformed" ? pfxFailure("malformed", "Malformed PFX MacData") : pfxFailure(r.code, r.message) };
361
361
  }
362
362
  /** Decrypts a PKCS#7 EncryptedData structure using PBES2 with the given password. */
363
- function decryptEncryptedData(e, t, n, r) {
364
- let i = M(t), a = i[0], o = i[1];
365
- if (i.length !== 2 || a === void 0 || o === void 0 || g(j(e, a, 2)) !== 0) throw Error("Malformed EncryptedData");
366
- let s = M(o), c = s[0], l = s[1], u = s[2];
367
- if (c === void 0 || l === void 0 || u === void 0 || s.length !== 3) throw Error("Malformed EncryptedContentInfo");
368
- return j(e, c, 6), S(P(e, l), N(e, u, 128, 4), n, r);
363
+ function decryptEncryptedData(t, n, r, i) {
364
+ let l = o(n), u = l[0], d = l[1];
365
+ if (l.length !== 2 || u === void 0 || d === void 0 || e(a(t, u, 2)) !== 0) throw Error("Malformed EncryptedData");
366
+ let f = o(d), p = f[0], m = f[1], h = f[2];
367
+ if (p === void 0 || m === void 0 || h === void 0 || f.length !== 3) throw Error("Malformed EncryptedContentInfo");
368
+ return a(t, p, 6), w(c(t, m), s(t, h, 128, 4), r, i);
369
369
  }
370
370
  /** Reads the OCTET STRING inside a `[0] EXPLICIT` wrapper. */
371
371
  function extractContextOctetString(e, t) {
372
- return N(e, extractContextChild(t), 4);
372
+ return s(e, extractContextChild(t), 4);
373
373
  }
374
374
  /** Reads the single child element inside a `[0] EXPLICIT` wrapper. */
375
375
  function extractContextChild(e) {
@@ -380,11 +380,11 @@ function extractContextChild(e) {
380
380
  }
381
381
  /** RFC 2985 §5.5.1: a friendlyName value is a BMPString of SIZE (1..255). */
382
382
  function decodeFriendlyName(e) {
383
- let t = d(e);
383
+ let t = _(e);
384
384
  if (t.tag !== 30) throw Error("friendlyName must be a BMPString");
385
- let n = v(30, t.value);
386
- if (n.length < 1 || n.length > 255) throw Error("friendlyName must hold 1 to 255 characters");
387
- return n;
385
+ let r = n(30, t.value);
386
+ if (r.length < 1 || r.length > 255) throw Error("friendlyName must hold 1 to 255 characters");
387
+ return r;
388
388
  }
389
389
  export { createPfx, parsePfxDer, parsePfxPem };
390
390