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
@@ -1,17 +1,17 @@
1
- import { DECODE_REFUSAL_CODES as e, failureResult as t, rethrowIfInvariant as n } from "../result/result.js";
2
- import { decodeRefusalOf as r } from "../internal/asn1/decode-refusal.js";
3
- import { explicitContext as i, integer as a, integerFromNumber as o, objectIdentifier as s, octetString as c, readElement as l, readRootElement as u, readSequenceChildren as d, sequence as f, setOf as p } from "../internal/asn1/der.js";
4
- import { childrenOf as m, decodeIntegerNumber as h, decodeObjectIdentifier as g, decodeString as _, hexToBytes as v, requireElement as y, toArrayBuffer as b, toHex as x } from "../internal/asn1/asn1.js";
5
- import { OIDS as S } from "../internal/asn1/oids2.js";
6
- import { getCrypto as C } from "../internal/crypto/webcrypto.js";
7
- import { base64Encode as w } from "../internal/shared/base64.js";
8
- import { pemEncode as T, splitPemBlocksOrThrow as E } from "../pem/pem.js";
9
- import { getVerifySignatureConfigResult as D, verifySignedDataDetailed as O } from "../internal/crypto/sig-verify.js";
10
- import { encodeAlgorithmIdentifier as k, getSignatureAlgorithm as A, signBytes as j } from "../internal/crypto/signing.js";
11
- import { describeHashAlgorithm as M, describeSignatureAlgorithm as N } from "../internal/crypto/algorithm-names.js";
12
- import { nameFieldKeyFromOid as P } from "../internal/x509/name-fields.js";
13
- import { compareDistinguishedNames as F } from "../internal/shared/dn.js";
14
- import { parseCertificateDerOrThrow as I } from "../x509/parse.js";
1
+ import { childrenOf as e, decodeIntegerNumber as t, decodeObjectIdentifier as n, decodeString as r, hexToBytes as i, requireElement as a, toArrayBuffer as o, toHex as s } from "../internal/asn1/asn1.js";
2
+ import { decodeRefusalOf as c } from "../internal/asn1/decode-refusal.js";
3
+ import { explicitContext as l, integer as u, integerFromNumber as d, objectIdentifier as f, octetString as p, readElement as m, readRootElement as h, readSequenceChildren as g, sequence as _, setOf as v } from "../internal/asn1/der.js";
4
+ import { OIDS as y } from "../internal/asn1/oids.js";
5
+ import { describeHashAlgorithm as b, describeSignatureAlgorithm as x } from "../internal/crypto/algorithm-names.js";
6
+ import { callerVerification as S, getVerifySignatureConfigResult as C, verifySignedDataDetailed as w } from "../internal/crypto/sig-verify.js";
7
+ import { encodeAlgorithmIdentifier as T, getSignatureAlgorithm as E, signBytes as D } from "../internal/crypto/signing.js";
8
+ import { getCrypto as O } from "../internal/crypto/webcrypto.js";
9
+ import { base64Encode as k } from "../internal/shared/base64.js";
10
+ import { compareDistinguishedNames as A } from "../internal/shared/dn.js";
11
+ import { pemEncode as j, splitPemBlocksOrThrow as M } from "../pem/pem.js";
12
+ import { DECODE_REFUSAL_CODES as N, failureResult as P, rethrowIfInvariant as F } from "../result/result.js";
13
+ import { nameFieldKeyFromOid as I } from "../internal/x509/name-fields.js";
14
+ import { parseCertificateDerOrThrow as L } from "../x509/parse.js";
15
15
  // src/pkcs/pkcs7.ts
16
16
  /**
17
17
  * PKCS#7/CMS certificate bags and SignedData.
@@ -25,37 +25,37 @@ import { parseCertificateDerOrThrow as I } from "../x509/parse.js";
25
25
  * @module
26
26
  */
27
27
  /** RFC 7468 Section 8 armors an RFC 2315 ContentInfo; Section 9 armors an RFC 5652 one. */
28
- const L = ["PKCS7", "CMS"];
28
+ const R = ["PKCS7", "CMS"];
29
29
  /**
30
30
  * Creates a degenerate PKCS#7 SignedData structure containing only
31
31
  * certificates (no signers), returning DER, PEM, and base64 forms, or a
32
32
  * typed `invalid_certificate` failure when a certificate source is not
33
33
  * valid PEM/DER.
34
34
  */
35
- function createPkcs7CertBag(t) {
36
- let n;
35
+ function createPkcs7CertBag(e) {
36
+ let t;
37
37
  try {
38
- n = t.flatMap(normalizeCertificateSource);
39
- for (let e of n) I(e);
40
- } catch (t) {
41
- let n = r(t, e);
42
- return n === void 0 ? createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER") : createCertBagFailure(n.code, n.message);
38
+ t = e.flatMap(normalizeCertificateSource);
39
+ for (let e of t) L(e);
40
+ } catch (e) {
41
+ let t = c(e, N);
42
+ return t === void 0 ? createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER") : createCertBagFailure(t.code, t.message);
43
43
  }
44
- let a = new Uint8Array(p(n));
45
- a[0] = 160;
46
- let c = f([
47
- o(1),
48
- p([]),
49
- f([s(S.pkcs7Data)]),
50
- a,
51
- p([])
52
- ]), l = f([s(S.pkcs7SignedData), i(0, c)]);
44
+ let n = new Uint8Array(v(t));
45
+ n[0] = 160;
46
+ let r = _([
47
+ d(1),
48
+ v([]),
49
+ _([f(y.pkcs7Data)]),
50
+ n,
51
+ v([])
52
+ ]), i = _([f(y.pkcs7SignedData), l(0, r)]);
53
53
  return {
54
54
  ok: !0,
55
55
  value: {
56
- der: l,
57
- pem: T("PKCS7", l),
58
- base64: w(l)
56
+ der: i,
57
+ pem: j("PKCS7", i),
58
+ base64: k(i)
59
59
  }
60
60
  };
61
61
  }
@@ -79,38 +79,38 @@ function createPkcs7CertBag(t) {
79
79
  * certificate whose public key cannot verify the signer key's algorithm, or an
80
80
  * unsupported signer key).
81
81
  */
82
- async function createPkcs7SignedData(t) {
83
- if (t.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
84
- let n = t.encapsulatedContentTypeOid ?? S.pkcs7Data, a = t.content.slice(), l = [], u = /* @__PURE__ */ new Set(), addCertificate = (e) => {
85
- let t = x(e);
86
- u.has(t) || (u.add(t), l.push(e));
87
- }, d = /* @__PURE__ */ new Set(), m = [];
88
- for (let e of t.signers) {
89
- let t = await buildPkcs7SignerInfo(e, a, n);
90
- if (!t.ok) return t;
91
- addCertificate(t.certificateDer), d.add(t.digestOid), m.push(t.signerInfoDer);
82
+ async function createPkcs7SignedData(e) {
83
+ if (e.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
84
+ let t = e.encapsulatedContentTypeOid ?? y.pkcs7Data, n = new Uint8Array(e.content), r = [], i = /* @__PURE__ */ new Set(), addCertificate = (e) => {
85
+ let t = s(e);
86
+ i.has(t) || (i.add(t), r.push(e));
87
+ }, a = /* @__PURE__ */ new Set(), o = [];
88
+ for (let r of e.signers) {
89
+ let e = await buildPkcs7SignerInfo(r, n, t);
90
+ if (!e.ok) return e;
91
+ addCertificate(e.certificateDer), a.add(e.digestOid), o.push(e.signerInfoDer);
92
92
  }
93
- for (let n of t.additionalCertificates ?? []) try {
94
- for (let e of normalizeCertificateSource(n)) I(e), addCertificate(e);
95
- } catch (t) {
96
- let n = r(t, e);
97
- return n === void 0 ? createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER") : createPkcs7Failure(n.code, n.message);
93
+ for (let t of e.additionalCertificates ?? []) try {
94
+ for (let e of normalizeCertificateSource(t)) L(e), addCertificate(e);
95
+ } catch (e) {
96
+ let t = c(e, N);
97
+ return t === void 0 ? createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER") : createPkcs7Failure(t.code, t.message);
98
98
  }
99
- let h = n === S.pkcs7Data ? 1 : 3, g = new Uint8Array(p(l));
100
- g[0] = 160;
101
- let _ = f([
102
- o(h),
103
- p([...d].map((e) => f([s(e)]))),
104
- t.detached === !0 ? f([s(n)]) : f([s(n), i(0, c(a))]),
105
- g,
106
- p(m)
107
- ]), v = f([s(S.pkcs7SignedData), i(0, _)]);
99
+ let u = t === y.pkcs7Data ? 1 : 3, m = new Uint8Array(v(r));
100
+ m[0] = 160;
101
+ let h = _([
102
+ d(u),
103
+ v([...a].map((e) => _([f(e)]))),
104
+ e.detached === !0 ? _([f(t)]) : _([f(t), l(0, p(n))]),
105
+ m,
106
+ v(o)
107
+ ]), g = _([f(y.pkcs7SignedData), l(0, h)]);
108
108
  return {
109
109
  ok: !0,
110
110
  value: {
111
- der: v,
112
- pem: T(h === 1 ? "PKCS7" : "CMS", v),
113
- base64: w(v)
111
+ der: g,
112
+ pem: j(u === 1 ? "PKCS7" : "CMS", g),
113
+ base64: k(g)
114
114
  }
115
115
  };
116
116
  }
@@ -120,49 +120,49 @@ async function createPkcs7SignedData(t) {
120
120
  * caller-correctable input — malformed PEM/DER, unsupported key — so each is
121
121
  * mapped to a typed failure rather than rejecting the public Promise.
122
122
  */
123
- async function buildPkcs7SignerInfo(t, n, i) {
124
- let l;
123
+ async function buildPkcs7SignerInfo(e, t, n) {
124
+ let r;
125
125
  try {
126
- l = normalizeCertificateSource(t.certificate);
126
+ r = normalizeCertificateSource(e.certificate);
127
127
  } catch {
128
128
  return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate source must be valid PEM or DER");
129
129
  }
130
- let u = l[0];
131
- if (u === void 0 || l.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
132
- let d;
130
+ let a = r[0];
131
+ if (a === void 0 || r.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
132
+ let s;
133
133
  try {
134
- d = I(u);
135
- } catch (t) {
136
- let n = r(t, e);
137
- return n === void 0 ? createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate") : createPkcs7Failure(n.code, n.message);
134
+ s = L(a);
135
+ } catch (e) {
136
+ let t = c(e, N);
137
+ return t === void 0 ? createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate") : createPkcs7Failure(t.code, t.message);
138
138
  }
139
- let p;
139
+ let l;
140
140
  try {
141
- p = A(t.privateKey, t.signature);
141
+ l = E(e.privateKey, e.signature);
142
142
  } catch {
143
143
  return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key or signature profile");
144
144
  }
145
- if (!D(p.algorithmOid, p.parameters, d.publicKeyAlgorithmOid, d.publicKeyParametersOid, "signer").ok) return createPkcs7Failure("signer_certificate_key_mismatch", "Each PKCS#7 signer certificate must carry a public key that verifies the signer key algorithm");
146
- let m = contentDigestForPrivateKey(t.privateKey);
145
+ if (!C(l.algorithmOid, l.parameters, s.publicKeyAlgorithmOid, s.publicKeyParametersOid, "signer").ok) return createPkcs7Failure("signer_certificate_key_mismatch", "Each PKCS#7 signer certificate must carry a public key that verifies the signer key algorithm");
146
+ let m = contentDigestForPrivateKey(e.privateKey);
147
147
  if (m === void 0) return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key algorithm for content digest");
148
- let { setForSigning: h, implicitForEmit: g } = buildSignedAttributes(i, new Uint8Array(await C().subtle.digest(m.hashName, b(n)))), _;
148
+ let { setForSigning: h, implicitForEmit: g } = buildSignedAttributes(n, new Uint8Array(await O().subtle.digest(m.hashName, o(t)))), v;
149
149
  try {
150
- _ = await j(t.privateKey, p, h);
150
+ v = await D(e.privateKey, l, h);
151
151
  } catch {
152
152
  return createPkcs7Failure("unsupported_signer_key", "Signer key could not produce a PKCS#7 signature");
153
153
  }
154
154
  return {
155
155
  ok: !0,
156
- signerInfoDer: f([
157
- o(1),
158
- f([v(d.issuer.derHex), a(v(d.serialNumberHex))]),
159
- f([s(m.digestOid)]),
156
+ signerInfoDer: _([
157
+ d(1),
158
+ _([i(s.issuer.derHex), u(i(s.serialNumberHex))]),
159
+ _([f(m.digestOid)]),
160
160
  g,
161
- k(p),
162
- c(_)
161
+ T(l),
162
+ p(v)
163
163
  ]),
164
164
  digestOid: m.digestOid,
165
- certificateDer: u
165
+ certificateDer: a
166
166
  };
167
167
  }
168
168
  /** Parses a DER-encoded PKCS#7 cert bag, returning the contained certificates. */
@@ -176,7 +176,7 @@ function parsePkcs7CertBagDer(e) {
176
176
  /** The DER of the single `PKCS7` or `CMS` block in `pem`, or a typed failure. */
177
177
  function contentInfoPemBytes(e) {
178
178
  try {
179
- let t = E(e).filter((e) => L.some((t) => t === e.label)), n = t[0];
179
+ let t = M(e).filter((e) => R.some((t) => t === e.label)), n = t[0];
180
180
  return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block") : {
181
181
  ok: !0,
182
182
  bytes: n.bytes
@@ -191,35 +191,35 @@ function parsePkcs7CertBagPem(e) {
191
191
  return t.ok ? parsePkcs7CertBagDer(t.bytes) : t;
192
192
  }
193
193
  /** Decodes a DER-encoded PKCS#7 ContentInfo expecting `signedData` content type. */
194
- function parsePkcs7SignedDataDer(t) {
194
+ function parsePkcs7SignedDataDer(r) {
195
195
  try {
196
- let e = d(t, { maxDepth: 64 }), n = e[0], r = e[1];
197
- if (n === void 0 || e.length > 2 || n.tag !== 6 || r !== void 0 && (r.tag !== 160 || m(t, r).length !== 1)) return pkcs7Failure("malformed", "Malformed PKCS#7 content info");
198
- let i = g(n.value);
199
- if (i !== S.pkcs7SignedData) return pkcs7Failure("not_signed_data", "PKCS#7 content is not signedData");
200
- if (r === void 0) return pkcs7Failure("malformed", "PKCS#7 signedData content info carries no content");
201
- let a = childAt(t, r, 0, "signedData"), o = m(t, a), s = o[0], c = o[1], l = o[2], u = o.slice(3), f = u[u.length - 1], p = parseSignedDataOptionalFields(u.slice(0, -1));
202
- if (!p.ok) return p;
203
- if (s === void 0 || c === void 0 || l === void 0 || f === void 0 || f.tag !== 49) return pkcs7Failure("malformed", "Malformed SignedData");
204
- let _ = t.slice(l.start - l.headerLength, l.end), v = d(_), y = v[0], b = v[1], x = parseDigestAlgorithms(t, c);
205
- return y === void 0 || v.length > 2 || y.tag !== 6 ? pkcs7Failure("malformed", "Malformed EncapsulatedContentInfo") : {
196
+ let i = g(r, { maxDepth: 64 }), a = i[0], o = i[1];
197
+ if (a === void 0 || i.length > 2 || a.tag !== 6 || o !== void 0 && (o.tag !== 160 || e(r, o).length !== 1)) return pkcs7Failure("malformed", "Malformed PKCS#7 content info");
198
+ let s = n(a.value);
199
+ if (s !== y.pkcs7SignedData) return pkcs7Failure("not_signed_data", "PKCS#7 content is not signedData");
200
+ if (o === void 0) return pkcs7Failure("malformed", "PKCS#7 signedData content info carries no content");
201
+ let c = childAt(r, o, 0, "signedData"), l = e(r, c), u = l[0], d = l[1], f = l[2], p = l.slice(3), m = p[p.length - 1], h = parseSignedDataOptionalFields(p.slice(0, -1));
202
+ if (!h.ok) return h;
203
+ if (u === void 0 || d === void 0 || f === void 0 || m === void 0 || m.tag !== 49) return pkcs7Failure("malformed", "Malformed SignedData");
204
+ let _ = r.slice(f.start - f.headerLength, f.end), v = g(_), x = v[0], S = v[1], C = parseDigestAlgorithms(r, d);
205
+ return x === void 0 || v.length > 2 || x.tag !== 6 ? pkcs7Failure("malformed", "Malformed EncapsulatedContentInfo") : {
206
206
  ok: !0,
207
207
  value: {
208
- der: new Uint8Array(t),
209
- contentTypeOid: i,
210
- version: h(s.value),
211
- digestAlgorithmOids: x,
212
- digestAlgorithmNames: x.map((e) => M(e)),
213
- encapsulatedContentTypeOid: g(y.value),
214
- ...b === void 0 ? {} : { encapsulatedContent: extractEncapsulatedContent(_, b) },
215
- certificateChoices: parseCertificateSet(t, p.value.certificates),
216
- signerInfos: parseSignerInfos(t, f)
208
+ der: new Uint8Array(r),
209
+ contentTypeOid: s,
210
+ version: t(u.value),
211
+ digestAlgorithmOids: C,
212
+ digestAlgorithmNames: C.map((e) => b(e)),
213
+ encapsulatedContentTypeOid: n(x.value),
214
+ ...S === void 0 ? {} : { encapsulatedContent: extractEncapsulatedContent(_, S) },
215
+ certificateChoices: parseCertificateSet(r, h.value.certificates),
216
+ signerInfos: parseSignerInfos(r, m)
217
217
  }
218
218
  };
219
- } catch (t) {
220
- n(t);
221
- let i = r(t, e);
222
- return i === void 0 ? pkcs7Failure("malformed", "Malformed PKCS#7 structure") : pkcs7Failure(i.code, i.message);
219
+ } catch (e) {
220
+ F(e);
221
+ let t = c(e, N);
222
+ return t === void 0 ? pkcs7Failure("malformed", "Malformed PKCS#7 structure") : pkcs7Failure(t.code, t.message);
223
223
  }
224
224
  }
225
225
  function parseSignedDataOptionalFields(e) {
@@ -251,6 +251,10 @@ function parsePkcs7SignedDataPem(e) {
251
251
  * Accepts PEM text, raw DER, or an already-parsed {@linkcode ParsedPkcs7SignedData}.
252
252
  * For each signer, locates the matching certificate in the embedded set and
253
253
  * verifies the signature (including signed-attribute digest checks per RFC 5652 Section 5.4).
254
+ * Defaults to id-data and requires signed attributes on every signer. Select
255
+ * `expectedContentTypeOid` from the application's protocol, not the input envelope.
256
+ * Legacy bare id-data signatures require `signedAttributes: 'allowed'` or 'forbidden'.
257
+ * Non-id-data always requires attributes (RFC 5652 §5.3).
254
258
  *
255
259
  * For a detached SignedData (absent `eContent`), pass the externally-held
256
260
  * content via `options.content`; without it, verification fails with the
@@ -273,24 +277,31 @@ function parsePkcs7SignedDataPem(e) {
273
277
  * ```
274
278
  */
275
279
  async function verifyPkcs7SignedData(e, t = {}) {
276
- let n = normalizePkcs7SignedDataForVerification(e);
280
+ let n = resolvePkcs7VerifyPolicy(t);
277
281
  if (!n.ok) return n;
278
- let r = n.value, i = r.encapsulatedContent ?? t.content?.slice();
279
- if (i === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
280
- if (r.signerInfos.length === 0) return verifyPkcs7Failure("no_signers", "SignedData contains no signer information");
281
- let a = [];
282
- for (let e of r.signerInfos) {
283
- let t = await verifyPkcs7SignerInfo(r, e, i);
282
+ let { expectedContentTypeOid: r, signedAttributes: i, verification: a } = n, o = normalizePkcs7SignedDataForVerification(e);
283
+ if (!o.ok) return o;
284
+ let s = o.value, c = s.encapsulatedContent ?? (t.content === void 0 ? void 0 : new Uint8Array(t.content));
285
+ if (c === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
286
+ if (s.signerInfos.length === 0) return verifyPkcs7Failure("no_signers", "SignedData contains no signer information");
287
+ if (s.encapsulatedContentTypeOid !== r) return verifyPkcs7Failure("content_type_mismatch", "Unexpected SignedData content type");
288
+ for (let e of s.signerInfos) {
289
+ if (!e.hasSignedAttrs && (i === "required" || s.encapsulatedContentTypeOid !== y.pkcs7Data)) return verifyPkcs7Failure("signed_attributes_required", "Signed attributes are required");
290
+ if (e.hasSignedAttrs && i === "forbidden") return verifyPkcs7Failure("signed_attributes_forbidden", "Signed attributes are forbidden");
291
+ }
292
+ let l = [];
293
+ for (let e of s.signerInfos) {
294
+ let t = await verifyPkcs7SignerInfo(s, e, c, a);
284
295
  if (!t.ok) return t;
285
- a.push({
296
+ l.push({
286
297
  signerInfo: e,
287
298
  certificate: t.certificate
288
299
  });
289
300
  }
290
301
  return {
291
302
  ok: !0,
292
- value: r,
293
- signers: a
303
+ value: s,
304
+ signers: l
294
305
  };
295
306
  }
296
307
  /** Normalizes encoded or parsed SignedData into a freshly parsed verification input. */
@@ -298,48 +309,75 @@ function normalizePkcs7SignedDataForVerification(e) {
298
309
  return typeof e == "string" ? parsePkcs7SignedDataPem(e) : e instanceof Uint8Array ? parsePkcs7SignedDataDer(e) : hasReparseablePkcs7SignedData(e) ? parsePkcs7SignedDataDer(new Uint8Array(e.der)) : verifyPkcs7Failure("malformed", "SignedData parsed input is malformed");
299
310
  }
300
311
  /** Resolves and verifies one signer entry in a parsed PKCS#7 SignedData value. */
301
- async function verifyPkcs7SignerInfo(e, t, n) {
302
- let r = x509CertificatesOf(e.certificateChoices).find((e) => signerIdentifierMatches(e, t));
303
- if (r === void 0) return verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates");
304
- let i = t.hasSignedAttrs ? await verifySignedAttrs(t, r, n, e.encapsulatedContentTypeOid) : await verifyPkcs7BareSignerInfo(t, r, n);
305
- return i.ok ? {
312
+ /** Validates the caller policy in {@linkcode VerifyPkcs7SignedDataOptions}. */
313
+ function resolvePkcs7VerifyPolicy(e) {
314
+ let t = e.signedAttributes ?? "required";
315
+ if (![
316
+ "required",
317
+ "allowed",
318
+ "forbidden"
319
+ ].includes(t)) return verifyPkcs7Failure("invalid_options", "Unknown signed-attribute policy");
320
+ let r;
321
+ try {
322
+ r = n(m(f(e.expectedContentTypeOid ?? y.pkcs7Data)).value);
323
+ } catch {
324
+ return verifyPkcs7Failure("invalid_options", "Expected content type must be an OID");
325
+ }
326
+ try {
327
+ let n = S(e.signatureVerifiers);
328
+ return {
329
+ ok: !0,
330
+ expectedContentTypeOid: r,
331
+ signedAttributes: t,
332
+ verification: n
333
+ };
334
+ } catch (e) {
335
+ if (e instanceof RangeError) return verifyPkcs7Failure("invalid_options", e.message);
336
+ throw e;
337
+ }
338
+ }
339
+ async function verifyPkcs7SignerInfo(e, t, n, r) {
340
+ let i = x509CertificatesOf(e.certificateChoices).find((e) => signerIdentifierMatches(e, t));
341
+ if (i === void 0) return verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates");
342
+ let a = t.hasSignedAttrs ? await verifySignedAttrs(t, i, n, e.encapsulatedContentTypeOid, r) : await verifyPkcs7BareSignerInfo(t, i, n, r);
343
+ return a.ok ? {
306
344
  ok: !0,
307
- certificate: r
308
- } : i;
345
+ certificate: i
346
+ } : a;
309
347
  }
310
- async function verifyPkcs7BareSignerInfo(e, t, n) {
348
+ async function verifyPkcs7BareSignerInfo(e, t, n, r) {
311
349
  try {
312
- let r = await O(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, n);
313
- return r.ok ? r.valid ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature does not verify") : r.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
350
+ let i = await w(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, 0, n, r);
351
+ return i.ok ? i.valid ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature does not verify") : i.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
314
352
  } catch (e) {
315
353
  return signatureVerificationThrowFailure(e);
316
354
  }
317
355
  }
318
356
  /** Shorthand for constructing a PKCS#7 parse failure result. */
319
- function pkcs7Failure(e, n) {
320
- return t(e, n);
357
+ function pkcs7Failure(e, t) {
358
+ return P(e, t);
321
359
  }
322
360
  /** Shorthand for constructing a PKCS#7 verification failure result. */
323
361
  /** A signer's signature verification that threw: its decode refusal, else `malformed`. */
324
- function signatureVerificationThrowFailure(t) {
325
- let n = r(t, e);
326
- return n === void 0 ? verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData") : verifyPkcs7Failure(n.code, n.message);
362
+ function signatureVerificationThrowFailure(e) {
363
+ let t = c(e, N);
364
+ return t === void 0 ? verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData") : verifyPkcs7Failure(t.code, t.message);
327
365
  }
328
- function verifyPkcs7Failure(e, n) {
329
- return t(e, n);
366
+ function verifyPkcs7Failure(e, t) {
367
+ return P(e, t);
330
368
  }
331
369
  /** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
332
- function createCertBagFailure(e, n) {
333
- return t(e, n);
370
+ function createCertBagFailure(e, t) {
371
+ return P(e, t);
334
372
  }
335
373
  /** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
336
- function createPkcs7Failure(e, n) {
337
- return t(e, n);
374
+ function createPkcs7Failure(e, t) {
375
+ return P(e, t);
338
376
  }
339
377
  /** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
340
378
  function normalizeCertificateSource(e) {
341
379
  if (typeof e == "string") {
342
- let t = E(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
380
+ let t = M(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
343
381
  if (t.length === 0) throw Error("Certificate PEM required");
344
382
  return t;
345
383
  }
@@ -368,15 +406,15 @@ function contentDigestForPrivateKey(e) {
368
406
  switch (t.namedCurve) {
369
407
  case "P-256": return {
370
408
  hashName: "SHA-256",
371
- digestOid: S.sha256
409
+ digestOid: y.sha256
372
410
  };
373
411
  case "P-384": return {
374
412
  hashName: "SHA-384",
375
- digestOid: S.sha384
413
+ digestOid: y.sha384
376
414
  };
377
415
  case "P-521": return {
378
416
  hashName: "SHA-512",
379
- digestOid: S.sha512
417
+ digestOid: y.sha512
380
418
  };
381
419
  default: return;
382
420
  }
@@ -386,22 +424,22 @@ function contentDigestForPrivateKey(e) {
386
424
  switch (t.hash.name) {
387
425
  case "SHA-256": return {
388
426
  hashName: "SHA-256",
389
- digestOid: S.sha256
427
+ digestOid: y.sha256
390
428
  };
391
429
  case "SHA-384": return {
392
430
  hashName: "SHA-384",
393
- digestOid: S.sha384
431
+ digestOid: y.sha384
394
432
  };
395
433
  case "SHA-512": return {
396
434
  hashName: "SHA-512",
397
- digestOid: S.sha512
435
+ digestOid: y.sha512
398
436
  };
399
437
  default: return;
400
438
  }
401
439
  }
402
440
  if (t.name === "Ed25519") return {
403
441
  hashName: "SHA-512",
404
- digestOid: S.sha512
442
+ digestOid: y.sha512
405
443
  };
406
444
  }
407
445
  /**
@@ -411,7 +449,7 @@ function contentDigestForPrivateKey(e) {
411
449
  * SignerInfo. The two differ only in the leading tag byte.
412
450
  */
413
451
  function buildSignedAttributes(e, t) {
414
- let n = p([f([s(S.cmsContentType), p([s(e)])]), f([s(S.cmsMessageDigest), p([c(t)])])]), r = new Uint8Array(n);
452
+ let n = v([_([f(y.cmsContentType), v([f(e)])]), _([f(y.cmsMessageDigest), v([p(t)])])]), r = new Uint8Array(n);
415
453
  return r[0] = 160, {
416
454
  setForSigning: n,
417
455
  implicitForEmit: r
@@ -427,17 +465,17 @@ function x509CertificatesOf(e) {
427
465
  * The IMPLICIT tag replaces the SEQUENCE tag, so the OID and the `ANY DEFINED BY`
428
466
  * value are direct children of the `[3]` element.
429
467
  */
430
- function parseOtherCertificateFormatOid(e, t) {
431
- let n = y(m(e, t)[0], "otherCertFormat");
432
- if (n.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
433
- return g(n.value);
468
+ function parseOtherCertificateFormatOid(t, r) {
469
+ let i = a(e(t, r)[0], "otherCertFormat");
470
+ if (i.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
471
+ return n(i.value);
434
472
  }
435
473
  /** Decodes one RFC 5652 §10.2.2 CertificateChoices alternative. */
436
474
  function parseCertificateChoice(e, t, n) {
437
475
  switch (t.tag) {
438
476
  case 48: return {
439
477
  type: "certificate",
440
- certificate: I(n)
478
+ certificate: L(n)
441
479
  };
442
480
  case 160: return {
443
481
  type: "extendedCertificate",
@@ -463,118 +501,118 @@ function parseCertificateChoice(e, t, n) {
463
501
  * Parses the IMPLICIT [0] certificate set from a SignedData structure as
464
502
  * RFC 5652 §10.2.3 `CertificateSet ::= SET OF CertificateChoices`.
465
503
  */
466
- function parseCertificateSet(e, t) {
467
- return t === void 0 || t.tag !== 160 ? [] : m(e, t).map((t) => parseCertificateChoice(e, t, e.slice(t.start - t.headerLength, t.end)));
504
+ function parseCertificateSet(t, n) {
505
+ return n === void 0 || n.tag !== 160 ? [] : e(t, n).map((e) => parseCertificateChoice(t, e, t.slice(e.start - e.headerLength, e.end)));
468
506
  }
469
507
  /** Extracts the list of digest algorithm OIDs from the digestAlgorithms SET. */
470
- function parseDigestAlgorithms(e, t) {
471
- let n = [];
472
- if (t.tag !== 49) throw Error("digestAlgorithms must use SET");
473
- for (let r of m(e, t)) {
474
- if (r.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
475
- let t = e.slice(r.start - r.headerLength, r.end), i = d(t), a = i[0];
476
- if (a === void 0 || i.length < 1 || i.length > 2 || a.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
477
- n.push(g(a.value));
508
+ function parseDigestAlgorithms(t, r) {
509
+ let i = [];
510
+ if (r.tag !== 49) throw Error("digestAlgorithms must use SET");
511
+ for (let a of e(t, r)) {
512
+ if (a.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
513
+ let e = t.slice(a.start - a.headerLength, a.end), r = g(e), o = r[0];
514
+ if (o === void 0 || r.length < 1 || r.length > 2 || o.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
515
+ i.push(n(o.value));
478
516
  }
479
- return n;
517
+ return i;
480
518
  }
481
519
  /** Decodes the signerInfos SET OF from a SignedData structure. */
482
- function parseSignerInfos(e, t) {
483
- return m(e, t).map((t) => parseSignerInfo(e, t));
484
- }
485
- function parseSignerInfo(e, t) {
486
- let n = e.slice(t.start - t.headerLength, t.end), r = d(n), i = r[0], a = r[1], o = r[2], s = 3, c = r[s]?.tag === 160 ? r[s] : void 0;
487
- c !== void 0 && (s += 1);
488
- let l = r[s], u = r[s + 1], f = r[s + 2];
489
- if (i === void 0 || a === void 0 || o === void 0 || l === void 0 || u === void 0 || u.tag !== 4 || r.length > s + 3 || f !== void 0 && f.tag !== 161) throw Error("Malformed SignerInfo");
490
- let p = parsePkcs7AlgorithmOid(n, o, "digest algorithm OID"), m = n.slice(l.start - l.headerLength, l.end), _ = d(m), v = g(y(_[0], "signature algorithm OID").value), b = _[1];
520
+ function parseSignerInfos(t, n) {
521
+ return e(t, n).map((e) => parseSignerInfo(t, e));
522
+ }
523
+ function parseSignerInfo(e, r) {
524
+ let i = e.slice(r.start - r.headerLength, r.end), o = g(i), c = o[0], l = o[1], u = o[2], d = 3, f = o[d]?.tag === 160 ? o[d] : void 0;
525
+ f !== void 0 && (d += 1);
526
+ let p = o[d], m = o[d + 1], h = o[d + 2];
527
+ if (c === void 0 || l === void 0 || u === void 0 || p === void 0 || m === void 0 || m.tag !== 4 || o.length > d + 3 || h !== void 0 && h.tag !== 161) throw Error("Malformed SignerInfo");
528
+ let _ = parsePkcs7AlgorithmOid(i, u, "digest algorithm OID"), v = i.slice(p.start - p.headerLength, p.end), y = g(v), S = n(a(y[0], "signature algorithm OID").value), C = y[1];
491
529
  return {
492
- version: h(i.value),
493
- signerIdentifier: parseSignerIdentifier(n.slice(a.start - a.headerLength, a.end)),
494
- digestAlgorithmOid: p,
495
- digestAlgorithmName: M(p),
496
- signatureAlgorithmOid: v,
497
- signatureAlgorithmName: N(v, b === void 0 ? void 0 : new Uint8Array(m.slice(b.start - b.headerLength, b.end))),
498
- ...b === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(m.slice(b.start - b.headerLength, b.end)) },
499
- signatureHex: x(u.value),
500
- signature: new Uint8Array(u.value),
501
- ...c === void 0 ? { hasSignedAttrs: !1 } : {
530
+ version: t(c.value),
531
+ signerIdentifier: parseSignerIdentifier(i.slice(l.start - l.headerLength, l.end)),
532
+ digestAlgorithmOid: _,
533
+ digestAlgorithmName: b(_),
534
+ signatureAlgorithmOid: S,
535
+ signatureAlgorithmName: x(S, C === void 0 ? void 0 : new Uint8Array(v.slice(C.start - C.headerLength, C.end))),
536
+ ...C === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(v.slice(C.start - C.headerLength, C.end)) },
537
+ signatureHex: s(m.value),
538
+ signature: new Uint8Array(m.value),
539
+ ...f === void 0 ? { hasSignedAttrs: !1 } : {
502
540
  hasSignedAttrs: !0,
503
- signedAttrsDer: new Uint8Array(n.slice(c.start - c.headerLength, c.end))
541
+ signedAttrsDer: new Uint8Array(i.slice(f.start - f.headerLength, f.end))
504
542
  }
505
543
  };
506
544
  }
507
- function parsePkcs7AlgorithmOid(e, t, n) {
508
- let r = e.slice(t.start - t.headerLength, t.end);
509
- return g(y(d(r)[0], n).value);
545
+ function parsePkcs7AlgorithmOid(e, t, r) {
546
+ let i = e.slice(t.start - t.headerLength, t.end);
547
+ return n(a(g(i)[0], r).value);
510
548
  }
511
549
  /** Unwraps the OCTET STRING inside the IMPLICIT [0] encapsulated content. */
512
550
  function extractEncapsulatedContent(e, t) {
513
551
  if (t.tag !== 160) throw Error("Unexpected encapsulated content tag");
514
- let n = l(e, t.start);
552
+ let n = m(e, t.start);
515
553
  if (n.tag !== 4) throw Error("Expected encapsulated OCTET STRING");
516
554
  if (n.end !== t.end) throw Error("Encapsulated content must hold exactly one element");
517
555
  return n.value;
518
556
  }
519
557
  /** Extracts issuer Name and serial number from an issuerAndSerialNumber SEQUENCE, or subjectKeyIdentifier from [0] IMPLICIT. */
520
558
  function parseSignerIdentifier(e) {
521
- let t = u(e, { maxDepth: 64 });
559
+ let t = h(e, { maxDepth: 64 });
522
560
  if (t.tag === 128) {
523
561
  if (t.value.length === 0) throw Error("SignerIdentifier subjectKeyIdentifier must not be empty");
524
562
  return {
525
563
  type: "subjectKeyIdentifier",
526
- subjectKeyIdentifier: x(t.value)
564
+ subjectKeyIdentifier: s(t.value)
527
565
  };
528
566
  }
529
567
  if (t.tag === 48) {
530
- let t = d(e), n = t[0], r = t[1];
568
+ let t = g(e), n = t[0], r = t[1];
531
569
  if (n === void 0 || r === void 0 || t.length !== 2) throw Error("SignerIdentifier issuerAndSerialNumber is malformed");
532
570
  if (n.tag !== 48) throw Error("SignerIdentifier issuer must use Name SEQUENCE");
533
571
  if (r.tag !== 2) throw Error("SignerIdentifier serialNumber must use INTEGER");
534
572
  return assertImplicitSerialNumberEncoding(r.value, "SignerIdentifier serialNumber"), {
535
573
  type: "issuerAndSerialNumber",
536
574
  issuer: parseSignerIssuerName(e, n),
537
- serialNumberHex: x(r.value)
575
+ serialNumberHex: s(r.value)
538
576
  };
539
577
  }
540
578
  throw Error(`Unsupported SignerIdentifier tag: ${String(t.tag)}`);
541
579
  }
542
580
  /** Parses a Name SEQUENCE element from a PKCS#7 signer identifier into a {@linkcode ParsedName}. */
543
- function parseSignerIssuerName(e, t) {
544
- let n = x(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
545
- for (let n of m(e, t)) {
546
- let t = [], o = {};
547
- for (let r of m(e, n)) {
548
- let n = m(e, r), s = y(n[0], "signer issuer attribute OID"), c = y(n[1], "signer issuer attribute value"), l = g(s.value), u = _(c.tag, c.value), d = P(l), f = d === void 0 ? {
549
- oid: l,
550
- valueTag: c.tag,
551
- value: u
581
+ function parseSignerIssuerName(t, i) {
582
+ let o = s(t.slice(i.start - i.headerLength, i.end)), c = [], l = [], u = {};
583
+ for (let o of e(t, i)) {
584
+ let i = [], d = {};
585
+ for (let s of e(t, o)) {
586
+ let o = e(t, s), c = a(o[0], "signer issuer attribute OID"), f = a(o[1], "signer issuer attribute value"), p = n(c.value), m = r(f.tag, f.value), h = I(p), g = h === void 0 ? {
587
+ oid: p,
588
+ valueTag: f.tag,
589
+ value: m
552
590
  } : {
553
- oid: l,
554
- key: d,
555
- valueTag: c.tag,
556
- value: u
591
+ oid: p,
592
+ key: h,
593
+ valueTag: f.tag,
594
+ value: m
557
595
  };
558
- t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
596
+ i.push(g), l.push(g), h !== void 0 && (d[h] === void 0 && (d[h] = m), u[h] === void 0 && (u[h] = m));
559
597
  }
560
- r.push({
561
- derHex: x(e.slice(n.start - n.headerLength, n.end)),
562
- attributes: t,
563
- values: o
598
+ c.push({
599
+ derHex: s(t.slice(o.start - o.headerLength, o.end)),
600
+ attributes: i,
601
+ values: d
564
602
  });
565
603
  }
566
604
  return {
567
- derHex: n,
568
- rdns: r,
569
- attributes: i,
570
- values: a
605
+ derHex: o,
606
+ rdns: c,
607
+ attributes: l,
608
+ values: u
571
609
  };
572
610
  }
573
611
  /** Returns the nth child element inside a constructed ASN.1 element, or throws. */
574
612
  function childAt(e, t, n, r) {
575
613
  let i = t.start, a = 0;
576
614
  for (; i < t.end;) {
577
- let t = l(e, i);
615
+ let t = m(e, i);
578
616
  if (a === n) return t;
579
617
  i = t.end, a += 1;
580
618
  }
@@ -583,40 +621,40 @@ function childAt(e, t, n, r) {
583
621
  /** Maps a digest algorithm OID to the WebCrypto hash name. */
584
622
  function digestAlgorithmHash(e) {
585
623
  switch (e) {
586
- case S.sha256: return "SHA-256";
587
- case S.sha384: return "SHA-384";
588
- case S.sha512: return "SHA-512";
624
+ case y.sha256: return "SHA-256";
625
+ case y.sha384: return "SHA-384";
626
+ case y.sha512: return "SHA-512";
589
627
  default: throw Error(`Unsupported digest algorithm OID: ${e}`);
590
628
  }
591
629
  }
592
630
  /** Parses required signed attributes and enforces uniqueness + exact-one-value shape. */
593
- function parseSignedAttributeRequirements(e) {
594
- let t = l(e), n = {};
595
- for (let r of m(e, t)) parseSignedAttributeRequirement(e, r, n);
596
- if (n.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
597
- if (n.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
631
+ function parseSignedAttributeRequirements(t) {
632
+ let n = m(t), r = {};
633
+ for (let i of e(t, n)) parseSignedAttributeRequirement(t, i, r);
634
+ if (r.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
635
+ if (r.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
598
636
  return {
599
- messageDigest: n.messageDigest,
600
- contentTypeOid: n.contentTypeOid
637
+ messageDigest: r.messageDigest,
638
+ contentTypeOid: r.contentTypeOid
601
639
  };
602
640
  }
603
- function parseSignedAttributeRequirement(e, t, n) {
604
- let r = e.slice(t.start - t.headerLength, t.end), i = d(r), a = i[0], o = i[1];
605
- if (a === void 0 || o === void 0 || i.length !== 2 || o.tag !== 49) throw Error("Malformed signedAttrs attribute");
606
- let s = g(a.value), c = m(r, o);
607
- s === S.cmsMessageDigest && (n.messageDigest = parseUniqueSignedAttributeOctetString(n.messageDigest, c, "messageDigest")), s === S.cmsContentType && (n.contentTypeOid = parseUniqueSignedAttributeOid(n.contentTypeOid, c, "contentType"));
641
+ function parseSignedAttributeRequirement(t, r, i) {
642
+ let a = t.slice(r.start - r.headerLength, r.end), o = g(a), s = o[0], c = o[1];
643
+ if (s === void 0 || c === void 0 || o.length !== 2 || c.tag !== 49) throw Error("Malformed signedAttrs attribute");
644
+ let l = n(s.value), u = e(a, c);
645
+ l === y.cmsMessageDigest && (i.messageDigest = parseUniqueSignedAttributeOctetString(i.messageDigest, u, "messageDigest")), l === y.cmsContentType && (i.contentTypeOid = parseUniqueSignedAttributeOid(i.contentTypeOid, u, "contentType"));
608
646
  }
609
647
  function parseUniqueSignedAttributeOctetString(e, t, n) {
610
648
  if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
611
- let r = y(t[0], `${n} attribute value`);
649
+ let r = a(t[0], `${n} attribute value`);
612
650
  if (r.tag !== 4) throw Error(`${n} attribute value must use OCTET STRING`);
613
651
  return r.value;
614
652
  }
615
- function parseUniqueSignedAttributeOid(e, t, n) {
616
- if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
617
- let r = y(t[0], `${n} attribute value`);
618
- if (r.tag !== 6) throw Error(`${n} attribute value must use OBJECT IDENTIFIER`);
619
- return g(r.value);
653
+ function parseUniqueSignedAttributeOid(e, t, r) {
654
+ if (e !== void 0 || t.length !== 1) throw Error(`${r} attribute must appear exactly once with one value`);
655
+ let i = a(t[0], `${r} attribute value`);
656
+ if (i.tag !== 6) throw Error(`${r} attribute value must use OBJECT IDENTIFIER`);
657
+ return n(i.value);
620
658
  }
621
659
  /** Replaces the IMPLICIT [0] tag (0xa0) with SET OF (0x31) per RFC 5652 Section 5.4. */
622
660
  function retagSignedAttrsAsSet(e) {
@@ -631,36 +669,36 @@ function constantTimeEqual(e, t) {
631
669
  return n === 0;
632
670
  }
633
671
  /** Verifies a signed-attributes flow: digest match + signature over re-tagged attrs. */
634
- async function verifySignedAttrs(t, i, a, o) {
635
- if (!t.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
636
- let s;
672
+ async function verifySignedAttrs(e, t, n, r, i) {
673
+ if (!e.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
674
+ let a;
637
675
  try {
638
- assertImplicitSignedAttrsDer(t.signedAttrsDer), s = parseSignedAttributeRequirements(t.signedAttrsDer);
639
- } catch (t) {
640
- n(t);
641
- let i = r(t, e);
642
- return i === void 0 ? verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData") : verifyPkcs7Failure(i.code, i.message);
676
+ assertImplicitSignedAttrsDer(e.signedAttrsDer), a = parseSignedAttributeRequirements(e.signedAttrsDer);
677
+ } catch (e) {
678
+ F(e);
679
+ let t = c(e, N);
680
+ return t === void 0 ? verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData") : verifyPkcs7Failure(t.code, t.message);
643
681
  }
644
- if (s.contentTypeOid !== o) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
645
- let c;
682
+ if (a.contentTypeOid !== r) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
683
+ let s;
646
684
  try {
647
- let e = digestAlgorithmHash(t.digestAlgorithmOid);
648
- c = new Uint8Array(await C().subtle.digest(e, b(a)));
685
+ let t = digestAlgorithmHash(e.digestAlgorithmOid);
686
+ s = new Uint8Array(await O().subtle.digest(t, o(n)));
649
687
  } catch {
650
688
  return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
651
689
  }
652
- if (!constantTimeEqual(c, s.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
690
+ if (!constantTimeEqual(s, a.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
653
691
  let l;
654
692
  try {
655
- l = retagSignedAttrsAsSet(t.signedAttrsDer);
693
+ l = retagSignedAttrsAsSet(e.signedAttrsDer);
656
694
  } catch {
657
695
  return verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData");
658
696
  }
659
697
  let u;
660
698
  try {
661
- let e = await O(t.signatureAlgorithmOid, t.signatureAlgorithmParametersDer, i.publicKeyAlgorithmOid, i.publicKeyParametersOid, i.subjectPublicKeyInfoDer, t.signature, l);
662
- if (!e.ok) return e.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
663
- u = e.valid;
699
+ let n = await w(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, 0, l, i);
700
+ if (!n.ok) return n.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
701
+ u = n.valid;
664
702
  } catch (e) {
665
703
  return signatureVerificationThrowFailure(e);
666
704
  }
@@ -668,10 +706,10 @@ async function verifySignedAttrs(t, i, a, o) {
668
706
  }
669
707
  function signerIdentifierMatches(e, t) {
670
708
  let n = t.signerIdentifier;
671
- return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && F(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
709
+ return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && A(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
672
710
  }
673
711
  function assertImplicitSignedAttrsDer(e) {
674
- if (l(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
712
+ if (m(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
675
713
  }
676
714
  function hasReparseablePkcs7SignedData(e) {
677
715
  return "der" in e && e.der instanceof Uint8Array;