micro509 0.14.0 → 0.16.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 (164) hide show
  1. package/CHANGELOG.md +2119 -0
  2. package/README.md +105 -225
  3. package/dist/crypto/crypto.d.ts +42 -11
  4. package/dist/crypto/crypto.js +53 -22
  5. package/dist/crypto/crypto.js.map +1 -1
  6. package/dist/crypto.d.ts +2 -2
  7. package/dist/crypto.js +1 -2
  8. package/dist/der/der.d.ts +41 -33
  9. package/dist/der/der.js +26 -24
  10. package/dist/der/der.js.map +1 -1
  11. package/dist/index.d.ts +11 -11
  12. package/dist/index.js +19 -19
  13. package/dist/internal/asn1/asn1.d.ts +3 -6
  14. package/dist/internal/asn1/asn1.js +343 -43
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js +146 -0
  17. package/dist/internal/asn1/ber.js.map +1 -0
  18. package/dist/internal/asn1/decode-refusal.js +29 -0
  19. package/dist/internal/asn1/decode-refusal.js.map +1 -0
  20. package/dist/internal/asn1/der.d.ts +38 -41
  21. package/dist/internal/asn1/der.js +131 -52
  22. package/dist/internal/asn1/der.js.map +1 -1
  23. package/dist/internal/asn1/oids.js +83 -53
  24. package/dist/internal/asn1/oids.js.map +1 -1
  25. package/dist/internal/asn1/oids2.js +1 -2
  26. package/dist/internal/asn1/oids2.js.map +1 -1
  27. package/dist/internal/crypto/algorithm-names.js +1 -2
  28. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  29. package/dist/internal/crypto/ecdsa.js +13 -8
  30. package/dist/internal/crypto/ecdsa.js.map +1 -1
  31. package/dist/internal/crypto/hash.js +1 -2
  32. package/dist/internal/crypto/hash.js.map +1 -1
  33. package/dist/internal/crypto/pbes2.d.ts +24 -11
  34. package/dist/internal/crypto/pbes2.js +79 -26
  35. package/dist/internal/crypto/pbes2.js.map +1 -1
  36. package/dist/internal/crypto/rsa-pss.js +46 -44
  37. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  38. package/dist/internal/crypto/sig-verify.d.ts +4 -7
  39. package/dist/internal/crypto/sig-verify.js +107 -60
  40. package/dist/internal/crypto/sig-verify.js.map +1 -1
  41. package/dist/internal/crypto/signing.d.ts +1 -4
  42. package/dist/internal/crypto/signing.js +28 -29
  43. package/dist/internal/crypto/signing.js.map +1 -1
  44. package/dist/internal/crypto/webcrypto.js +1 -2
  45. package/dist/internal/crypto/webcrypto.js.map +1 -1
  46. package/dist/internal/shared/base64.js +1 -2
  47. package/dist/internal/shared/base64.js.map +1 -1
  48. package/dist/internal/shared/dn.d.ts +3 -6
  49. package/dist/internal/shared/dn.js +99 -53
  50. package/dist/internal/shared/dn.js.map +1 -1
  51. package/dist/internal/shared/idna-tables.js +7217 -0
  52. package/dist/internal/shared/idna-tables.js.map +1 -0
  53. package/dist/internal/shared/idna.js +296 -0
  54. package/dist/internal/shared/idna.js.map +1 -0
  55. package/dist/internal/shared/ip.d.ts +4 -7
  56. package/dist/internal/shared/ip.js +1 -2
  57. package/dist/internal/shared/ip.js.map +1 -1
  58. package/dist/internal/shared/mailbox.js +26 -0
  59. package/dist/internal/shared/mailbox.js.map +1 -0
  60. package/dist/internal/shared/punycode.js +101 -0
  61. package/dist/internal/shared/punycode.js.map +1 -0
  62. package/dist/internal/shared/rfc3454-tables.js +1 -2
  63. package/dist/internal/shared/rfc3454-tables.js.map +1 -1
  64. package/dist/internal/shared/rfc4518-tables.js +119 -0
  65. package/dist/internal/shared/rfc4518-tables.js.map +1 -0
  66. package/dist/internal/shared/uri-host.js +102 -0
  67. package/dist/internal/shared/uri-host.js.map +1 -0
  68. package/dist/internal/verify/name-constraints-engine.js +246 -131
  69. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  70. package/dist/internal/verify/policy-engine.js +6 -21
  71. package/dist/internal/verify/policy-engine.js.map +1 -1
  72. package/dist/internal/verify/spki-distrust.js +23 -0
  73. package/dist/internal/verify/spki-distrust.js.map +1 -0
  74. package/dist/internal/verify/verify-path.d.ts +1 -4
  75. package/dist/internal/verify/verify-path.js +282 -129
  76. package/dist/internal/verify/verify-path.js.map +1 -1
  77. package/dist/internal/x509/directory-name.js +1 -2
  78. package/dist/internal/x509/directory-name.js.map +1 -1
  79. package/dist/internal/x509/extension-bits.js +2 -3
  80. package/dist/internal/x509/extension-bits.js.map +1 -1
  81. package/dist/internal/x509/extension-errors.d.ts +1 -4
  82. package/dist/internal/x509/extension-errors.js +1 -2
  83. package/dist/internal/x509/extension-errors.js.map +1 -1
  84. package/dist/internal/x509/extension-registry.js +107 -89
  85. package/dist/internal/x509/extension-registry.js.map +1 -1
  86. package/dist/internal/x509/general-name-profile.js +129 -0
  87. package/dist/internal/x509/general-name-profile.js.map +1 -0
  88. package/dist/internal/x509/general-name-tags.js +1 -2
  89. package/dist/internal/x509/general-name-tags.js.map +1 -1
  90. package/dist/internal/x509/general-name.js +128 -42
  91. package/dist/internal/x509/general-name.js.map +1 -1
  92. package/dist/internal/x509/name-fields.js +1 -2
  93. package/dist/internal/x509/name-fields.js.map +1 -1
  94. package/dist/internal/x509/or-address.js +217 -0
  95. package/dist/internal/x509/or-address.js.map +1 -0
  96. package/dist/keys/keys.d.ts +122 -104
  97. package/dist/keys/keys.js +211 -204
  98. package/dist/keys/keys.js.map +1 -1
  99. package/dist/keys.d.ts +3 -3
  100. package/dist/pem/pem.d.ts +14 -17
  101. package/dist/pem/pem.js +16 -17
  102. package/dist/pem/pem.js.map +1 -1
  103. package/dist/pem.js +1 -2
  104. package/dist/pkcs/pfx.d.ts +57 -32
  105. package/dist/pkcs/pfx.js +209 -173
  106. package/dist/pkcs/pfx.js.map +1 -1
  107. package/dist/pkcs/pkcs12-mac.d.ts +104 -27
  108. package/dist/pkcs/pkcs12-mac.js +266 -79
  109. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  110. package/dist/pkcs/pkcs7.d.ts +43 -37
  111. package/dist/pkcs/pkcs7.js +218 -217
  112. package/dist/pkcs/pkcs7.js.map +1 -1
  113. package/dist/pkcs.d.ts +4 -3
  114. package/dist/result/result.d.ts +27 -20
  115. package/dist/result/result.js +8 -3
  116. package/dist/result/result.js.map +1 -1
  117. package/dist/result.d.ts +2 -2
  118. package/dist/result.js +1 -2
  119. package/dist/revocation/chain.d.ts +101 -23
  120. package/dist/revocation/chain.js +436 -182
  121. package/dist/revocation/chain.js.map +1 -1
  122. package/dist/revocation/crl.d.ts +131 -67
  123. package/dist/revocation/crl.js +443 -327
  124. package/dist/revocation/crl.js.map +1 -1
  125. package/dist/revocation/ocsp.d.ts +94 -59
  126. package/dist/revocation/ocsp.js +331 -293
  127. package/dist/revocation/ocsp.js.map +1 -1
  128. package/dist/revocation/revocation.d.ts +47 -35
  129. package/dist/revocation/revocation.js +88 -57
  130. package/dist/revocation/revocation.js.map +1 -1
  131. package/dist/revocation.d.ts +3 -3
  132. package/dist/verify/identity.d.ts +16 -19
  133. package/dist/verify/identity.js +118 -89
  134. package/dist/verify/identity.js.map +1 -1
  135. package/dist/verify/name-constraints.d.ts +1 -4
  136. package/dist/verify/policy.d.ts +9 -7
  137. package/dist/verify/verify.d.ts +115 -46
  138. package/dist/verify/verify.js +373 -183
  139. package/dist/verify/verify.js.map +1 -1
  140. package/dist/verify.d.ts +2 -2
  141. package/dist/x509/certificate.d.ts +20 -21
  142. package/dist/x509/certificate.js +62 -46
  143. package/dist/x509/certificate.js.map +1 -1
  144. package/dist/x509/csr.d.ts +5 -7
  145. package/dist/x509/csr.js +10 -11
  146. package/dist/x509/csr.js.map +1 -1
  147. package/dist/x509/extensions.d.ts +154 -66
  148. package/dist/x509/extensions.js +317 -151
  149. package/dist/x509/extensions.js.map +1 -1
  150. package/dist/x509/fingerprint.d.ts +15 -7
  151. package/dist/x509/fingerprint.js +20 -3
  152. package/dist/x509/fingerprint.js.map +1 -1
  153. package/dist/x509/name-text.d.ts +7 -9
  154. package/dist/x509/name-text.js +18 -4
  155. package/dist/x509/name-text.js.map +1 -1
  156. package/dist/x509/name.d.ts +9 -11
  157. package/dist/x509/name.js +18 -19
  158. package/dist/x509/name.js.map +1 -1
  159. package/dist/x509/parse.d.ts +84 -69
  160. package/dist/x509/parse.js +421 -400
  161. package/dist/x509/parse.js.map +1 -1
  162. package/dist/x509.d.ts +3 -3
  163. package/dist/x509.js +3 -3
  164. package/package.json +76 -59
@@ -1,17 +1,18 @@
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";
13
- import { encodeAlgorithmIdentifier as j, getSignatureAlgorithm as M, signBytes as N } from "../internal/crypto/signing.js";
14
- //#region src/pkcs/pkcs7.ts
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";
15
+ // src/pkcs/pkcs7.ts
15
16
  /**
16
17
  * PKCS#7/CMS certificate bags and SignedData.
17
18
  *
@@ -24,7 +25,7 @@ import { encodeAlgorithmIdentifier as j, getSignatureAlgorithm as M, signBytes a
24
25
  * @module
25
26
  */
26
27
  /** RFC 7468 Section 8 armors an RFC 2315 ContentInfo; Section 9 armors an RFC 5652 one. */
27
- const P = ["PKCS7", "CMS"];
28
+ const L = ["PKCS7", "CMS"];
28
29
  /**
29
30
  * Creates a degenerate PKCS#7 SignedData structure containing only
30
31
  * certificates (no signers), returning DER, PEM, and base64 forms, or a
@@ -32,28 +33,29 @@ const P = ["PKCS7", "CMS"];
32
33
  * valid PEM/DER.
33
34
  */
34
35
  function createPkcs7CertBag(t) {
35
- let i;
36
+ let n;
36
37
  try {
37
- i = t.flatMap(normalizeCertificateSource);
38
- for (let e of i) O(e);
39
- } catch {
40
- return createCertBagFailure("invalid_certificate", "Each PKCS#7 certificate source must be valid PEM or DER");
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);
41
43
  }
42
- let a = new Uint8Array(l(i));
44
+ let a = new Uint8Array(p(n));
43
45
  a[0] = 160;
44
- let o = c([
45
- n(1),
46
- l([]),
47
- c([r(v.pkcs7Data)]),
46
+ let c = f([
47
+ o(1),
48
+ p([]),
49
+ f([s(S.pkcs7Data)]),
48
50
  a,
49
- l([])
50
- ]), s = c([r(v.pkcs7SignedData), e(0, o)]);
51
+ p([])
52
+ ]), l = f([s(S.pkcs7SignedData), i(0, c)]);
51
53
  return {
52
54
  ok: !0,
53
55
  value: {
54
- der: s,
55
- pem: S("PKCS7", s),
56
- base64: b(s)
56
+ der: l,
57
+ pem: T("PKCS7", l),
58
+ base64: w(l)
57
59
  }
58
60
  };
59
61
  }
@@ -79,35 +81,36 @@ function createPkcs7CertBag(t) {
79
81
  */
80
82
  async function createPkcs7SignedData(t) {
81
83
  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 = [];
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 = [];
86
88
  for (let e of t.signers) {
87
- let t = await buildPkcs7SignerInfo(e, o, a);
89
+ let t = await buildPkcs7SignerInfo(e, a, n);
88
90
  if (!t.ok) return t;
89
- addCertificate(t.certificateDer), d.add(t.digestOid), f.push(t.signerInfoDer);
91
+ addCertificate(t.certificateDer), d.add(t.digestOid), m.push(t.signerInfoDer);
90
92
  }
91
- for (let e of t.additionalCertificates ?? []) try {
92
- for (let t of normalizeCertificateSource(e)) O(t), addCertificate(t);
93
- } catch {
94
- return createPkcs7Failure("invalid_certificate", "Each additional PKCS#7 certificate source must be valid PEM or DER");
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);
95
98
  }
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)]);
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, _)]);
105
108
  return {
106
109
  ok: !0,
107
110
  value: {
108
- der: g,
109
- pem: S(p === 1 ? "PKCS7" : "CMS", g),
110
- base64: b(g)
111
+ der: v,
112
+ pem: T(h === 1 ? "PKCS7" : "CMS", v),
113
+ base64: w(v)
111
114
  }
112
115
  };
113
116
  }
@@ -117,48 +120,49 @@ async function createPkcs7SignedData(t) {
117
120
  * caller-correctable input — malformed PEM/DER, unsupported key — so each is
118
121
  * mapped to a typed failure rather than rejecting the public Promise.
119
122
  */
120
- async function buildPkcs7SignerInfo(e, a, o) {
121
- let s;
123
+ async function buildPkcs7SignerInfo(t, n, i) {
124
+ let l;
122
125
  try {
123
- s = normalizeCertificateSource(e.certificate);
126
+ l = normalizeCertificateSource(t.certificate);
124
127
  } catch {
125
128
  return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate source must be valid PEM or DER");
126
129
  }
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;
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
133
  try {
131
- u = O(l);
132
- } catch {
133
- return createPkcs7Failure("invalid_signer_certificate", "Each PKCS#7 signer certificate must be a parseable X.509 certificate");
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
138
  }
135
- let d;
139
+ let p;
136
140
  try {
137
- d = M(e.privateKey, e.signature);
141
+ p = A(t.privateKey, t.signature);
138
142
  } catch {
139
143
  return createPkcs7Failure("unsupported_signer_key", "Unsupported signer key or signature profile");
140
144
  }
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)))), _;
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);
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)))), _;
145
149
  try {
146
- _ = await N(e.privateKey, d, p);
150
+ _ = await j(t.privateKey, p, h);
147
151
  } catch {
148
152
  return createPkcs7Failure("unsupported_signer_key", "Signer key could not produce a PKCS#7 signature");
149
153
  }
150
154
  return {
151
155
  ok: !0,
152
- signerInfoDer: c([
153
- n(1),
154
- c([m(u.issuer.derHex), t(m(u.serialNumberHex))]),
155
- c([r(f.digestOid)]),
156
- h,
157
- j(d),
158
- i(_)
156
+ signerInfoDer: f([
157
+ o(1),
158
+ f([v(d.issuer.derHex), a(v(d.serialNumberHex))]),
159
+ f([s(m.digestOid)]),
160
+ g,
161
+ k(p),
162
+ c(_)
159
163
  ]),
160
- digestOid: f.digestOid,
161
- certificateDer: l
164
+ digestOid: m.digestOid,
165
+ certificateDer: u
162
166
  };
163
167
  }
164
168
  /** Parses a DER-encoded PKCS#7 cert bag, returning the contained certificates. */
@@ -172,7 +176,7 @@ function parsePkcs7CertBagDer(e) {
172
176
  /** The DER of the single `PKCS7` or `CMS` block in `pem`, or a typed failure. */
173
177
  function contentInfoPemBytes(e) {
174
178
  try {
175
- let t = C(e).filter((e) => P.some((t) => t === e.label)), n = t[0];
179
+ let t = E(e).filter((e) => L.some((t) => t === e.label)), n = t[0];
176
180
  return n === void 0 || t.length !== 1 ? pkcs7Failure("malformed", "Expected exactly one PKCS7 or CMS PEM block") : {
177
181
  ok: !0,
178
182
  bytes: n.bytes
@@ -187,51 +191,47 @@ function parsePkcs7CertBagPem(e) {
187
191
  return t.ok ? parsePkcs7CertBagDer(t.bytes) : t;
188
192
  }
189
193
  /** Decodes a DER-encoded PKCS#7 ContentInfo expecting `signedData` content type. */
190
- function parsePkcs7SignedDataDer(e) {
194
+ function parsePkcs7SignedDataDer(t) {
191
195
  try {
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
+ 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");
196
200
  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));
198
- if (!h.ok) return h;
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") : {
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") : {
202
206
  ok: !0,
203
207
  value: {
204
- der: new Uint8Array(e),
208
+ der: new Uint8Array(t),
205
209
  contentTypeOid: i,
206
- version: d(o.value),
210
+ version: h(s.value),
207
211
  digestAlgorithmOids: x,
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)
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)
213
217
  }
214
218
  };
215
- } catch {
216
- return pkcs7Failure("malformed", "Malformed PKCS#7 structure");
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);
217
223
  }
218
224
  }
219
225
  function parseSignedDataOptionalFields(e) {
220
226
  let t, n;
221
- for (let r of e) {
222
- if (r.tag === 160) {
223
- if (n !== void 0) return pkcs7Failure("malformed", "SignedData certificates field must precede CRLs field");
224
- if (t !== void 0) return pkcs7Failure("malformed", "SignedData certificates field must not repeat");
225
- t = r;
226
- continue;
227
- }
228
- if (r.tag === 161) {
229
- if (n !== void 0) return pkcs7Failure("malformed", "SignedData CRLs field must not repeat");
230
- n = r;
231
- continue;
232
- }
233
- return pkcs7Failure("malformed", "Malformed SignedData optional field");
234
- }
227
+ for (let r of e) if (r.tag === 160) {
228
+ if (n !== void 0) return pkcs7Failure("malformed", "SignedData certificates field must precede CRLs field");
229
+ if (t !== void 0) return pkcs7Failure("malformed", "SignedData certificates field must not repeat");
230
+ t = r;
231
+ } else if (r.tag === 161) {
232
+ if (n !== void 0) return pkcs7Failure("malformed", "SignedData CRLs field must not repeat");
233
+ n = r;
234
+ } else return pkcs7Failure("malformed", "Malformed SignedData optional field");
235
235
  return {
236
236
  ok: !0,
237
237
  value: {
@@ -277,6 +277,7 @@ async function verifyPkcs7SignedData(e, t = {}) {
277
277
  if (!n.ok) return n;
278
278
  let r = n.value, i = r.encapsulatedContent ?? t.content?.slice();
279
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");
280
281
  let a = [];
281
282
  for (let e of r.signerInfos) {
282
283
  let t = await verifyPkcs7SignerInfo(r, e, i);
@@ -308,32 +309,37 @@ async function verifyPkcs7SignerInfo(e, t, n) {
308
309
  }
309
310
  async function verifyPkcs7BareSignerInfo(e, t, n) {
310
311
  try {
311
- let r = await A(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, n);
312
+ let r = await O(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, n);
312
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");
313
- } catch {
314
- return verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
314
+ } catch (e) {
315
+ return signatureVerificationThrowFailure(e);
315
316
  }
316
317
  }
317
318
  /** Shorthand for constructing a PKCS#7 parse failure result. */
318
- function pkcs7Failure(e, t) {
319
- return x(e, t);
319
+ function pkcs7Failure(e, n) {
320
+ return t(e, n);
320
321
  }
321
322
  /** Shorthand for constructing a PKCS#7 verification failure result. */
322
- function verifyPkcs7Failure(e, t) {
323
- return x(e, t);
323
+ /** 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);
327
+ }
328
+ function verifyPkcs7Failure(e, n) {
329
+ return t(e, n);
324
330
  }
325
331
  /** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
326
- function createCertBagFailure(e, t) {
327
- return x(e, t);
332
+ function createCertBagFailure(e, n) {
333
+ return t(e, n);
328
334
  }
329
335
  /** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
330
- function createPkcs7Failure(e, t) {
331
- return x(e, t);
336
+ function createPkcs7Failure(e, n) {
337
+ return t(e, n);
332
338
  }
333
339
  /** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
334
340
  function normalizeCertificateSource(e) {
335
341
  if (typeof e == "string") {
336
- let t = C(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
342
+ let t = E(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
337
343
  if (t.length === 0) throw Error("Certificate PEM required");
338
344
  return t;
339
345
  }
@@ -362,15 +368,15 @@ function contentDigestForPrivateKey(e) {
362
368
  switch (t.namedCurve) {
363
369
  case "P-256": return {
364
370
  hashName: "SHA-256",
365
- digestOid: v.sha256
371
+ digestOid: S.sha256
366
372
  };
367
373
  case "P-384": return {
368
374
  hashName: "SHA-384",
369
- digestOid: v.sha384
375
+ digestOid: S.sha384
370
376
  };
371
377
  case "P-521": return {
372
378
  hashName: "SHA-512",
373
- digestOid: v.sha512
379
+ digestOid: S.sha512
374
380
  };
375
381
  default: return;
376
382
  }
@@ -380,22 +386,22 @@ function contentDigestForPrivateKey(e) {
380
386
  switch (t.hash.name) {
381
387
  case "SHA-256": return {
382
388
  hashName: "SHA-256",
383
- digestOid: v.sha256
389
+ digestOid: S.sha256
384
390
  };
385
391
  case "SHA-384": return {
386
392
  hashName: "SHA-384",
387
- digestOid: v.sha384
393
+ digestOid: S.sha384
388
394
  };
389
395
  case "SHA-512": return {
390
396
  hashName: "SHA-512",
391
- digestOid: v.sha512
397
+ digestOid: S.sha512
392
398
  };
393
399
  default: return;
394
400
  }
395
401
  }
396
402
  if (t.name === "Ed25519") return {
397
403
  hashName: "SHA-512",
398
- digestOid: v.sha512
404
+ digestOid: S.sha512
399
405
  };
400
406
  }
401
407
  /**
@@ -405,10 +411,10 @@ function contentDigestForPrivateKey(e) {
405
411
  * SignerInfo. The two differ only in the leading tag byte.
406
412
  */
407
413
  function buildSignedAttributes(e, t) {
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, {
414
+ let n = p([f([s(S.cmsContentType), p([s(e)])]), f([s(S.cmsMessageDigest), p([c(t)])])]), r = new Uint8Array(n);
415
+ return r[0] = 160, {
410
416
  setForSigning: n,
411
- implicitForEmit: a
417
+ implicitForEmit: r
412
418
  };
413
419
  }
414
420
  /** The X.509 subset of a decoded CertificateSet. */
@@ -422,16 +428,16 @@ function x509CertificatesOf(e) {
422
428
  * value are direct children of the `[3]` element.
423
429
  */
424
430
  function parseOtherCertificateFormatOid(e, t) {
425
- let n = h(u(e, t)[0], "otherCertFormat");
431
+ let n = y(m(e, t)[0], "otherCertFormat");
426
432
  if (n.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
427
- return f(n.value);
433
+ return g(n.value);
428
434
  }
429
435
  /** Decodes one RFC 5652 §10.2.2 CertificateChoices alternative. */
430
436
  function parseCertificateChoice(e, t, n) {
431
437
  switch (t.tag) {
432
438
  case 48: return {
433
439
  type: "certificate",
434
- certificate: O(n)
440
+ certificate: I(n)
435
441
  };
436
442
  case 160: return {
437
443
  type: "extendedCertificate",
@@ -458,107 +464,101 @@ function parseCertificateChoice(e, t, n) {
458
464
  * RFC 5652 §10.2.3 `CertificateSet ::= SET OF CertificateChoices`.
459
465
  */
460
466
  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)));
467
+ return t === void 0 || t.tag !== 160 ? [] : m(e, t).map((t) => parseCertificateChoice(e, t, e.slice(t.start - t.headerLength, t.end)));
462
468
  }
463
469
  /** Extracts the list of digest algorithm OIDs from the digestAlgorithms SET. */
464
470
  function parseDigestAlgorithms(e, t) {
465
471
  let n = [];
466
472
  if (t.tag !== 49) throw Error("digestAlgorithms must use SET");
467
- for (let r of u(e, t)) {
473
+ for (let r of m(e, t)) {
468
474
  if (r.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
469
- let t = s(e.slice(r.start - r.headerLength, r.end)), i = t[0];
470
- if (i === void 0 || t.length < 1 || t.length > 2 || i.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
471
- n.push(f(i.value));
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));
472
478
  }
473
479
  return n;
474
480
  }
475
481
  /** Decodes the signerInfos SET OF from a SignedData structure. */
476
482
  function parseSignerInfos(e, t) {
477
- return u(e, t).map((t) => parseSignerInfo(e, t));
483
+ return m(e, t).map((t) => parseSignerInfo(e, t));
478
484
  }
479
485
  function parseSignerInfo(e, t) {
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];
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];
485
491
  return {
486
- version: d(i.value),
492
+ version: h(i.value),
487
493
  signerIdentifier: parseSignerIdentifier(n.slice(a.start - a.headerLength, a.end)),
488
- digestAlgorithmOid: g,
489
- digestAlgorithmName: w(g),
490
- signatureAlgorithmOid: b,
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 } : {
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 } : {
496
502
  hasSignedAttrs: !0,
497
- signedAttrsDer: new Uint8Array(n.slice(l.start - l.headerLength, l.end))
503
+ signedAttrsDer: new Uint8Array(n.slice(c.start - c.headerLength, c.end))
498
504
  }
499
505
  };
500
506
  }
501
507
  function parsePkcs7AlgorithmOid(e, t, n) {
502
- return f(h(s(e.slice(t.start - t.headerLength, t.end))[0], n).value);
508
+ let r = e.slice(t.start - t.headerLength, t.end);
509
+ return g(y(d(r)[0], n).value);
503
510
  }
504
511
  /** Unwraps the OCTET STRING inside the IMPLICIT [0] encapsulated content. */
505
512
  function extractEncapsulatedContent(e, t) {
506
513
  if (t.tag !== 160) throw Error("Unexpected encapsulated content tag");
507
- let n = a(e, t.start);
514
+ let n = l(e, t.start);
508
515
  if (n.tag !== 4) throw Error("Expected encapsulated OCTET STRING");
509
516
  if (n.end !== t.end) throw Error("Encapsulated content must hold exactly one element");
510
517
  return n.value;
511
518
  }
512
519
  /** Extracts issuer Name and serial number from an issuerAndSerialNumber SEQUENCE, or subjectKeyIdentifier from [0] IMPLICIT. */
513
520
  function parseSignerIdentifier(e) {
514
- let t = o(e, { maxDepth: 64 });
521
+ let t = u(e, { maxDepth: 64 });
515
522
  if (t.tag === 128) {
516
523
  if (t.value.length === 0) throw Error("SignerIdentifier subjectKeyIdentifier must not be empty");
517
524
  return {
518
525
  type: "subjectKeyIdentifier",
519
- subjectKeyIdentifier: _(t.value)
526
+ subjectKeyIdentifier: x(t.value)
520
527
  };
521
528
  }
522
529
  if (t.tag === 48) {
523
- let t = s(e), n = t[0], r = t[1];
530
+ let t = d(e), n = t[0], r = t[1];
524
531
  if (n === void 0 || r === void 0 || t.length !== 2) throw Error("SignerIdentifier issuerAndSerialNumber is malformed");
525
532
  if (n.tag !== 48) throw Error("SignerIdentifier issuer must use Name SEQUENCE");
526
533
  if (r.tag !== 2) throw Error("SignerIdentifier serialNumber must use INTEGER");
527
534
  return assertImplicitSerialNumberEncoding(r.value, "SignerIdentifier serialNumber"), {
528
535
  type: "issuerAndSerialNumber",
529
536
  issuer: parseSignerIssuerName(e, n),
530
- serialNumberHex: _(r.value)
537
+ serialNumberHex: x(r.value)
531
538
  };
532
539
  }
533
540
  throw Error(`Unsupported SignerIdentifier tag: ${String(t.tag)}`);
534
541
  }
535
- const F = new TextDecoder();
536
542
  /** Parses a Name SEQUENCE element from a PKCS#7 signer identifier into a {@linkcode ParsedName}. */
537
543
  function parseSignerIssuerName(e, t) {
538
- let n = _(e.slice(t.start - t.headerLength, t.end)), r = [], i = [], a = {};
539
- for (let n of u(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)) {
540
546
  let t = [], o = {};
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;
543
- try {
544
- d = p(c.tag, c.value);
545
- } catch {
546
- d = F.decode(c.value);
547
- }
548
- let m = E(l), g = m === void 0 ? {
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
549
  oid: l,
550
550
  valueTag: c.tag,
551
- value: d
551
+ value: u
552
552
  } : {
553
553
  oid: l,
554
- key: m,
554
+ key: d,
555
555
  valueTag: c.tag,
556
- value: d
556
+ value: u
557
557
  };
558
- t.push(g), i.push(g), m !== void 0 && (o[m] === void 0 && (o[m] = d), a[m] === void 0 && (a[m] = d));
558
+ t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
559
559
  }
560
560
  r.push({
561
- derHex: _(e.slice(n.start - n.headerLength, n.end)),
561
+ derHex: x(e.slice(n.start - n.headerLength, n.end)),
562
562
  attributes: t,
563
563
  values: o
564
564
  });
@@ -572,27 +572,27 @@ function parseSignerIssuerName(e, t) {
572
572
  }
573
573
  /** Returns the nth child element inside a constructed ASN.1 element, or throws. */
574
574
  function childAt(e, t, n, r) {
575
- let i = t.start, o = 0;
575
+ let i = t.start, a = 0;
576
576
  for (; i < t.end;) {
577
- let t = a(e, i);
578
- if (o === n) return t;
579
- i = t.end, o += 1;
577
+ let t = l(e, i);
578
+ if (a === n) return t;
579
+ i = t.end, a += 1;
580
580
  }
581
581
  throw Error(`Missing ${r}`);
582
582
  }
583
583
  /** Maps a digest algorithm OID to the WebCrypto hash name. */
584
584
  function digestAlgorithmHash(e) {
585
585
  switch (e) {
586
- case v.sha256: return "SHA-256";
587
- case v.sha384: return "SHA-384";
588
- case v.sha512: return "SHA-512";
586
+ case S.sha256: return "SHA-256";
587
+ case S.sha384: return "SHA-384";
588
+ case S.sha512: return "SHA-512";
589
589
  default: throw Error(`Unsupported digest algorithm OID: ${e}`);
590
590
  }
591
591
  }
592
592
  /** Parses required signed attributes and enforces uniqueness + exact-one-value shape. */
593
593
  function parseSignedAttributeRequirements(e) {
594
- let t = a(e), n = {};
595
- for (let r of u(e, t)) parseSignedAttributeRequirement(e, r, n);
594
+ let t = l(e), n = {};
595
+ for (let r of m(e, t)) parseSignedAttributeRequirement(e, r, n);
596
596
  if (n.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
597
597
  if (n.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
598
598
  return {
@@ -601,22 +601,22 @@ function parseSignedAttributeRequirements(e) {
601
601
  };
602
602
  }
603
603
  function parseSignedAttributeRequirement(e, t, n) {
604
- let r = e.slice(t.start - t.headerLength, t.end), i = s(r), a = i[0], o = i[1];
604
+ let r = e.slice(t.start - t.headerLength, t.end), i = d(r), a = i[0], o = i[1];
605
605
  if (a === void 0 || o === void 0 || i.length !== 2 || o.tag !== 49) throw Error("Malformed signedAttrs attribute");
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"));
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"));
608
608
  }
609
609
  function parseUniqueSignedAttributeOctetString(e, t, n) {
610
610
  if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
611
- let r = h(t[0], `${n} attribute value`);
611
+ let r = y(t[0], `${n} attribute value`);
612
612
  if (r.tag !== 4) throw Error(`${n} attribute value must use OCTET STRING`);
613
613
  return r.value;
614
614
  }
615
615
  function parseUniqueSignedAttributeOid(e, t, n) {
616
616
  if (e !== void 0 || t.length !== 1) throw Error(`${n} attribute must appear exactly once with one value`);
617
- let r = h(t[0], `${n} attribute value`);
617
+ let r = y(t[0], `${n} attribute value`);
618
618
  if (r.tag !== 6) throw Error(`${n} attribute value must use OBJECT IDENTIFIER`);
619
- return f(r.value);
619
+ return g(r.value);
620
620
  }
621
621
  /** Replaces the IMPLICIT [0] tag (0xa0) with SET OF (0x31) per RFC 5652 Section 5.4. */
622
622
  function retagSignedAttrsAsSet(e) {
@@ -631,45 +631,47 @@ function constantTimeEqual(e, t) {
631
631
  return n === 0;
632
632
  }
633
633
  /** Verifies a signed-attributes flow: digest match + signature over re-tagged attrs. */
634
- async function verifySignedAttrs(e, t, n, r) {
635
- if (!e.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
636
- let i;
634
+ async function verifySignedAttrs(t, i, a, o) {
635
+ if (!t.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
636
+ let s;
637
637
  try {
638
- assertImplicitSignedAttrsDer(e.signedAttrsDer), i = parseSignedAttributeRequirements(e.signedAttrsDer);
639
- } catch {
640
- return verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData");
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);
641
643
  }
642
- if (i.contentTypeOid !== r) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
643
- let a;
644
+ if (s.contentTypeOid !== o) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
645
+ let c;
644
646
  try {
645
- let t = digestAlgorithmHash(e.digestAlgorithmOid);
646
- a = new Uint8Array(await y().subtle.digest(t, g(n)));
647
+ let e = digestAlgorithmHash(t.digestAlgorithmOid);
648
+ c = new Uint8Array(await C().subtle.digest(e, b(a)));
647
649
  } catch {
648
650
  return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
649
651
  }
650
- if (!constantTimeEqual(a, i.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
651
- let o;
652
+ if (!constantTimeEqual(c, s.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
653
+ let l;
652
654
  try {
653
- o = retagSignedAttrsAsSet(e.signedAttrsDer);
655
+ l = retagSignedAttrsAsSet(t.signedAttrsDer);
654
656
  } catch {
655
657
  return verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData");
656
658
  }
657
- let s;
659
+ let u;
658
660
  try {
659
- let n = await A(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, o);
660
- if (!n.ok) return n.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
661
- s = n.valid;
662
- } catch {
663
- return verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
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;
664
+ } catch (e) {
665
+ return signatureVerificationThrowFailure(e);
664
666
  }
665
- return s ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
667
+ return u ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
666
668
  }
667
669
  function signerIdentifierMatches(e, t) {
668
670
  let n = t.signerIdentifier;
669
- return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && D(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
671
+ return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && F(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
670
672
  }
671
673
  function assertImplicitSignedAttrsDer(e) {
672
- if (a(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
674
+ if (l(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
673
675
  }
674
676
  function hasReparseablePkcs7SignedData(e) {
675
677
  return "der" in e && e.der instanceof Uint8Array;
@@ -680,7 +682,6 @@ function assertImplicitSerialNumberEncoding(e, t) {
680
682
  if (n & 128) throw Error(`${t} must be non-negative`);
681
683
  if (e.length > 1 && n === 0 && !((e[1] ?? 0) & 128)) throw Error(`${t} must use minimal encoding`);
682
684
  }
683
- //#endregion
684
685
  export { createPkcs7CertBag, createPkcs7SignedData, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, verifyPkcs7SignedData };
685
686
 
686
687
  //# sourceMappingURL=pkcs7.js.map