micro509 0.17.1 → 0.18.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 (126) hide show
  1. package/CHANGELOG.md +78 -6
  2. package/dist/crypto/crypto.d.ts +2 -3
  3. package/dist/crypto.d.ts +6 -0
  4. package/dist/der/der.d.ts +14 -4
  5. package/dist/der/der.js +19 -19
  6. package/dist/der.d.ts +26 -2
  7. package/dist/der.js +4 -4
  8. package/dist/index.d.ts +82 -15
  9. package/dist/index.js +19 -19
  10. package/dist/internal/asn1/asn1.d.ts +1 -2
  11. package/dist/internal/asn1/der.d.ts +1 -2
  12. package/dist/internal/asn1/oids.js +71 -353
  13. package/dist/internal/asn1/oids.js.map +1 -1
  14. package/dist/internal/asn1/oids.json.js +357 -0
  15. package/dist/internal/asn1/oids.json.js.map +1 -0
  16. package/dist/internal/crypto/algorithm-names.js +1 -1
  17. package/dist/internal/crypto/pbes2.d.ts +1 -2
  18. package/dist/internal/crypto/pbes2.js +70 -70
  19. package/dist/internal/crypto/prime-ec.js +37 -0
  20. package/dist/internal/crypto/prime-ec.js.map +1 -0
  21. package/dist/internal/crypto/rsa-pss.js +50 -50
  22. package/dist/internal/crypto/sig-verify.d.ts +1 -2
  23. package/dist/internal/crypto/sig-verify.js +60 -60
  24. package/dist/internal/crypto/signing.d.ts +1 -2
  25. package/dist/internal/crypto/signing.js +26 -26
  26. package/dist/internal/jose/json-data.js +108 -0
  27. package/dist/internal/jose/json-data.js.map +1 -0
  28. package/dist/internal/jose/strict-json.d.ts +1 -2
  29. package/dist/internal/shared/dn.d.ts +1 -2
  30. package/dist/internal/shared/dn.js +1 -1
  31. package/dist/internal/shared/ip.d.ts +1 -2
  32. package/dist/internal/verify/name-constraints-engine.js +64 -64
  33. package/dist/internal/verify/policy-engine.js +1 -1
  34. package/dist/internal/verify/verify-path.d.ts +1 -2
  35. package/dist/internal/verify/verify-path.js +19 -19
  36. package/dist/internal/x509/directory-name.js +10 -10
  37. package/dist/internal/x509/extension-errors.d.ts +1 -2
  38. package/dist/internal/x509/extension-registry.js +18 -18
  39. package/dist/internal/x509/general-name-profile.js +9 -9
  40. package/dist/internal/x509/general-name.js +32 -32
  41. package/dist/internal/x509/name-fields.js +1 -1
  42. package/dist/jose/base64url.d.ts +4 -0
  43. package/dist/jose/base64url.js +14 -0
  44. package/dist/jose/base64url.js.map +1 -0
  45. package/dist/jose/errors.d.ts +9 -3
  46. package/dist/jose/errors.js.map +1 -1
  47. package/dist/jose/jwe.d.ts +64 -0
  48. package/dist/jose/jwe.js +188 -0
  49. package/dist/jose/jwe.js.map +1 -0
  50. package/dist/jose/jwks.d.ts +38 -10
  51. package/dist/jose/jwks.js +156 -96
  52. package/dist/jose/jwks.js.map +1 -1
  53. package/dist/jose/jws.d.ts +8 -6
  54. package/dist/jose/jws.js +216 -170
  55. package/dist/jose/jws.js.map +1 -1
  56. package/dist/jose/jwt.d.ts +8 -2
  57. package/dist/jose/jwt.js +98 -98
  58. package/dist/jose/remote-jwks.d.ts +1 -2
  59. package/dist/jose/remote-jwks.js +106 -108
  60. package/dist/jose/remote-jwks.js.map +1 -1
  61. package/dist/jose.d.ts +15 -4
  62. package/dist/jose.js +7 -5
  63. package/dist/kdf/argon2.d.ts +7 -2
  64. package/dist/kdf.d.ts +6 -0
  65. package/dist/keys/keys.d.ts +31 -6
  66. package/dist/keys/keys.js +315 -233
  67. package/dist/keys/keys.js.map +1 -1
  68. package/dist/keys.d.ts +11 -2
  69. package/dist/keys.js +2 -2
  70. package/dist/pem/pem.d.ts +1 -2
  71. package/dist/pem/pem.js +40 -25
  72. package/dist/pem/pem.js.map +1 -1
  73. package/dist/pem.d.ts +6 -0
  74. package/dist/pkcs/pfx.d.ts +2 -3
  75. package/dist/pkcs/pfx.js +142 -142
  76. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  77. package/dist/pkcs/pkcs12-mac.js +122 -122
  78. package/dist/pkcs/pkcs7.d.ts +14 -3
  79. package/dist/pkcs/pkcs7.js +268 -248
  80. package/dist/pkcs/pkcs7.js.map +1 -1
  81. package/dist/pkcs.d.ts +10 -1
  82. package/dist/pkcs.js +4 -4
  83. package/dist/result/result.d.ts +1 -2
  84. package/dist/result.d.ts +6 -0
  85. package/dist/revocation/chain.d.ts +2 -3
  86. package/dist/revocation/chain.js +52 -52
  87. package/dist/revocation/crl.d.ts +2 -3
  88. package/dist/revocation/crl.js +319 -319
  89. package/dist/revocation/crl.js.map +1 -1
  90. package/dist/revocation/ocsp.d.ts +2 -3
  91. package/dist/revocation/ocsp.js +395 -395
  92. package/dist/revocation/revocation.d.ts +2 -3
  93. package/dist/revocation/revocation.js +22 -22
  94. package/dist/revocation.d.ts +12 -3
  95. package/dist/revocation.js +4 -4
  96. package/dist/ssh/ssh.d.ts +2 -3
  97. package/dist/ssh/ssh.js +165 -170
  98. package/dist/ssh/ssh.js.map +1 -1
  99. package/dist/ssh/wire.d.ts +1 -2
  100. package/dist/ssh/wire.js +10 -10
  101. package/dist/ssh.d.ts +8 -0
  102. package/dist/verify/identity.d.ts +1 -2
  103. package/dist/verify/identity.js +31 -31
  104. package/dist/verify/name-constraints.d.ts +9 -2
  105. package/dist/verify/policy.d.ts +9 -2
  106. package/dist/verify/verify.d.ts +3 -4
  107. package/dist/verify/verify.js +121 -121
  108. package/dist/verify.d.ts +9 -0
  109. package/dist/x509/certificate.d.ts +4 -5
  110. package/dist/x509/certificate.js +40 -40
  111. package/dist/x509/csr.d.ts +3 -4
  112. package/dist/x509/csr.js +15 -15
  113. package/dist/x509/extensions.d.ts +1 -2
  114. package/dist/x509/extensions.js +165 -165
  115. package/dist/x509/extensions.js.map +1 -1
  116. package/dist/x509/fingerprint.d.ts +1 -2
  117. package/dist/x509/name-text.d.ts +1 -2
  118. package/dist/x509/name.d.ts +1 -2
  119. package/dist/x509/name.js +15 -15
  120. package/dist/x509/parse.d.ts +3 -4
  121. package/dist/x509/parse.js +423 -423
  122. package/dist/x509.d.ts +17 -4
  123. package/dist/x509.js +8 -8
  124. package/package.json +22 -23
  125. package/dist/internal/asn1/oids2.js +0 -75
  126. package/dist/internal/asn1/oids2.js.map +0 -1
@@ -1,16 +1,16 @@
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";
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 { getVerifySignatureConfigResult as S, verifySignedDataDetailed as C } from "../internal/crypto/sig-verify.js";
7
+ import { encodeAlgorithmIdentifier as w, getSignatureAlgorithm as T, signBytes as E } from "../internal/crypto/signing.js";
8
+ import { getCrypto as D } from "../internal/crypto/webcrypto.js";
9
+ import { base64Encode as O } from "../internal/shared/base64.js";
10
+ import { compareDistinguishedNames as k } from "../internal/shared/dn.js";
11
+ import { pemEncode as A, splitPemBlocksOrThrow as j } from "../pem/pem.js";
12
+ import { DECODE_REFUSAL_CODES as M, failureResult as N, rethrowIfInvariant as P } from "../result/result.js";
13
+ import { nameFieldKeyFromOid as F } from "../internal/x509/name-fields.js";
14
14
  import { parseCertificateDerOrThrow as I } from "../x509/parse.js";
15
15
  // src/pkcs/pkcs7.ts
16
16
  /**
@@ -32,30 +32,30 @@ const L = ["PKCS7", "CMS"];
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) I(e);
40
+ } catch (e) {
41
+ let t = c(e, M);
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: A("PKCS7", i),
58
+ base64: O(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 = e.content.slice(), 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)) I(e), addCertificate(e);
95
+ } catch (e) {
96
+ let t = c(e, M);
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: A(u === 1 ? "PKCS7" : "CMS", g),
113
+ base64: O(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 = I(a);
135
+ } catch (e) {
136
+ let t = c(e, M);
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 = T(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 (!S(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 D().subtle.digest(m.hashName, o(t)))), v;
149
149
  try {
150
- _ = await j(t.privateKey, p, h);
150
+ v = await E(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
+ w(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 = j(e).filter((e) => L.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
+ P(e);
221
+ let t = c(e, M);
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,40 @@ function parsePkcs7SignedDataPem(e) {
273
277
  * ```
274
278
  */
275
279
  async function verifyPkcs7SignedData(e, t = {}) {
276
- let n = normalizePkcs7SignedDataForVerification(e);
277
- 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);
280
+ let r, i = t.signedAttributes ?? "required";
281
+ if (![
282
+ "required",
283
+ "allowed",
284
+ "forbidden"
285
+ ].includes(i)) return verifyPkcs7Failure("invalid_options", "Unknown signed-attribute policy");
286
+ try {
287
+ r = n(m(f(t.expectedContentTypeOid ?? y.pkcs7Data)).value);
288
+ } catch {
289
+ return verifyPkcs7Failure("invalid_options", "Expected content type must be an OID");
290
+ }
291
+ let a = normalizePkcs7SignedDataForVerification(e);
292
+ if (!a.ok) return a;
293
+ let o = a.value, s = o.encapsulatedContent ?? t.content?.slice();
294
+ if (s === void 0) return verifyPkcs7Failure("detached_content_required", "SignedData has no encapsulated content; supply the detached content via options.content");
295
+ if (o.signerInfos.length === 0) return verifyPkcs7Failure("no_signers", "SignedData contains no signer information");
296
+ if (o.encapsulatedContentTypeOid !== r) return verifyPkcs7Failure("content_type_mismatch", "Unexpected SignedData content type");
297
+ for (let e of o.signerInfos) {
298
+ if (!e.hasSignedAttrs && (i === "required" || o.encapsulatedContentTypeOid !== y.pkcs7Data)) return verifyPkcs7Failure("signed_attributes_required", "Signed attributes are required");
299
+ if (e.hasSignedAttrs && i === "forbidden") return verifyPkcs7Failure("signed_attributes_forbidden", "Signed attributes are forbidden");
300
+ }
301
+ let c = [];
302
+ for (let e of o.signerInfos) {
303
+ let t = await verifyPkcs7SignerInfo(o, e, s);
284
304
  if (!t.ok) return t;
285
- a.push({
305
+ c.push({
286
306
  signerInfo: e,
287
307
  certificate: t.certificate
288
308
  });
289
309
  }
290
310
  return {
291
311
  ok: !0,
292
- value: r,
293
- signers: a
312
+ value: o,
313
+ signers: c
294
314
  };
295
315
  }
296
316
  /** Normalizes encoded or parsed SignedData into a freshly parsed verification input. */
@@ -309,37 +329,37 @@ async function verifyPkcs7SignerInfo(e, t, n) {
309
329
  }
310
330
  async function verifyPkcs7BareSignerInfo(e, t, n) {
311
331
  try {
312
- let r = await O(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, n);
332
+ let r = await C(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, n);
313
333
  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");
314
334
  } catch (e) {
315
335
  return signatureVerificationThrowFailure(e);
316
336
  }
317
337
  }
318
338
  /** Shorthand for constructing a PKCS#7 parse failure result. */
319
- function pkcs7Failure(e, n) {
320
- return t(e, n);
339
+ function pkcs7Failure(e, t) {
340
+ return N(e, t);
321
341
  }
322
342
  /** Shorthand for constructing a PKCS#7 verification failure result. */
323
343
  /** 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);
344
+ function signatureVerificationThrowFailure(e) {
345
+ let t = c(e, M);
346
+ return t === void 0 ? verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData") : verifyPkcs7Failure(t.code, t.message);
327
347
  }
328
- function verifyPkcs7Failure(e, n) {
329
- return t(e, n);
348
+ function verifyPkcs7Failure(e, t) {
349
+ return N(e, t);
330
350
  }
331
351
  /** Shorthand for constructing a PKCS#7 certificate bag creation failure result. */
332
- function createCertBagFailure(e, n) {
333
- return t(e, n);
352
+ function createCertBagFailure(e, t) {
353
+ return N(e, t);
334
354
  }
335
355
  /** Shorthand for constructing a PKCS#7 SignedData creation failure result. */
336
- function createPkcs7Failure(e, n) {
337
- return t(e, n);
356
+ function createPkcs7Failure(e, t) {
357
+ return N(e, t);
338
358
  }
339
359
  /** Converts PEM text to an array of DER certificate blobs, or wraps raw DER. */
340
360
  function normalizeCertificateSource(e) {
341
361
  if (typeof e == "string") {
342
- let t = E(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
362
+ let t = j(e).filter((e) => e.label === "CERTIFICATE").map((e) => new Uint8Array(e.bytes));
343
363
  if (t.length === 0) throw Error("Certificate PEM required");
344
364
  return t;
345
365
  }
@@ -368,15 +388,15 @@ function contentDigestForPrivateKey(e) {
368
388
  switch (t.namedCurve) {
369
389
  case "P-256": return {
370
390
  hashName: "SHA-256",
371
- digestOid: S.sha256
391
+ digestOid: y.sha256
372
392
  };
373
393
  case "P-384": return {
374
394
  hashName: "SHA-384",
375
- digestOid: S.sha384
395
+ digestOid: y.sha384
376
396
  };
377
397
  case "P-521": return {
378
398
  hashName: "SHA-512",
379
- digestOid: S.sha512
399
+ digestOid: y.sha512
380
400
  };
381
401
  default: return;
382
402
  }
@@ -386,22 +406,22 @@ function contentDigestForPrivateKey(e) {
386
406
  switch (t.hash.name) {
387
407
  case "SHA-256": return {
388
408
  hashName: "SHA-256",
389
- digestOid: S.sha256
409
+ digestOid: y.sha256
390
410
  };
391
411
  case "SHA-384": return {
392
412
  hashName: "SHA-384",
393
- digestOid: S.sha384
413
+ digestOid: y.sha384
394
414
  };
395
415
  case "SHA-512": return {
396
416
  hashName: "SHA-512",
397
- digestOid: S.sha512
417
+ digestOid: y.sha512
398
418
  };
399
419
  default: return;
400
420
  }
401
421
  }
402
422
  if (t.name === "Ed25519") return {
403
423
  hashName: "SHA-512",
404
- digestOid: S.sha512
424
+ digestOid: y.sha512
405
425
  };
406
426
  }
407
427
  /**
@@ -411,7 +431,7 @@ function contentDigestForPrivateKey(e) {
411
431
  * SignerInfo. The two differ only in the leading tag byte.
412
432
  */
413
433
  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);
434
+ let n = v([_([f(y.cmsContentType), v([f(e)])]), _([f(y.cmsMessageDigest), v([p(t)])])]), r = new Uint8Array(n);
415
435
  return r[0] = 160, {
416
436
  setForSigning: n,
417
437
  implicitForEmit: r
@@ -427,10 +447,10 @@ function x509CertificatesOf(e) {
427
447
  * The IMPLICIT tag replaces the SEQUENCE tag, so the OID and the `ANY DEFINED BY`
428
448
  * value are direct children of the `[3]` element.
429
449
  */
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);
450
+ function parseOtherCertificateFormatOid(t, r) {
451
+ let i = a(e(t, r)[0], "otherCertFormat");
452
+ if (i.tag !== 6) throw Error("otherCertFormat must be an OBJECT IDENTIFIER");
453
+ return n(i.value);
434
454
  }
435
455
  /** Decodes one RFC 5652 §10.2.2 CertificateChoices alternative. */
436
456
  function parseCertificateChoice(e, t, n) {
@@ -463,118 +483,118 @@ function parseCertificateChoice(e, t, n) {
463
483
  * Parses the IMPLICIT [0] certificate set from a SignedData structure as
464
484
  * RFC 5652 §10.2.3 `CertificateSet ::= SET OF CertificateChoices`.
465
485
  */
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)));
486
+ function parseCertificateSet(t, n) {
487
+ return n === void 0 || n.tag !== 160 ? [] : e(t, n).map((e) => parseCertificateChoice(t, e, t.slice(e.start - e.headerLength, e.end)));
468
488
  }
469
489
  /** 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));
490
+ function parseDigestAlgorithms(t, r) {
491
+ let i = [];
492
+ if (r.tag !== 49) throw Error("digestAlgorithms must use SET");
493
+ for (let a of e(t, r)) {
494
+ if (a.tag !== 48) throw Error("digestAlgorithm must use AlgorithmIdentifier SEQUENCE");
495
+ let e = t.slice(a.start - a.headerLength, a.end), r = g(e), o = r[0];
496
+ if (o === void 0 || r.length < 1 || r.length > 2 || o.tag !== 6) throw Error("Malformed digest AlgorithmIdentifier");
497
+ i.push(n(o.value));
478
498
  }
479
- return n;
499
+ return i;
480
500
  }
481
501
  /** 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];
502
+ function parseSignerInfos(t, n) {
503
+ return e(t, n).map((e) => parseSignerInfo(t, e));
504
+ }
505
+ function parseSignerInfo(e, r) {
506
+ 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;
507
+ f !== void 0 && (d += 1);
508
+ let p = o[d], m = o[d + 1], h = o[d + 2];
509
+ 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");
510
+ 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
511
  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 } : {
512
+ version: t(c.value),
513
+ signerIdentifier: parseSignerIdentifier(i.slice(l.start - l.headerLength, l.end)),
514
+ digestAlgorithmOid: _,
515
+ digestAlgorithmName: b(_),
516
+ signatureAlgorithmOid: S,
517
+ signatureAlgorithmName: x(S, C === void 0 ? void 0 : new Uint8Array(v.slice(C.start - C.headerLength, C.end))),
518
+ ...C === void 0 ? {} : { signatureAlgorithmParametersDer: new Uint8Array(v.slice(C.start - C.headerLength, C.end)) },
519
+ signatureHex: s(m.value),
520
+ signature: new Uint8Array(m.value),
521
+ ...f === void 0 ? { hasSignedAttrs: !1 } : {
502
522
  hasSignedAttrs: !0,
503
- signedAttrsDer: new Uint8Array(n.slice(c.start - c.headerLength, c.end))
523
+ signedAttrsDer: new Uint8Array(i.slice(f.start - f.headerLength, f.end))
504
524
  }
505
525
  };
506
526
  }
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);
527
+ function parsePkcs7AlgorithmOid(e, t, r) {
528
+ let i = e.slice(t.start - t.headerLength, t.end);
529
+ return n(a(g(i)[0], r).value);
510
530
  }
511
531
  /** Unwraps the OCTET STRING inside the IMPLICIT [0] encapsulated content. */
512
532
  function extractEncapsulatedContent(e, t) {
513
533
  if (t.tag !== 160) throw Error("Unexpected encapsulated content tag");
514
- let n = l(e, t.start);
534
+ let n = m(e, t.start);
515
535
  if (n.tag !== 4) throw Error("Expected encapsulated OCTET STRING");
516
536
  if (n.end !== t.end) throw Error("Encapsulated content must hold exactly one element");
517
537
  return n.value;
518
538
  }
519
539
  /** Extracts issuer Name and serial number from an issuerAndSerialNumber SEQUENCE, or subjectKeyIdentifier from [0] IMPLICIT. */
520
540
  function parseSignerIdentifier(e) {
521
- let t = u(e, { maxDepth: 64 });
541
+ let t = h(e, { maxDepth: 64 });
522
542
  if (t.tag === 128) {
523
543
  if (t.value.length === 0) throw Error("SignerIdentifier subjectKeyIdentifier must not be empty");
524
544
  return {
525
545
  type: "subjectKeyIdentifier",
526
- subjectKeyIdentifier: x(t.value)
546
+ subjectKeyIdentifier: s(t.value)
527
547
  };
528
548
  }
529
549
  if (t.tag === 48) {
530
- let t = d(e), n = t[0], r = t[1];
550
+ let t = g(e), n = t[0], r = t[1];
531
551
  if (n === void 0 || r === void 0 || t.length !== 2) throw Error("SignerIdentifier issuerAndSerialNumber is malformed");
532
552
  if (n.tag !== 48) throw Error("SignerIdentifier issuer must use Name SEQUENCE");
533
553
  if (r.tag !== 2) throw Error("SignerIdentifier serialNumber must use INTEGER");
534
554
  return assertImplicitSerialNumberEncoding(r.value, "SignerIdentifier serialNumber"), {
535
555
  type: "issuerAndSerialNumber",
536
556
  issuer: parseSignerIssuerName(e, n),
537
- serialNumberHex: x(r.value)
557
+ serialNumberHex: s(r.value)
538
558
  };
539
559
  }
540
560
  throw Error(`Unsupported SignerIdentifier tag: ${String(t.tag)}`);
541
561
  }
542
562
  /** 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
563
+ function parseSignerIssuerName(t, i) {
564
+ let o = s(t.slice(i.start - i.headerLength, i.end)), c = [], l = [], u = {};
565
+ for (let o of e(t, i)) {
566
+ let i = [], d = {};
567
+ for (let s of e(t, o)) {
568
+ 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 = F(p), g = h === void 0 ? {
569
+ oid: p,
570
+ valueTag: f.tag,
571
+ value: m
552
572
  } : {
553
- oid: l,
554
- key: d,
555
- valueTag: c.tag,
556
- value: u
573
+ oid: p,
574
+ key: h,
575
+ valueTag: f.tag,
576
+ value: m
557
577
  };
558
- t.push(f), i.push(f), d !== void 0 && (o[d] === void 0 && (o[d] = u), a[d] === void 0 && (a[d] = u));
578
+ i.push(g), l.push(g), h !== void 0 && (d[h] === void 0 && (d[h] = m), u[h] === void 0 && (u[h] = m));
559
579
  }
560
- r.push({
561
- derHex: x(e.slice(n.start - n.headerLength, n.end)),
562
- attributes: t,
563
- values: o
580
+ c.push({
581
+ derHex: s(t.slice(o.start - o.headerLength, o.end)),
582
+ attributes: i,
583
+ values: d
564
584
  });
565
585
  }
566
586
  return {
567
- derHex: n,
568
- rdns: r,
569
- attributes: i,
570
- values: a
587
+ derHex: o,
588
+ rdns: c,
589
+ attributes: l,
590
+ values: u
571
591
  };
572
592
  }
573
593
  /** Returns the nth child element inside a constructed ASN.1 element, or throws. */
574
594
  function childAt(e, t, n, r) {
575
595
  let i = t.start, a = 0;
576
596
  for (; i < t.end;) {
577
- let t = l(e, i);
597
+ let t = m(e, i);
578
598
  if (a === n) return t;
579
599
  i = t.end, a += 1;
580
600
  }
@@ -583,40 +603,40 @@ function childAt(e, t, n, r) {
583
603
  /** Maps a digest algorithm OID to the WebCrypto hash name. */
584
604
  function digestAlgorithmHash(e) {
585
605
  switch (e) {
586
- case S.sha256: return "SHA-256";
587
- case S.sha384: return "SHA-384";
588
- case S.sha512: return "SHA-512";
606
+ case y.sha256: return "SHA-256";
607
+ case y.sha384: return "SHA-384";
608
+ case y.sha512: return "SHA-512";
589
609
  default: throw Error(`Unsupported digest algorithm OID: ${e}`);
590
610
  }
591
611
  }
592
612
  /** 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");
613
+ function parseSignedAttributeRequirements(t) {
614
+ let n = m(t), r = {};
615
+ for (let i of e(t, n)) parseSignedAttributeRequirement(t, i, r);
616
+ if (r.messageDigest === void 0) throw Error("Missing messageDigest attribute in signedAttrs");
617
+ if (r.contentTypeOid === void 0) throw Error("Missing contentType attribute in signedAttrs");
598
618
  return {
599
- messageDigest: n.messageDigest,
600
- contentTypeOid: n.contentTypeOid
619
+ messageDigest: r.messageDigest,
620
+ contentTypeOid: r.contentTypeOid
601
621
  };
602
622
  }
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"));
623
+ function parseSignedAttributeRequirement(t, r, i) {
624
+ let a = t.slice(r.start - r.headerLength, r.end), o = g(a), s = o[0], c = o[1];
625
+ if (s === void 0 || c === void 0 || o.length !== 2 || c.tag !== 49) throw Error("Malformed signedAttrs attribute");
626
+ let l = n(s.value), u = e(a, c);
627
+ l === y.cmsMessageDigest && (i.messageDigest = parseUniqueSignedAttributeOctetString(i.messageDigest, u, "messageDigest")), l === y.cmsContentType && (i.contentTypeOid = parseUniqueSignedAttributeOid(i.contentTypeOid, u, "contentType"));
608
628
  }
609
629
  function parseUniqueSignedAttributeOctetString(e, t, n) {
610
630
  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`);
631
+ let r = a(t[0], `${n} attribute value`);
612
632
  if (r.tag !== 4) throw Error(`${n} attribute value must use OCTET STRING`);
613
633
  return r.value;
614
634
  }
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);
635
+ function parseUniqueSignedAttributeOid(e, t, r) {
636
+ if (e !== void 0 || t.length !== 1) throw Error(`${r} attribute must appear exactly once with one value`);
637
+ let i = a(t[0], `${r} attribute value`);
638
+ if (i.tag !== 6) throw Error(`${r} attribute value must use OBJECT IDENTIFIER`);
639
+ return n(i.value);
620
640
  }
621
641
  /** Replaces the IMPLICIT [0] tag (0xa0) with SET OF (0x31) per RFC 5652 Section 5.4. */
622
642
  function retagSignedAttrsAsSet(e) {
@@ -631,47 +651,47 @@ function constantTimeEqual(e, t) {
631
651
  return n === 0;
632
652
  }
633
653
  /** 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;
654
+ async function verifySignedAttrs(e, t, n, r) {
655
+ if (!e.hasSignedAttrs) return verifyPkcs7Failure("malformed", "Missing signedAttrs DER");
656
+ let i;
637
657
  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);
658
+ assertImplicitSignedAttrsDer(e.signedAttrsDer), i = parseSignedAttributeRequirements(e.signedAttrsDer);
659
+ } catch (e) {
660
+ P(e);
661
+ let t = c(e, M);
662
+ return t === void 0 ? verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData") : verifyPkcs7Failure(t.code, t.message);
643
663
  }
644
- if (s.contentTypeOid !== o) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
645
- let c;
664
+ if (i.contentTypeOid !== r) return verifyPkcs7Failure("malformed", "SignedData contentType attribute does not match");
665
+ let a;
646
666
  try {
647
- let e = digestAlgorithmHash(t.digestAlgorithmOid);
648
- c = new Uint8Array(await C().subtle.digest(e, b(a)));
667
+ let t = digestAlgorithmHash(e.digestAlgorithmOid);
668
+ a = new Uint8Array(await D().subtle.digest(t, o(n)));
649
669
  } catch {
650
670
  return verifyPkcs7Failure("malformed", "Unsupported digest algorithm in SignedData");
651
671
  }
652
- if (!constantTimeEqual(c, s.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
653
- let l;
672
+ if (!constantTimeEqual(a, i.messageDigest)) return verifyPkcs7Failure("message_digest_mismatch", "Content digest does not match messageDigest attribute");
673
+ let s;
654
674
  try {
655
- l = retagSignedAttrsAsSet(t.signedAttrsDer);
675
+ s = retagSignedAttrsAsSet(e.signedAttrsDer);
656
676
  } catch {
657
677
  return verifyPkcs7Failure("malformed", "Malformed signedAttrs in SignedData");
658
678
  }
659
- let u;
679
+ let l;
660
680
  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;
681
+ let n = await C(e.signatureAlgorithmOid, e.signatureAlgorithmParametersDer, t.publicKeyAlgorithmOid, t.publicKeyParametersOid, t.subjectPublicKeyInfoDer, e.signature, s);
682
+ if (!n.ok) return n.code === "verification_error" ? verifyPkcs7Failure("malformed", "SignedData signature verification failed") : verifyPkcs7Failure("malformed", "Unsupported signature algorithm in SignedData");
683
+ l = n.valid;
664
684
  } catch (e) {
665
685
  return signatureVerificationThrowFailure(e);
666
686
  }
667
- return u ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
687
+ return l ? { ok: !0 } : verifyPkcs7Failure("signature_invalid", "SignedData signature over signedAttrs does not verify");
668
688
  }
669
689
  function signerIdentifierMatches(e, t) {
670
690
  let n = t.signerIdentifier;
671
- return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && F(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
691
+ return n.type === "issuerAndSerialNumber" ? e.serialNumberHex === n.serialNumberHex && k(e.issuer, n.issuer) : e.subjectKeyIdentifier === n.subjectKeyIdentifier;
672
692
  }
673
693
  function assertImplicitSignedAttrsDer(e) {
674
- if (l(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
694
+ if (m(e).tag !== 160) throw Error("signedAttrs must use IMPLICIT [0] tag");
675
695
  }
676
696
  function hasReparseablePkcs7SignedData(e) {
677
697
  return "der" in e && e.der instanceof Uint8Array;