micro509 0.12.0 → 0.14.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 (123) hide show
  1. package/README.md +78 -30
  2. package/dist/crypto/crypto.d.ts +73 -0
  3. package/dist/crypto/crypto.js +74 -0
  4. package/dist/crypto/crypto.js.map +1 -0
  5. package/dist/crypto.d.ts +4 -0
  6. package/dist/crypto.js +2 -0
  7. package/dist/der/der.d.ts +127 -0
  8. package/dist/der/der.js +171 -0
  9. package/dist/der/der.js.map +1 -0
  10. package/dist/der.d.ts +4 -0
  11. package/dist/der.js +4 -0
  12. package/dist/index.d.ts +13 -9
  13. package/dist/index.js +17 -15
  14. package/dist/internal/asn1/asn1.d.ts +20 -0
  15. package/dist/internal/asn1/asn1.js +80 -37
  16. package/dist/internal/asn1/asn1.js.map +1 -1
  17. package/dist/internal/asn1/der.d.ts +173 -0
  18. package/dist/internal/asn1/der.js +116 -38
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +7 -1
  21. package/dist/internal/asn1/oids2.js +9 -2
  22. package/dist/internal/asn1/oids2.js.map +1 -1
  23. package/dist/internal/crypto/algorithm-names.js +4 -0
  24. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  25. package/dist/internal/crypto/pbes2.d.ts +38 -0
  26. package/dist/internal/crypto/pbes2.js +9 -10
  27. package/dist/internal/crypto/pbes2.js.map +1 -1
  28. package/dist/internal/crypto/rsa-pss.js +2 -0
  29. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  30. package/dist/internal/crypto/sig-verify.d.ts +31 -0
  31. package/dist/internal/crypto/sig-verify.js +10 -8
  32. package/dist/internal/crypto/sig-verify.js.map +1 -1
  33. package/dist/internal/shared/base64.js +7 -1
  34. package/dist/internal/shared/base64.js.map +1 -1
  35. package/dist/internal/shared/dn.d.ts +16 -0
  36. package/dist/internal/shared/dn.js +149 -12
  37. package/dist/internal/shared/dn.js.map +1 -1
  38. package/dist/internal/shared/ip.d.ts +69 -0
  39. package/dist/internal/shared/ip.js +18 -1
  40. package/dist/internal/shared/ip.js.map +1 -1
  41. package/dist/internal/shared/rfc3454-tables.js +1782 -0
  42. package/dist/internal/shared/rfc3454-tables.js.map +1 -0
  43. package/dist/internal/verify/name-constraints-engine.js +47 -15
  44. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  45. package/dist/internal/verify/policy-engine.js +85 -94
  46. package/dist/internal/verify/policy-engine.js.map +1 -1
  47. package/dist/internal/verify/verify-path.d.ts +7 -0
  48. package/dist/internal/verify/verify-path.js +49 -45
  49. package/dist/internal/verify/verify-path.js.map +1 -1
  50. package/dist/internal/x509/directory-name.js +24 -0
  51. package/dist/internal/x509/directory-name.js.map +1 -0
  52. package/dist/internal/x509/extension-bits.js +14 -11
  53. package/dist/internal/x509/extension-bits.js.map +1 -1
  54. package/dist/internal/x509/extension-errors.d.ts +6 -0
  55. package/dist/internal/x509/extension-errors.js +20 -0
  56. package/dist/internal/x509/extension-errors.js.map +1 -0
  57. package/dist/internal/x509/extension-registry.js +113 -55
  58. package/dist/internal/x509/extension-registry.js.map +1 -1
  59. package/dist/internal/x509/general-name-tags.js +28 -0
  60. package/dist/internal/x509/general-name-tags.js.map +1 -0
  61. package/dist/internal/x509/general-name.js +97 -0
  62. package/dist/internal/x509/general-name.js.map +1 -0
  63. package/dist/internal/x509/name-fields.js +20 -10
  64. package/dist/internal/x509/name-fields.js.map +1 -1
  65. package/dist/keys/keys.d.ts +16 -2
  66. package/dist/keys/keys.js +311 -170
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +3 -2
  69. package/dist/keys.js +3 -2
  70. package/dist/pem/pem.d.ts +3 -2
  71. package/dist/pem/pem.js +112 -30
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pkcs/pkcs12-mac.js +3 -3
  74. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  75. package/dist/pkcs/pkcs7.d.ts +85 -21
  76. package/dist/pkcs/pkcs7.js +261 -186
  77. package/dist/pkcs/pkcs7.js.map +1 -1
  78. package/dist/pkcs.d.ts +2 -2
  79. package/dist/result/result.d.ts +18 -10
  80. package/dist/result/result.js +20 -12
  81. package/dist/result/result.js.map +1 -1
  82. package/dist/result.d.ts +2 -2
  83. package/dist/result.js +2 -2
  84. package/dist/revocation/chain.js +154 -103
  85. package/dist/revocation/chain.js.map +1 -1
  86. package/dist/revocation/crl.d.ts +13 -2
  87. package/dist/revocation/crl.js +415 -236
  88. package/dist/revocation/crl.js.map +1 -1
  89. package/dist/revocation/ocsp.d.ts +58 -17
  90. package/dist/revocation/ocsp.js +186 -174
  91. package/dist/revocation/ocsp.js.map +1 -1
  92. package/dist/revocation/revocation.d.ts +4 -4
  93. package/dist/revocation/revocation.js +48 -30
  94. package/dist/revocation/revocation.js.map +1 -1
  95. package/dist/revocation.d.ts +4 -4
  96. package/dist/revocation.js +5 -5
  97. package/dist/verify/identity.d.ts +2 -1
  98. package/dist/verify/identity.js +2 -1
  99. package/dist/verify/identity.js.map +1 -1
  100. package/dist/verify/policy.d.ts +6 -1
  101. package/dist/verify/verify.d.ts +18 -3
  102. package/dist/verify/verify.js +66 -41
  103. package/dist/verify/verify.js.map +1 -1
  104. package/dist/verify.d.ts +2 -1
  105. package/dist/verify.js +4 -3
  106. package/dist/x509/certificate.d.ts +36 -13
  107. package/dist/x509/certificate.js +36 -19
  108. package/dist/x509/certificate.js.map +1 -1
  109. package/dist/x509/csr.d.ts +6 -3
  110. package/dist/x509/extensions.d.ts +59 -22
  111. package/dist/x509/extensions.js +384 -117
  112. package/dist/x509/extensions.js.map +1 -1
  113. package/dist/x509/name-text.js +2 -0
  114. package/dist/x509/name-text.js.map +1 -1
  115. package/dist/x509/name.d.ts +8 -5
  116. package/dist/x509/name.js +17 -12
  117. package/dist/x509/name.js.map +1 -1
  118. package/dist/x509/parse.d.ts +104 -18
  119. package/dist/x509/parse.js +127 -163
  120. package/dist/x509/parse.js.map +1 -1
  121. package/dist/x509.d.ts +8 -5
  122. package/dist/x509.js +10 -8
  123. package/package.json +52 -34
@@ -1,51 +1,59 @@
1
- import { concatBytes as e, explicitContext as t, integer as n, integerFromNumber as r, nullValue as i, objectIdentifier as a, octetString as o, readElement as s, readRootElement as c, readSequenceChildren as l, sequence as u, setOf as d } from "../internal/asn1/der.js";
2
- import { childrenOf as f, decodeIntegerNumber as p, decodeObjectIdentifier as m, decodeString as h, hexToBytes as g, requireElement as _, toArrayBuffer as v, toHex as y } from "../internal/asn1/asn1.js";
3
- import { OIDS as b } from "../internal/asn1/oids2.js";
4
- import { getCrypto as x } from "../internal/crypto/webcrypto.js";
5
- import { base64Encode as S } from "../internal/shared/base64.js";
6
- import { failureResult as C } from "../result/result.js";
7
- import { pemEncode as w, splitPemBlocksOrThrow as T } from "../pem/pem.js";
8
- import { describeHashAlgorithm as E, describeSignatureAlgorithm as D } from "../internal/crypto/algorithm-names.js";
9
- import { nameFieldKeyFromOid as O } from "../internal/x509/name-fields.js";
10
- import { parseCertificateDerOrThrow as k } from "../x509/parse.js";
11
- import { verifySignedDataDetailed as A } from "../internal/crypto/sig-verify.js";
1
+ import { explicitContext as e, integer as t, integerFromNumber as n, objectIdentifier as r, octetString as i, readElement as a, readRootElement as o, readSequenceChildren as s, sequence as c, setOf as l } from "../internal/asn1/der.js";
2
+ import { childrenOf as u, decodeIntegerNumber as d, decodeObjectIdentifier as f, decodeString as p, hexToBytes as m, requireElement as h, toArrayBuffer as g, toHex as _ } from "../internal/asn1/asn1.js";
3
+ import { OIDS as v } from "../internal/asn1/oids2.js";
4
+ import { getCrypto as y } from "../internal/crypto/webcrypto.js";
5
+ import { base64Encode as b } from "../internal/shared/base64.js";
6
+ import { failureResult as x } from "../result/result.js";
7
+ import { pemEncode as S, splitPemBlocksOrThrow as C } from "../pem/pem.js";
8
+ import { describeHashAlgorithm as w, describeSignatureAlgorithm as T } from "../internal/crypto/algorithm-names.js";
9
+ import { nameFieldKeyFromOid as E } from "../internal/x509/name-fields.js";
10
+ import { compareDistinguishedNames as D } from "../internal/shared/dn.js";
11
+ import { parseCertificateDerOrThrow as O } from "../x509/parse.js";
12
+ import { getVerifySignatureConfigResult as k, verifySignedDataDetailed as A } from "../internal/crypto/sig-verify.js";
12
13
  import { encodeAlgorithmIdentifier as j, getSignatureAlgorithm as M, signBytes as N } from "../internal/crypto/signing.js";
13
- import { compareDistinguishedNames as P } from "../internal/shared/dn.js";
14
14
  //#region src/pkcs/pkcs7.ts
15
15
  /**
16
16
  * PKCS#7/CMS certificate bags and SignedData.
17
17
  *
18
- * Creates degenerate (signature-less) certificate bags, parses RFC 2315 / RFC 5652
19
- * SignedData structures, and verifies signer signatures including signed-attribute flows.
18
+ * Creates degenerate (signature-less) certificate bags, parses RFC 5652
19
+ * SignedData (and the RFC 2315 form whose contentInfo content is an OCTET
20
+ * STRING), and verifies signer signatures including signed-attribute flows.
21
+ * A CertificateSet is decoded as RFC 5652 §10.2.2 CertificateChoices, so an
22
+ * attribute certificate or other-format entry is preserved rather than dropped.
20
23
  *
21
24
  * @module
22
25
  */
26
+ /** RFC 7468 Section 8 armors an RFC 2315 ContentInfo; Section 9 armors an RFC 5652 one. */
27
+ const P = ["PKCS7", "CMS"];
23
28
  /**
24
29
  * Creates a degenerate PKCS#7 SignedData structure containing only
25
30
  * certificates (no signers), returning DER, PEM, and base64 forms, or a
26
31
  * typed `invalid_certificate` failure when a certificate source is not
27
32
  * valid PEM/DER.
28
33
  */
29
- function createPkcs7CertBag(n) {
34
+ function createPkcs7CertBag(t) {
30
35
  let i;
31
36
  try {
32
- i = n.flatMap(normalizeCertificateSource);
37
+ i = t.flatMap(normalizeCertificateSource);
38
+ for (let e of i) O(e);
33
39
  } catch {
34
40
  return createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER");
35
41
  }
36
- let o = u([
37
- r(1),
38
- d([]),
39
- u([a(b.pkcs7Data)]),
40
- t(0, e(i)),
41
- d([])
42
- ]), s = u([a(b.pkcs7SignedData), t(0, o)]);
42
+ let a = new Uint8Array(l(i));
43
+ a[0] = 160;
44
+ let o = c([
45
+ n(1),
46
+ l([]),
47
+ c([r(v.pkcs7Data)]),
48
+ a,
49
+ l([])
50
+ ]), s = c([r(v.pkcs7SignedData), e(0, o)]);
43
51
  return {
44
52
  ok: !0,
45
53
  value: {
46
54
  der: s,
47
- pem: w("PKCS7", s),
48
- base64: S(s)
55
+ pem: S("PKCS7", s),
56
+ base64: b(s)
49
57
  }
50
58
  };
51
59
  }
@@ -65,40 +73,41 @@ function createPkcs7CertBag(n) {
65
73
  *
66
74
  * Returns a {@linkcode CreatePkcs7SignedDataResult}: DER, PEM, and base64
67
75
  * forms on success, or a typed failure for caller-correctable input (no
68
- * signers, a signer source that is not exactly one certificate, or an
76
+ * signers, a signer source that is not exactly one certificate, a signer
77
+ * certificate whose public key cannot verify the signer key's algorithm, or an
69
78
  * unsupported signer key).
70
79
  */
71
- async function createPkcs7SignedData(e) {
72
- if (e.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
73
- let n = e.encapsulatedContentTypeOid ?? b.pkcs7Data, s = e.content.slice(), c = [], l = /* @__PURE__ */ new Set(), addCertificate = (e) => {
74
- let t = y(e);
75
- l.has(t) || (l.add(t), c.push(e));
76
- }, f = /* @__PURE__ */ new Set(), p = [];
77
- for (let t of e.signers) {
78
- let e = await buildPkcs7SignerInfo(t, s, n);
79
- if (!e.ok) return e;
80
- addCertificate(e.certificateDer), f.add(e.digestOid), p.push(e.signerInfoDer);
80
+ async function createPkcs7SignedData(t) {
81
+ if (t.signers.length === 0) return createPkcs7Failure("no_signers", "createPkcs7SignedData requires at least one signer");
82
+ let a = t.encapsulatedContentTypeOid ?? v.pkcs7Data, o = t.content.slice(), s = [], u = /* @__PURE__ */ new Set(), addCertificate = (e) => {
83
+ let t = _(e);
84
+ u.has(t) || (u.add(t), s.push(e));
85
+ }, d = /* @__PURE__ */ new Set(), f = [];
86
+ for (let e of t.signers) {
87
+ let t = await buildPkcs7SignerInfo(e, o, a);
88
+ if (!t.ok) return t;
89
+ addCertificate(t.certificateDer), d.add(t.digestOid), f.push(t.signerInfoDer);
81
90
  }
82
- for (let t of e.additionalCertificates ?? []) try {
83
- for (let e of normalizeCertificateSource(t)) k(e), addCertificate(e);
91
+ for (let e of t.additionalCertificates ?? []) try {
92
+ for (let t of normalizeCertificateSource(e)) O(t), addCertificate(t);
84
93
  } catch {
85
94
  return createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER");
86
95
  }
87
- let m = n === b.pkcs7Data ? 1 : 3, h = new Uint8Array(d(c));
88
- h[0] = 160;
89
- let g = u([
90
- r(m),
91
- d([...f].map((e) => u([a(e), i()]))),
92
- e.detached === !0 ? u([a(n)]) : u([a(n), t(0, o(s))]),
93
- h,
94
- d(p)
95
- ]), _ = u([a(b.pkcs7SignedData), t(0, g)]);
96
+ let p = a === v.pkcs7Data ? 1 : 3, m = new Uint8Array(l(s));
97
+ m[0] = 160;
98
+ let h = c([
99
+ n(p),
100
+ l([...d].map((e) => c([r(e)]))),
101
+ t.detached === !0 ? c([r(a)]) : c([r(a), e(0, i(o))]),
102
+ m,
103
+ l(f)
104
+ ]), g = c([r(v.pkcs7SignedData), e(0, h)]);
96
105
  return {
97
106
  ok: !0,
98
107
  value: {
99
- der: _,
100
- pem: w("PKCS7", _),
101
- base64: S(_)
108
+ der: g,
109
+ pem: S(p === 1 ? "PKCS7" : "CMS", g),
110
+ base64: b(g)
102
111
  }
103
112
  };
104
113
  }
@@ -108,46 +117,47 @@ async function createPkcs7SignedData(e) {
108
117
  * caller-correctable input — malformed PEM/DER, unsupported key — so each is
109
118
  * mapped to a typed failure rather than rejecting the public Promise.
110
119
  */
111
- async function buildPkcs7SignerInfo(e, t, s) {
112
- let c;
120
+ async function buildPkcs7SignerInfo(e, a, o) {
121
+ let s;
113
122
  try {
114
- c = normalizeCertificateSource(e.certificate);
123
+ s = normalizeCertificateSource(e.certificate);
115
124
  } catch {
116
125
  return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate source must be valid PEM or DER");
117
126
  }
118
- let l = c[0];
119
- if (l === void 0 || c.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
120
- let d;
127
+ let l = s[0];
128
+ if (l === void 0 || s.length !== 1) return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer must provide exactly one certificate");
129
+ let u;
121
130
  try {
122
- d = k(l);
131
+ u = O(l);
123
132
  } catch {
124
133
  return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate");
125
134
  }
126
- let f;
135
+ let d;
127
136
  try {
128
- f = M(e.privateKey, e.signature);
137
+ d = M(e.privateKey, e.signature);
129
138
  } catch {
130
139
  return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key or signature profile");
131
140
  }
132
- let p = contentDigestForPrivateKey(e.privateKey);
133
- if (p === void 0) return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key algorithm for content digest");
134
- let { setForSigning: m, implicitForEmit: h } = buildSignedAttributes(s, new Uint8Array(await x().subtle.digest(p.hashName, v(t)))), _;
141
+ if (!k(d.algorithmOid, d.parameters, u.publicKeyAlgorithmOid, u.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");
142
+ let f = contentDigestForPrivateKey(e.privateKey);
143
+ if (f === void 0) return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key algorithm for content digest");
144
+ let { setForSigning: p, implicitForEmit: h } = buildSignedAttributes(o, new Uint8Array(await y().subtle.digest(f.hashName, g(a)))), _;
135
145
  try {
136
- _ = await N(e.privateKey, f, m);
146
+ _ = await N(e.privateKey, d, p);
137
147
  } catch {
138
148
  return createPkcs7Failure("unsupported_signer_key", "Signer key could not produce a PKCS#7 signature");
139
149
  }
140
150
  return {
141
151
  ok: !0,
142
- signerInfoDer: u([
143
- r(1),
144
- u([g(d.issuer.derHex), n(g(d.serialNumberHex))]),
145
- u([a(p.digestOid), i()]),
152
+ signerInfoDer: c([
153
+ n(1),
154
+ c([m(u.issuer.derHex), t(m(u.serialNumberHex))]),
155
+ c([r(f.digestOid)]),
146
156
  h,
147
- j(f),
148
- o(_)
157
+ j(d),
158
+ i(_)
149
159
  ]),
150
- digestOid: p.digestOid,
160
+ digestOid: f.digestOid,
151
161
  certificateDer: l
152
162
  };
153
163
  }
@@ -156,43 +166,50 @@ function parsePkcs7CertBagDer(e) {
156
166
  let t = parsePkcs7SignedDataDer(e);
157
167
  return t.ok ? {
158
168
  ok: !0,
159
- value: t.value.certificates
169
+ value: x509CertificatesOf(t.value.certificateChoices)
160
170
  } : t;
161
171
  }
162
- /** Parses a PEM-armored PKCS#7 cert bag. Expects exactly one `PKCS7` PEM block. */
163
- function parsePkcs7CertBagPem(e) {
172
+ /** The DER of the single `PKCS7` or `CMS` block in `pem`, or a typed failure. */
173
+ function contentInfoPemBytes(e) {
164
174
  try {
165
- let t = T(e).filter((e) => e.label === "PKCS7");
166
- if (t.length !== 1) return pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block");
167
- let n = t[0];
168
- return n === void 0 ? pkcs7Failure("malformed", "Missing PKCS7 block") : parsePkcs7CertBagDer(n.bytes);
175
+ let t = C(e).filter((e) => P.some((t) => t === e.label)), n = t[0];
176
+ return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block") : {
177
+ ok: !0,
178
+ bytes: n.bytes
179
+ };
169
180
  } catch {
170
- return pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block");
181
+ return pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block");
171
182
  }
172
183
  }
184
+ /** Parses a PEM-armored PKCS#7/CMS cert bag. Expects exactly one `PKCS7` or `CMS` PEM block. */
185
+ function parsePkcs7CertBagPem(e) {
186
+ let t = contentInfoPemBytes(e);
187
+ return t.ok ? parsePkcs7CertBagDer(t.bytes) : t;
188
+ }
173
189
  /** Decodes a DER-encoded PKCS#7 ContentInfo expecting `signedData` content type. */
174
190
  function parsePkcs7SignedDataDer(e) {
175
191
  try {
176
- let t = l(e, { maxDepth: 64 }), n = t[0], r = t[1];
177
- if (n === void 0 || r === void 0 || t.length !== 2 || n.tag !== 6 || r.tag !== 160 || f(e, r).length !== 1) return pkcs7Failure("malformed", "Malformed PKCS#7 content info");
178
- let i = m(n.value);
179
- if (i !== b.pkcs7SignedData) return pkcs7Failure("not_signed_data", "PKCS#7 content is not signedData");
180
- let a = f(e, childAt(e, r, 0, "signedData")), o = a[0], s = a[1], c = a[2], u = a.slice(3), d = u[u.length - 1], h = parseSignedDataOptionalFields(u.slice(0, -1));
192
+ let t = s(e, { maxDepth: 64 }), n = t[0], r = t[1];
193
+ if (n === void 0 || t.length > 2 || n.tag !== 6 || r !== void 0 && (r.tag !== 160 || u(e, r).length !== 1)) return pkcs7Failure("malformed", "Malformed PKCS#7 content info");
194
+ let i = f(n.value);
195
+ if (i !== v.pkcs7SignedData) return pkcs7Failure("not_signed_data", "PKCS#7 content is not signedData");
196
+ if (r === void 0) return pkcs7Failure("malformed", "PKCS#7 signedData content info carries no content");
197
+ let a = u(e, childAt(e, r, 0, "signedData")), o = a[0], c = a[1], l = a[2], p = a.slice(3), m = p[p.length - 1], h = parseSignedDataOptionalFields(p.slice(0, -1));
181
198
  if (!h.ok) return h;
182
- if (o === void 0 || s === void 0 || c === void 0 || d === void 0 || d.tag !== 49) return pkcs7Failure("malformed", "Malformed SignedData");
183
- let g = e.slice(c.start - c.headerLength, c.end), _ = l(g), v = _[0], y = _[1], x = parseDigestAlgorithms(e, s);
184
- return v === void 0 ? pkcs7Failure("malformed", "Malformed EncapsulatedContentInfo") : {
199
+ if (o === void 0 || c === void 0 || l === void 0 || m === void 0 || m.tag !== 49) return pkcs7Failure("malformed", "Malformed SignedData");
200
+ let g = e.slice(l.start - l.headerLength, l.end), _ = s(g), y = _[0], b = _[1], x = parseDigestAlgorithms(e, c);
201
+ return y === void 0 || _.length > 2 || y.tag !== 6 ? pkcs7Failure("malformed", "Malformed EncapsulatedContentInfo") : {
185
202
  ok: !0,
186
203
  value: {
187
204
  der: new Uint8Array(e),
188
205
  contentTypeOid: i,
189
- version: p(o.value),
206
+ version: d(o.value),
190
207
  digestAlgorithmOids: x,
191
- digestAlgorithmNames: x.map((e) => E(e)),
192
- encapsulatedContentTypeOid: m(v.value),
193
- ...y === void 0 ? {} : { encapsulatedContent: extractEncapsulatedContent(g, y) },
194
- certificates: parseCertificateSet(e, h.value.certificates),
195
- signerInfos: parseSignerInfos(e, d)
208
+ digestAlgorithmNames: x.map((e) => w(e)),
209
+ encapsulatedContentTypeOid: f(y.value),
210
+ ...b === void 0 ? {} : { encapsulatedContent: extractEncapsulatedContent(g, b) },
211
+ certificateChoices: parseCertificateSet(e, h.value.certificates),
212
+ signerInfos: parseSignerInfos(e, m)
196
213
  }
197
214
  };
198
215
  } catch {
@@ -223,14 +240,10 @@ function parseSignedDataOptionalFields(e) {
223
240
  }
224
241
  };
225
242
  }
226
- /** Decodes a PEM-armored PKCS#7 SignedData. Expects exactly one `PKCS7` PEM block. */
243
+ /** Decodes a PEM-armored PKCS#7/CMS SignedData. Expects exactly one `PKCS7` or `CMS` PEM block. */
227
244
  function parsePkcs7SignedDataPem(e) {
228
- try {
229
- let t = T(e).filter((e) => e.label === "PKCS7"), n = t[0];
230
- return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block") : parsePkcs7SignedDataDer(n.bytes);
231
- } catch {
232
- return pkcs7Failure("malformed", "Expected exactly one PKCS7 PEM block");
233
- }
245
+ let t = contentInfoPemBytes(e);
246
+ return t.ok ? parsePkcs7SignedDataDer(t.bytes) : t;
234
247
  }
235
248
  /**
236
249
  * Verifies all signer signatures in a PKCS#7 SignedData structure.
@@ -250,7 +263,9 @@ function parsePkcs7SignedDataPem(e) {
250
263
  *
251
264
  * const result = await verifyPkcs7SignedData(pkcs7Pem);
252
265
  * if (result.ok) {
253
- * console.log('all signers verified');
266
+ * for (const { signerInfo, certificate } of result.signers) {
267
+ * console.log(signerInfo.digestAlgorithmOid, certificate.subject);
268
+ * }
254
269
  * }
255
270
  *
256
271
  * // Detached signature: supply the content externally
@@ -262,13 +277,19 @@ async function verifyPkcs7SignedData(e, t = {}) {
262
277
  if (!n.ok) return n;
263
278
  let r = n.value, i = r.encapsulatedContent ?? t.content?.slice();
264
279
  if (i === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
280
+ let a = [];
265
281
  for (let e of r.signerInfos) {
266
282
  let t = await verifyPkcs7SignerInfo(r, e, i);
267
283
  if (!t.ok) return t;
284
+ a.push({
285
+ signerInfo: e,
286
+ certificate: t.certificate
287
+ });
268
288
  }
269
289
  return {
270
290
  ok: !0,
271
- value: r
291
+ value: r,
292
+ signers: a
272
293
  };
273
294
  }
274
295
  /** Normalizes encoded or parsed SignedData into a freshly parsed verification input. */
@@ -277,8 +298,13 @@ function normalizePkcs7SignedDataForVerification(e) {
277
298
  }
278
299
  /** Resolves and verifies one signer entry in a parsed PKCS#7 SignedData value. */
279
300
  async function verifyPkcs7SignerInfo(e, t, n) {
280
- let r = e.certificates.find((e) => signerIdentifierMatches(e, t));
281
- return r === void 0 ? verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates") : t.hasSignedAttrs ? await verifySignedAttrs(t, r, n, e.encapsulatedContentTypeOid) : await verifyPkcs7BareSignerInfo(t, r, n);
301
+ let r = x509CertificatesOf(e.certificateChoices).find((e) => signerIdentifierMatches(e, t));
302
+ if (r === void 0) return verifyPkcs7Failure("signer_not_found", "Signer certificate not found in SignedData certificates");
303
+ let i = t.hasSignedAttrs ? await verifySignedAttrs(t, r, n, e.encapsulatedContentTypeOid) : await verifyPkcs7BareSignerInfo(t, r, n);
304
+ return i.ok ? {
305
+ ok: !0,
306
+ certificate: r
307
+ } : i;
282
308
  }
283
309
  async function verifyPkcs7BareSignerInfo(e, t, n) {
284
310
  try {
@@ -290,23 +316,28 @@ async function verifyPkcs7BareSignerInfo(e, t, n) {
290
316
  }
291
317
  /** Shorthand for constructing a PKCS#7 parse failure result. */
292
318
  function pkcs7Failure(e, t) {
293
- return C(e, t);
319
+ return x(e, t);
294
320
  }
295
321
  /** Shorthand for constructing a PKCS#7 verification failure result. */
296
322
  function verifyPkcs7Failure(e, t) {
297
- return C(e, t);
323
+ return x(e, t);
298
324
  }
299
325
  /** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
300
326
  function createCertBagFailure(e, t) {
301
- return C(e, t);
327
+ return x(e, t);
302
328
  }
303
329
  /** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
304
330
  function createPkcs7Failure(e, t) {
305
- return C(e, t);
331
+ return x(e, t);
306
332
  }
307
333
  /** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
308
334
  function normalizeCertificateSource(e) {
309
- return typeof e == "string" ? T(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes)) : e instanceof Uint8Array ? [new Uint8Array(e)] : [new Uint8Array(e.der)];
335
+ if (typeof e == "string") {
336
+ let t = C(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
337
+ if (t.length === 0) throw Error("Certificate PEM required");
338
+ return t;
339
+ }
340
+ return e instanceof Uint8Array ? [new Uint8Array(e)] : [new Uint8Array(e.der)];
310
341
  }
311
342
  /** Type guard: key algorithm carries an RSA `hash`. */
312
343
  function signerHasHash(e) {
@@ -319,9 +350,10 @@ function signerHasNamedCurve(e) {
319
350
  /**
320
351
  * Resolves the content-digest hash and its OID for a signer key.
321
352
  *
322
- * Pairs each key with the digest used by its signature algorithm (RFC 5754):
323
- * P-256/RSA-SHA256 → SHA-256, P-384 → SHA-384, P-521 → SHA-512. Ed25519 uses
324
- * SHA-512 for the messageDigest attribute, per RFC 8419.
353
+ * ECDSA curve pairing follows RFC 5753 §8: P-256 → SHA-256, P-384 → SHA-384,
354
+ * P-521 → SHA-512. RSA uses the hash bound to the key.
355
+ * Digest OIDs are from RFC 5754 §2.
356
+ * Ed25519 uses SHA-512 for the messageDigest attribute, per RFC 8419.
325
357
  */
326
358
  function contentDigestForPrivateKey(e) {
327
359
  let t = e.algorithm;
@@ -330,15 +362,15 @@ function contentDigestForPrivateKey(e) {
330
362
  switch (t.namedCurve) {
331
363
  case "P-256": return {
332
364
  hashName: "SHA-256",
333
- digestOid: b.sha256
365
+ digestOid: v.sha256
334
366
  };
335
367
  case "P-384": return {
336
368
  hashName: "SHA-384",
337
- digestOid: b.sha384
369
+ digestOid: v.sha384
338
370
  };
339
371
  case "P-521": return {
340
372
  hashName: "SHA-512",
341
- digestOid: b.sha512
373
+ digestOid: v.sha512
342
374
  };
343
375
  default: return;
344
376
  }
@@ -348,22 +380,22 @@ function contentDigestForPrivateKey(e) {
348
380
  switch (t.hash.name) {
349
381
  case "SHA-256": return {
350
382
  hashName: "SHA-256",
351
- digestOid: b.sha256
383
+ digestOid: v.sha256
352
384
  };
353
385
  case "SHA-384": return {
354
386
  hashName: "SHA-384",
355
- digestOid: b.sha384
387
+ digestOid: v.sha384
356
388
  };
357
389
  case "SHA-512": return {
358
390
  hashName: "SHA-512",
359
- digestOid: b.sha512
391
+ digestOid: v.sha512
360
392
  };
361
393
  default: return;
362
394
  }
363
395
  }
364
396
  if (t.name === "Ed25519") return {
365
397
  hashName: "SHA-512",
366
- digestOid: b.sha512
398
+ digestOid: v.sha512
367
399
  };
368
400
  }
369
401
  /**
@@ -373,87 +405,129 @@ function contentDigestForPrivateKey(e) {
373
405
  * SignerInfo. The two differ only in the leading tag byte.
374
406
  */
375
407
  function buildSignedAttributes(e, t) {
376
- let n = d([u([a(b.cmsContentType), d([a(e)])]), u([a(b.cmsMessageDigest), d([o(t)])])]), r = new Uint8Array(n);
377
- return r[0] = 160, {
408
+ let n = l([c([r(v.cmsContentType), l([r(e)])]), c([r(v.cmsMessageDigest), l([i(t)])])]), a = new Uint8Array(n);
409
+ return a[0] = 160, {
378
410
  setForSigning: n,
379
- implicitForEmit: r
411
+ implicitForEmit: a
380
412
  };
381
413
  }
382
- /** Parses the IMPLICIT [0] certificate set from a SignedData structure. */
383
- function parseCertificateSet(e, t) {
384
- if (t === void 0 || t.tag !== 160) return [];
385
- let n = [], r = t.start;
386
- for (; r < t.end;) {
387
- let t = s(e, r);
388
- n.push(k(e.slice(r, t.end))), r = t.end;
414
+ /** The X.509 subset of a decoded CertificateSet. */
415
+ function x509CertificatesOf(e) {
416
+ return e.flatMap((e) => e.type === "certificate" ? [e.certificate] : []);
417
+ }
418
+ /**
419
+ * `otherCertFormat` from an `other [3] IMPLICIT OtherCertificateFormat` entry.
420
+ *
421
+ * The IMPLICIT tag replaces the SEQUENCE tag, so the OID and the `ANY DEFINED BY`
422
+ * value are direct children of the `[3]` element.
423
+ */
424
+ function parseOtherCertificateFormatOid(e, t) {
425
+ let n = h(u(e, t)[0], "otherCertFormat");
426
+ if (n.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
427
+ return f(n.value);
428
+ }
429
+ /** Decodes one RFC 5652 §10.2.2 CertificateChoices alternative. */
430
+ function parseCertificateChoice(e, t, n) {
431
+ switch (t.tag) {
432
+ case 48: return {
433
+ type: "certificate",
434
+ certificate: O(n)
435
+ };
436
+ case 160: return {
437
+ type: "extendedCertificate",
438
+ der: n
439
+ };
440
+ case 161: return {
441
+ type: "attributeCertificateV1",
442
+ der: n
443
+ };
444
+ case 162: return {
445
+ type: "attributeCertificateV2",
446
+ der: n
447
+ };
448
+ case 163: return {
449
+ type: "other",
450
+ formatOid: parseOtherCertificateFormatOid(e, t),
451
+ der: n
452
+ };
453
+ default: throw Error(`Unsupported CertificateChoices tag: ${t.tag}`);
389
454
  }
390
- return n;
455
+ }
456
+ /**
457
+ * Parses the IMPLICIT [0] certificate set from a SignedData structure as
458
+ * RFC 5652 §10.2.3 `CertificateSet ::= SET OF CertificateChoices`.
459
+ */
460
+ function parseCertificateSet(e, t) {
461
+ return t === void 0 || t.tag !== 160 ? [] : u(e, t).map((t) => parseCertificateChoice(e, t, e.slice(t.start - t.headerLength, t.end)));
391
462
  }
392
463
  /** Extracts the list of digest algorithm OIDs from the digestAlgorithms SET. */
393
464
  function parseDigestAlgorithms(e, t) {
394
465
  let n = [];
395
466
  if (t.tag !== 49) throw Error("digestAlgorithms must use SET");
396
- for (let r of f(e, t)) {
467
+ for (let r of u(e, t)) {
397
468
  if (r.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
398
- let t = l(e.slice(r.start - r.headerLength, r.end)), i = t[0];
469
+ let t = s(e.slice(r.start - r.headerLength, r.end)), i = t[0];
399
470
  if (i === void 0 || t.length < 1 || t.length > 2 || i.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
400
- n.push(m(i.value));
471
+ n.push(f(i.value));
401
472
  }
402
473
  return n;
403
474
  }
404
475
  /** Decodes the signerInfos SET OF from a SignedData structure. */
405
476
  function parseSignerInfos(e, t) {
406
- return f(e, t).map((t) => parseSignerInfo(e, t));
477
+ return u(e, t).map((t) => parseSignerInfo(e, t));
407
478
  }
408
479
  function parseSignerInfo(e, t) {
409
- let n = e.slice(t.start - t.headerLength, t.end), r = l(n), i = r[0], a = r[1], o = r[2], s = 3, c = r[s]?.tag === 160 ? r[s] : void 0;
410
- c !== void 0 && (s += 1);
411
- let u = r[s], d = r[s + 1], f = r[s + 2];
412
- if (i === void 0 || a === void 0 || o === void 0 || u === void 0 || d === void 0 || d.tag !== 4 || r.length > s + 3 || f !== void 0 && f.tag !== 161) throw Error("Malformed SignerInfo");
413
- let h = parsePkcs7AlgorithmOid(n, o, "digest algorithm OID"), g = n.slice(u.start - u.headerLength, u.end), v = l(g), b = m(_(v[0], "signature algorithm OID").value), x = v[1], S = parseSignerIdentifier(n.slice(a.start - a.headerLength, a.end));
480
+ let n = e.slice(t.start - t.headerLength, t.end), r = s(n), i = r[0], a = r[1], o = r[2], c = 3, l = r[c]?.tag === 160 ? r[c] : void 0;
481
+ l !== void 0 && (c += 1);
482
+ let u = r[c], p = r[c + 1], m = r[c + 2];
483
+ if (i === void 0 || a === void 0 || o === void 0 || u === void 0 || p === void 0 || p.tag !== 4 || r.length > c + 3 || m !== void 0 && m.tag !== 161) throw Error("Malformed SignerInfo");
484
+ let g = parsePkcs7AlgorithmOid(n, o, "digest algorithm OID"), v = n.slice(u.start - u.headerLength, u.end), y = s(v), b = f(h(y[0], "signature algorithm OID").value), x = y[1];
414
485
  return {
415
- version: p(i.value),
416
- ...S.issuer === void 0 ? {} : { issuer: S.issuer },
417
- ...S.serialNumberHex === void 0 ? {} : { serialNumberHex: S.serialNumberHex },
418
- ...S.subjectKeyIdentifier === void 0 ? {} : { subjectKeyIdentifier: S.subjectKeyIdentifier },
419
- digestAlgorithmOid: h,
420
- digestAlgorithmName: E(h),
486
+ version: d(i.value),
487
+ signerIdentifier: parseSignerIdentifier(n.slice(a.start - a.headerLength, a.end)),
488
+ digestAlgorithmOid: g,
489
+ digestAlgorithmName: w(g),
421
490
  signatureAlgorithmOid: b,
422
- signatureAlgorithmName: D(b, x === void 0 ? void 0 : new Uint8Array(g.slice(x.start - x.headerLength, x.end))),
423
- ...x === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(g.slice(x.start - x.headerLength, x.end)) },
424
- signatureHex: y(d.value),
425
- signature: new Uint8Array(d.value),
426
- ...c === void 0 ? { hasSignedAttrs: !1 } : {
491
+ signatureAlgorithmName: T(b, x === void 0 ? void 0 : new Uint8Array(v.slice(x.start - x.headerLength, x.end))),
492
+ ...x === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(v.slice(x.start - x.headerLength, x.end)) },
493
+ signatureHex: _(p.value),
494
+ signature: new Uint8Array(p.value),
495
+ ...l === void 0 ? { hasSignedAttrs: !1 } : {
427
496
  hasSignedAttrs: !0,
428
- signedAttrsDer: new Uint8Array(n.slice(c.start - c.headerLength, c.end))
497
+ signedAttrsDer: new Uint8Array(n.slice(l.start - l.headerLength, l.end))
429
498
  }
430
499
  };
431
500
  }
432
501
  function parsePkcs7AlgorithmOid(e, t, n) {
433
- return m(_(l(e.slice(t.start - t.headerLength, t.end))[0], n).value);
502
+ return f(h(s(e.slice(t.start - t.headerLength, t.end))[0], n).value);
434
503
  }
435
504
  /** Unwraps the OCTET STRING inside the IMPLICIT [0] encapsulated content. */
436
505
  function extractEncapsulatedContent(e, t) {
437
506
  if (t.tag !== 160) throw Error("Unexpected encapsulated content tag");
438
- let n = s(e, t.start);
507
+ let n = a(e, t.start);
439
508
  if (n.tag !== 4) throw Error("Expected encapsulated OCTET STRING");
509
+ if (n.end !== t.end) throw Error("Encapsulated content must hold exactly one element");
440
510
  return n.value;
441
511
  }
442
512
  /** Extracts issuer Name and serial number from an issuerAndSerialNumber SEQUENCE, or subjectKeyIdentifier from [0] IMPLICIT. */
443
513
  function parseSignerIdentifier(e) {
444
- let t = c(e, { maxDepth: 64 });
514
+ let t = o(e, { maxDepth: 64 });
445
515
  if (t.tag === 128) {
446
516
  if (t.value.length === 0) throw Error("SignerIdentifier subjectKeyIdentifier must not be empty");
447
- return { subjectKeyIdentifier: y(t.value) };
517
+ return {
518
+ type: "subjectKeyIdentifier",
519
+ subjectKeyIdentifier: _(t.value)
520
+ };
448
521
  }
449
522
  if (t.tag === 48) {
450
- let t = l(e), n = t[0], r = t[1];
523
+ let t = s(e), n = t[0], r = t[1];
451
524
  if (n === void 0 || r === void 0 || t.length !== 2) throw Error("SignerIdentifier issuerAndSerialNumber is malformed");
452
525
  if (n.tag !== 48) throw Error("SignerIdentifier issuer must use Name SEQUENCE");
453
526
  if (r.tag !== 2) throw Error("SignerIdentifier serialNumber must use INTEGER");
454
527
  return assertImplicitSerialNumberEncoding(r.value, "SignerIdentifier serialNumber"), {
528
+ type: "issuerAndSerialNumber",
455
529
  issuer: parseSignerIssuerName(e, n),
456
- serialNumberHex: y(r.value)
530
+ serialNumberHex: _(r.value)
457
531
  };
458
532
  }
459
533
  throw Error(`Unsupported SignerIdentifier tag: ${String(t.tag)}`);
@@ -461,30 +535,30 @@ function parseSignerIdentifier(e) {
461
535
  const F = new TextDecoder();
462
536
  /** Parses a Name SEQUENCE element from a PKCS#7 signer identifier into a {@linkcode ParsedName}. */
463
537
  function parseSignerIssuerName(e, t) {
464
- let n = y(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
465
- for (let n of f(e, t)) {
538
+ let n = _(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
539
+ for (let n of u(e, t)) {
466
540
  let t = [], o = {};
467
- for (let r of f(e, n)) {
468
- let n = f(e, r), s = _(n[0], "signer issuer attribute OID"), c = _(n[1], "signer issuer attribute value"), l = m(s.value), u;
541
+ for (let r of u(e, n)) {
542
+ let n = u(e, r), s = h(n[0], "signer issuer attribute OID"), c = h(n[1], "signer issuer attribute value"), l = f(s.value), d;
469
543
  try {
470
- u = h(c.tag, c.value);
544
+ d = p(c.tag, c.value);
471
545
  } catch {
472
- u = F.decode(c.value);
546
+ d = F.decode(c.value);
473
547
  }
474
- let d = O(l), p = d === void 0 ? {
548
+ let m = E(l), g = m === void 0 ? {
475
549
  oid: l,
476
550
  valueTag: c.tag,
477
- value: u
551
+ value: d
478
552
  } : {
479
553
  oid: l,
480
- key: d,
554
+ key: m,
481
555
  valueTag: c.tag,
482
- value: u
556
+ value: d
483
557
  };
484
- t.push(p), i.push(p), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
558
+ t.push(g), i.push(g), m !== void 0 && (o[m] === void 0 && (o[m] = d), a[m] === void 0 && (a[m] = d));
485
559
  }
486
560
  r.push({
487
- derHex: y(e.slice(n.start - n.headerLength, n.end)),
561
+ derHex: _(e.slice(n.start - n.headerLength, n.end)),
488
562
  attributes: t,
489
563
  values: o
490
564
  });
@@ -498,27 +572,27 @@ function parseSignerIssuerName(e, t) {
498
572
  }
499
573
  /** Returns the nth child element inside a constructed ASN.1 element, or throws. */
500
574
  function childAt(e, t, n, r) {
501
- let i = t.start, a = 0;
575
+ let i = t.start, o = 0;
502
576
  for (; i < t.end;) {
503
- let t = s(e, i);
504
- if (a === n) return t;
505
- i = t.end, a += 1;
577
+ let t = a(e, i);
578
+ if (o === n) return t;
579
+ i = t.end, o += 1;
506
580
  }
507
581
  throw Error(`Missing ${r}`);
508
582
  }
509
583
  /** Maps a digest algorithm OID to the WebCrypto hash name. */
510
584
  function digestAlgorithmHash(e) {
511
585
  switch (e) {
512
- case b.sha256: return "SHA-256";
513
- case b.sha384: return "SHA-384";
514
- case b.sha512: return "SHA-512";
586
+ case v.sha256: return "SHA-256";
587
+ case v.sha384: return "SHA-384";
588
+ case v.sha512: return "SHA-512";
515
589
  default: throw Error(`Unsupported digest algorithm OID: ${e}`);
516
590
  }
517
591
  }
518
592
  /** Parses required signed attributes and enforces uniqueness + exact-one-value shape. */
519
593
  function parseSignedAttributeRequirements(e) {
520
- let t = s(e), n = {};
521
- for (let r of f(e, t)) parseSignedAttributeRequirement(e, r, n);
594
+ let t = a(e), n = {};
595
+ for (let r of u(e, t)) parseSignedAttributeRequirement(e, r, n);
522
596
  if (n.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
523
597
  if (n.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
524
598
  return {
@@ -527,22 +601,22 @@ function parseSignedAttributeRequirements(e) {
527
601
  };
528
602
  }
529
603
  function parseSignedAttributeRequirement(e, t, n) {
530
- let r = e.slice(t.start - t.headerLength, t.end), i = l(r), a = i[0], o = i[1];
604
+ let r = e.slice(t.start - t.headerLength, t.end), i = s(r), a = i[0], o = i[1];
531
605
  if (a === void 0 || o === void 0 || i.length !== 2 || o.tag !== 49) throw Error("Malformed signedAttrs attribute");
532
- let s = m(a.value), c = f(r, o);
533
- s === b.cmsMessageDigest && (n.messageDigest = parseUniqueSignedAttributeOctetString(n.messageDigest, c, "messageDigest")), s === b.cmsContentType && (n.contentTypeOid = parseUniqueSignedAttributeOid(n.contentTypeOid, c, "contentType"));
606
+ let c = f(a.value), l = u(r, o);
607
+ c === v.cmsMessageDigest && (n.messageDigest = parseUniqueSignedAttributeOctetString(n.messageDigest, l, "messageDigest")), c === v.cmsContentType && (n.contentTypeOid = parseUniqueSignedAttributeOid(n.contentTypeOid, l, "contentType"));
534
608
  }
535
609
  function parseUniqueSignedAttributeOctetString(e, t, n) {
536
610
  if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
537
- let r = _(t[0], `${n} attribute value`);
611
+ let r = h(t[0], `${n} attribute value`);
538
612
  if (r.tag !== 4) throw Error(`${n} attribute value must use OCTET STRING`);
539
613
  return r.value;
540
614
  }
541
615
  function parseUniqueSignedAttributeOid(e, t, n) {
542
616
  if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
543
- let r = _(t[0], `${n} attribute value`);
617
+ let r = h(t[0], `${n} attribute value`);
544
618
  if (r.tag !== 6) throw Error(`${n} attribute value must use OBJECT IDENTIFIER`);
545
- return m(r.value);
619
+ return f(r.value);
546
620
  }
547
621
  /** Replaces the IMPLICIT [0] tag (0xa0) with SET OF (0x31) per RFC 5652 Section 5.4. */
548
622
  function retagSignedAttrsAsSet(e) {
@@ -569,7 +643,7 @@ async function verifySignedAttrs(e, t, n, r) {
569
643
  let a;
570
644
  try {
571
645
  let t = digestAlgorithmHash(e.digestAlgorithmOid);
572
- a = new Uint8Array(await x().subtle.digest(t, v(n)));
646
+ a = new Uint8Array(await y().subtle.digest(t, g(n)));
573
647
  } catch {
574
648
  return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
575
649
  }
@@ -591,10 +665,11 @@ async function verifySignedAttrs(e, t, n, r) {
591
665
  return s ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
592
666
  }
593
667
  function signerIdentifierMatches(e, t) {
594
- return t.issuer !== void 0 || t.serialNumberHex !== void 0 ? t.issuer !== void 0 && t.serialNumberHex !== void 0 && e.serialNumberHex === t.serialNumberHex && P(e.issuer, t.issuer) : t.subjectKeyIdentifier !== void 0 && e.subjectKeyIdentifier === t.subjectKeyIdentifier;
668
+ let n = t.signerIdentifier;
669
+ return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && D(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
595
670
  }
596
671
  function assertImplicitSignedAttrsDer(e) {
597
- if (s(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
672
+ if (a(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
598
673
  }
599
674
  function hasReparseablePkcs7SignedData(e) {
600
675
  return "der" in e && e.der instanceof Uint8Array;