micro509 0.9.0 → 0.11.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 (111) hide show
  1. package/dist/index.d.ts +5 -4
  2. package/dist/index.js +16 -15
  3. package/dist/internal/asn1/asn1.js +145 -186
  4. package/dist/internal/asn1/asn1.js.map +1 -0
  5. package/dist/internal/asn1/der.js +210 -227
  6. package/dist/internal/asn1/der.js.map +1 -0
  7. package/dist/internal/asn1/oids.js +297 -101
  8. package/dist/internal/asn1/oids.js.map +1 -0
  9. package/dist/internal/asn1/oids2.js +69 -0
  10. package/dist/internal/asn1/oids2.js.map +1 -0
  11. package/dist/internal/crypto/algorithm-names.js +37 -35
  12. package/dist/internal/crypto/algorithm-names.js.map +1 -0
  13. package/dist/internal/crypto/ecdsa.js +25 -28
  14. package/dist/internal/crypto/ecdsa.js.map +1 -0
  15. package/dist/internal/crypto/hash.js +56 -117
  16. package/dist/internal/crypto/hash.js.map +1 -0
  17. package/dist/internal/crypto/pbes2.js +122 -133
  18. package/dist/internal/crypto/pbes2.js.map +1 -0
  19. package/dist/internal/crypto/rsa-pss.js +118 -124
  20. package/dist/internal/crypto/rsa-pss.js.map +1 -0
  21. package/dist/internal/crypto/sig-verify.js +87 -99
  22. package/dist/internal/crypto/sig-verify.js.map +1 -0
  23. package/dist/internal/crypto/signing.d.ts +12 -8
  24. package/dist/internal/crypto/signing.js +53 -55
  25. package/dist/internal/crypto/signing.js.map +1 -0
  26. package/dist/internal/crypto/webcrypto.js +5 -3
  27. package/dist/internal/crypto/webcrypto.js.map +1 -0
  28. package/dist/internal/shared/base64.js +10 -9
  29. package/dist/internal/shared/base64.js.map +1 -0
  30. package/dist/internal/shared/dn.js +50 -57
  31. package/dist/internal/shared/dn.js.map +1 -0
  32. package/dist/internal/shared/ip.js +43 -53
  33. package/dist/internal/shared/ip.js.map +1 -0
  34. package/dist/internal/verify/name-constraints-engine.js +211 -239
  35. package/dist/internal/verify/name-constraints-engine.js.map +1 -0
  36. package/dist/internal/verify/policy-engine.js +228 -247
  37. package/dist/internal/verify/policy-engine.js.map +1 -0
  38. package/dist/internal/verify/verify-path.js +213 -228
  39. package/dist/internal/verify/verify-path.js.map +1 -0
  40. package/dist/internal/x509/extension-bits.js +62 -59
  41. package/dist/internal/x509/extension-bits.js.map +1 -0
  42. package/dist/internal/x509/extension-registry.js +133 -164
  43. package/dist/internal/x509/extension-registry.js.map +1 -0
  44. package/dist/internal/x509/name-fields.js +35 -41
  45. package/dist/internal/x509/name-fields.js.map +1 -0
  46. package/dist/keys/keys.d.ts +583 -547
  47. package/dist/keys/keys.js +519 -431
  48. package/dist/keys/keys.js.map +1 -0
  49. package/dist/keys.js +2 -2
  50. package/dist/pem/pem.d.ts +46 -46
  51. package/dist/pem/pem.js +62 -81
  52. package/dist/pem/pem.js.map +1 -0
  53. package/dist/pem.js +2 -2
  54. package/dist/pkcs/pfx.d.ts +96 -80
  55. package/dist/pkcs/pfx.js +191 -231
  56. package/dist/pkcs/pfx.js.map +1 -0
  57. package/dist/pkcs/pkcs12-mac.d.ts +20 -18
  58. package/dist/pkcs/pkcs12-mac.js +90 -111
  59. package/dist/pkcs/pkcs12-mac.js.map +1 -0
  60. package/dist/pkcs/pkcs7.d.ts +118 -69
  61. package/dist/pkcs/pkcs7.js +401 -443
  62. package/dist/pkcs/pkcs7.js.map +1 -0
  63. package/dist/pkcs.d.ts +2 -2
  64. package/dist/pkcs.js +4 -4
  65. package/dist/result/result.d.ts +37 -32
  66. package/dist/result/result.js +46 -44
  67. package/dist/result/result.js.map +1 -0
  68. package/dist/result.js +2 -2
  69. package/dist/revocation/chain.d.ts +138 -119
  70. package/dist/revocation/chain.js +248 -281
  71. package/dist/revocation/chain.js.map +1 -0
  72. package/dist/revocation/crl.d.ts +125 -123
  73. package/dist/revocation/crl.js +653 -745
  74. package/dist/revocation/crl.js.map +1 -0
  75. package/dist/revocation/ocsp.d.ts +183 -177
  76. package/dist/revocation/ocsp.js +579 -636
  77. package/dist/revocation/ocsp.js.map +1 -0
  78. package/dist/revocation/revocation.d.ts +26 -26
  79. package/dist/revocation/revocation.js +104 -125
  80. package/dist/revocation/revocation.js.map +1 -0
  81. package/dist/revocation.js +5 -5
  82. package/dist/verify/identity.d.ts +42 -42
  83. package/dist/verify/identity.js +158 -167
  84. package/dist/verify/identity.js.map +1 -0
  85. package/dist/verify/name-constraints.d.ts +7 -7
  86. package/dist/verify/policy.d.ts +10 -10
  87. package/dist/verify/verify.d.ts +163 -163
  88. package/dist/verify/verify.js +396 -392
  89. package/dist/verify/verify.js.map +1 -0
  90. package/dist/verify.js +3 -3
  91. package/dist/x509/certificate.d.ts +117 -117
  92. package/dist/x509/certificate.js +51 -60
  93. package/dist/x509/certificate.js.map +1 -0
  94. package/dist/x509/csr.d.ts +25 -25
  95. package/dist/x509/csr.js +26 -30
  96. package/dist/x509/csr.js.map +1 -0
  97. package/dist/x509/extensions.d.ts +228 -184
  98. package/dist/x509/extensions.js +175 -200
  99. package/dist/x509/extensions.js.map +1 -0
  100. package/dist/x509/fingerprint.d.ts +55 -0
  101. package/dist/x509/fingerprint.js +55 -0
  102. package/dist/x509/fingerprint.js.map +1 -0
  103. package/dist/x509/name.d.ts +94 -93
  104. package/dist/x509/name.js +30 -29
  105. package/dist/x509/name.js.map +1 -0
  106. package/dist/x509/parse.d.ts +288 -185
  107. package/dist/x509/parse.js +762 -677
  108. package/dist/x509/parse.js.map +1 -0
  109. package/dist/x509.d.ts +3 -2
  110. package/dist/x509.js +7 -6
  111. package/package.json +79 -41
@@ -1,17 +1,17 @@
1
- import { bitString, concatBytes, explicitContext, implicitPrimitiveContext, integer, nullValue, objectIdentifier, octetString, readElement, readRootElement, readSequenceChildren, sequence, time, tlv } from "../internal/asn1/der.js";
2
- import { childrenOf, decodeNonNegativeIntegerNumber, decodeObjectIdentifier, decodeString, extractBitStringValue, hexToBytes, parseTime, requireElement, toArrayBuffer, toHex } from "../internal/asn1/asn1.js";
3
- import { OIDS } from "../internal/asn1/oids.js";
4
- import { getCrypto } from "../internal/crypto/webcrypto.js";
5
- import { base64Encode } from "../internal/shared/base64.js";
6
- import { failureResult, rethrowIfInvariant, successResult } from "../result/result.js";
7
- import { pemDecodeOrThrow, pemEncode } from "../pem/pem.js";
8
- import { describeHashAlgorithm, describeSignatureAlgorithm } from "../internal/crypto/algorithm-names.js";
9
- import { parseCertificateDerOrThrow, parseCertificateFromSource } from "../x509/parse.js";
10
- import { verifySignedDataDetailed } from "../internal/crypto/sig-verify.js";
11
- import { encodeAlgorithmIdentifier, getSignatureAlgorithm, signBytes } from "../internal/crypto/signing.js";
12
- import { compareDistinguishedNames } from "../internal/shared/dn.js";
13
- import { checkCertificateRevocationAgainstCrl, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPemOrThrow } from "./crl.js";
14
- import { verifyCertificateChain } from "../verify/verify.js";
1
+ import { bitString as e, concatBytes as t, explicitContext as n, implicitPrimitiveContext as r, integer as i, nullValue as a, objectIdentifier as o, octetString as s, readElement as c, readRootElement as l, readSequenceChildren as u, sequence as d, time as f, tlv as p } from "../internal/asn1/der.js";
2
+ import { childrenOf as m, decodeNonNegativeIntegerNumber as h, decodeObjectIdentifier as g, decodeString as _, extractBitStringValue as v, hexToBytes as y, parseTime as b, requireElement as x, toArrayBuffer as S, toHex as C } from "../internal/asn1/asn1.js";
3
+ import { OIDS as w } from "../internal/asn1/oids2.js";
4
+ import { getCrypto as T } from "../internal/crypto/webcrypto.js";
5
+ import { base64Encode as E } from "../internal/shared/base64.js";
6
+ import { failureResult as D, rethrowIfInvariant as O, successResult as k } from "../result/result.js";
7
+ import { pemDecodeOrThrow as A, pemEncode as j } from "../pem/pem.js";
8
+ import { describeHashAlgorithm as M, describeSignatureAlgorithm as N } from "../internal/crypto/algorithm-names.js";
9
+ import { parseCertificateDerOrThrow as P, parseCertificateFromSource as F } from "../x509/parse.js";
10
+ import { verifySignedDataDetailed as I } from "../internal/crypto/sig-verify.js";
11
+ import { encodeAlgorithmIdentifier as L, getSignatureAlgorithm as R, signBytes as z } from "../internal/crypto/signing.js";
12
+ import { compareDistinguishedNames as B } from "../internal/shared/dn.js";
13
+ import { checkCertificateRevocationAgainstCrl as V, parseCertificateRevocationListDerOrThrow as H, parseCertificateRevocationListPemOrThrow as U } from "./crl.js";
14
+ import { verifyCertificateChain as W } from "../verify/verify.js";
15
15
  //#region src/revocation/ocsp.ts
16
16
  /**
17
17
  * Full OCSP lifecycle: build requests, create/parse/verify/validate responses.
@@ -38,69 +38,63 @@ import { verifyCertificateChain } from "../verify/verify.js";
38
38
  * // POST req.der to the OCSP responder URI
39
39
  * ```
40
40
  */
41
- async function createOcspRequest(input) {
42
- const hashAlgorithm = input.hashAlgorithm ?? "SHA-1";
43
- const requestEntries = [];
44
- for (const request of input.requests) {
45
- const certificate = await normalizeCertificate(request.certificate);
46
- const issuer = await normalizeCertificate(request.issuerCertificate);
47
- requestEntries.push(sequence([await encodeOcspCertId(certificate, issuer, hashAlgorithm)]));
48
- }
49
- const tbsRequestFields = [sequence(requestEntries)];
50
- if (input.nonce !== void 0) tbsRequestFields.push(explicitContext(2, sequence([sequence([objectIdentifier(OIDS.ocspNonce), octetString(octetString(input.nonce))])])));
51
- const der = sequence([sequence(tbsRequestFields)]);
41
+ async function createOcspRequest(e) {
42
+ let t = e.hashAlgorithm ?? "SHA-1", r = [];
43
+ for (let n of e.requests) {
44
+ let e = normalizeCertificate(n.certificate), i = normalizeCertificate(n.issuerCertificate);
45
+ r.push(d([await encodeOcspCertId(e, i, t)]));
46
+ }
47
+ let i = [d(r)];
48
+ e.nonce !== void 0 && i.push(n(2, d([d([o(w.ocspNonce), s(s(e.nonce))])])));
49
+ let a = d([d(i)]);
52
50
  return {
53
- der,
54
- pem: pemEncode("OCSP REQUEST", der),
55
- base64: base64Encode(der)
51
+ der: a,
52
+ pem: j("OCSP REQUEST", a),
53
+ base64: E(a)
56
54
  };
57
55
  }
58
56
  /** Throwing core for {@linkcode parseOcspRequestDer}. */
59
- function parseOcspRequestDerOrThrow(der) {
60
- const top = readSequenceChildren(der, { maxDepth: 64 });
61
- if (top.length < 1 || top.length > 2) throw new Error("Malformed OCSP request");
62
- const tbsRequest = requireElement(top[0], "tbsRequest");
63
- const optionalSignature = top[1];
64
- if (optionalSignature !== void 0 && optionalSignature.tag !== 160) throw new Error("Malformed OCSP request");
65
- if (optionalSignature !== void 0) validateOcspOptionalSignature(der, optionalSignature);
66
- const tbsChildren = childrenOf(der, tbsRequest);
67
- let cursor = 0;
68
- if (tbsChildren[cursor]?.tag === 160) {
69
- const versionFields = childrenOf(der, requireElement(tbsChildren[cursor], "version"));
70
- const versionElement = requireElement(versionFields[0], "version");
71
- if (versionFields.length !== 1 || versionElement.tag !== 2) throw new Error("version must use INTEGER");
72
- if (decodeNonNegativeIntegerNumber(versionElement.value, "OCSP request version") !== 0) throw new Error("Unsupported OCSP request version");
73
- cursor += 1;
74
- }
75
- const requestorName = tbsChildren[cursor];
76
- if (requestorName?.tag === 161) {
77
- validateOcspRequestorName(der, requestorName);
78
- cursor += 1;
79
- }
80
- const requestList = requireElement(tbsChildren[cursor], "requestList");
81
- if (requestList.tag !== 48) throw new Error("requestList must use SEQUENCE");
82
- if (childrenOf(der, requestList).length === 0) throw new Error("requestList must not be empty");
83
- const requests = childrenOf(der, requestList).map((request) => {
84
- const requestChildren = childrenOf(der, request);
85
- if (requestChildren.length < 1 || requestChildren.length > 2) throw new Error("Malformed OCSP request entry");
86
- if (requestChildren[1] !== void 0 && requestChildren[1].tag !== 160) throw new Error("Malformed OCSP request entry");
87
- const certId = requireElement(requestChildren[0], "reqCert");
88
- return parseOcspCertId(der.slice(certId.start - certId.headerLength, certId.end));
57
+ function parseOcspRequestDerOrThrow(e) {
58
+ let t = u(e, { maxDepth: 64 });
59
+ if (t.length < 1 || t.length > 2) throw Error("Malformed OCSP request");
60
+ let n = x(t[0], "tbsRequest"), r = t[1];
61
+ if (r !== void 0 && r.tag !== 160) throw Error("Malformed OCSP request");
62
+ r !== void 0 && validateOcspOptionalSignature(e, r);
63
+ let i = m(e, n), a = skipOcspRequestVersion(e, i, 0);
64
+ a = skipOcspRequestorName(e, i, a);
65
+ let o = x(i[a], "requestList");
66
+ if (o.tag !== 48) throw Error("requestList must use SEQUENCE");
67
+ if (m(e, o).length === 0) throw Error("requestList must not be empty");
68
+ let s = m(e, o).map((t) => {
69
+ let n = m(e, t);
70
+ if (n.length < 1 || n.length > 2 || n[1] !== void 0 && n[1].tag !== 160) throw Error("Malformed OCSP request entry");
71
+ let r = x(n[0], "reqCert");
72
+ return parseOcspCertId(e.slice(r.start - r.headerLength, r.end));
89
73
  });
90
- cursor += 1;
91
- const extensions = tbsChildren[cursor];
92
- if (extensions !== void 0 && extensions.tag !== 162) throw new Error("Malformed OCSP request");
93
- if (tbsChildren.length !== cursor + (extensions === void 0 ? 0 : 1)) throw new Error("Malformed OCSP request");
94
- const nonce = extensions === void 0 ? void 0 : parseOcspNonceFromExtensions(der, extensions);
74
+ a += 1;
75
+ let c = i[a];
76
+ if (c !== void 0 && c.tag !== 162 || i.length !== a + (c === void 0 ? 0 : 1)) throw Error("Malformed OCSP request");
77
+ let l = c === void 0 ? void 0 : parseOcspNonceFromExtensions(e, c);
95
78
  return {
96
- der: new Uint8Array(der),
97
- requests,
98
- ...nonce === void 0 ? {} : { nonce }
79
+ der: new Uint8Array(e),
80
+ requests: s,
81
+ ...l === void 0 ? {} : { nonce: l }
99
82
  };
100
83
  }
84
+ function skipOcspRequestVersion(e, t, n) {
85
+ if (t[n]?.tag !== 160) return n;
86
+ let r = m(e, x(t[n], "version")), i = x(r[0], "version");
87
+ if (r.length !== 1 || i.tag !== 2) throw Error("version must use INTEGER");
88
+ if (h(i.value, "OCSP request version") !== 0) throw Error("Unsupported OCSP request version");
89
+ return n + 1;
90
+ }
91
+ function skipOcspRequestorName(e, t, n) {
92
+ let r = t[n];
93
+ return r?.tag === 161 ? (validateOcspRequestorName(e, r), n + 1) : n;
94
+ }
101
95
  /** Decodes a PEM-encoded OCSP request (`-----BEGIN OCSP REQUEST-----`). */
102
- function parseOcspRequestPemOrThrow(pem) {
103
- return parseOcspRequestDerOrThrow(pemDecodeOrThrow("OCSP REQUEST", pem));
96
+ function parseOcspRequestPemOrThrow(e) {
97
+ return parseOcspRequestDerOrThrow(A("OCSP REQUEST", e));
104
98
  }
105
99
  /**
106
100
  * Decodes a DER-encoded OCSP request into a structured {@linkcode ParsedOcspRequest}.
@@ -108,12 +102,11 @@ function parseOcspRequestPemOrThrow(pem) {
108
102
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
109
103
  * throwing form use {@linkcode parseOcspRequestDerOrThrow}.
110
104
  */
111
- function parseOcspRequestDer(der) {
105
+ function parseOcspRequestDer(e) {
112
106
  try {
113
- return successResult(parseOcspRequestDerOrThrow(der));
114
- } catch (error) {
115
- rethrowIfInvariant(error);
116
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed OCSP request");
107
+ return k(parseOcspRequestDerOrThrow(e));
108
+ } catch (e) {
109
+ return O(e), D("malformed", e instanceof Error ? e.message : "Malformed OCSP request");
117
110
  }
118
111
  }
119
112
  /**
@@ -122,67 +115,55 @@ function parseOcspRequestDer(der) {
122
115
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
123
116
  * throwing form use {@linkcode parseOcspRequestPemOrThrow}.
124
117
  */
125
- function parseOcspRequestPem(pem) {
118
+ function parseOcspRequestPem(e) {
126
119
  try {
127
- return successResult(parseOcspRequestPemOrThrow(pem));
128
- } catch (error) {
129
- rethrowIfInvariant(error);
130
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed OCSP request");
120
+ return k(parseOcspRequestPemOrThrow(e));
121
+ } catch (e) {
122
+ return O(e), D("malformed", e instanceof Error ? e.message : "Malformed OCSP request");
131
123
  }
132
124
  }
133
125
  /** Throwing core for {@linkcode parseOcspResponseDer}. */
134
- function parseOcspResponseDerOrThrow(der) {
135
- const top = readSequenceChildren(der, { maxDepth: 64 });
136
- if (top.length < 1 || top.length > 2) throw new Error("Malformed OCSP response");
137
- const statusElement = requireElement(top[0], "responseStatus");
138
- if (statusElement.tag !== 10) throw new Error("responseStatus must use ENUMERATED");
139
- const responseStatus = ocspResponseStatusFromCode(decodeNonNegativeIntegerNumber(statusElement.value, "OCSP responseStatus"));
140
- const responseBytes = top[1];
141
- if (responseBytes === void 0) return {
142
- der: new Uint8Array(der),
143
- responseStatus
126
+ function parseOcspResponseDerOrThrow(e) {
127
+ let t = u(e, { maxDepth: 64 });
128
+ if (t.length < 1 || t.length > 2) throw Error("Malformed OCSP response");
129
+ let n = x(t[0], "responseStatus");
130
+ if (n.tag !== 10) throw Error("responseStatus must use ENUMERATED");
131
+ let r = ocspResponseStatusFromCode(h(n.value, "OCSP responseStatus")), i = t[1];
132
+ if (i === void 0) return {
133
+ der: new Uint8Array(e),
134
+ responseStatus: r
144
135
  };
145
- if (responseBytes.tag !== 160) throw new Error("Malformed OCSP response");
146
- const responseBytesWrapper = childrenOf(der, responseBytes);
147
- const bytesSequence = requireElement(responseBytesWrapper[0], "responseBytes");
148
- if (responseBytesWrapper.length !== 1 || bytesSequence.tag !== 48) throw new Error("Malformed OCSP response");
149
- const responseBytesChildren = childrenOf(der, bytesSequence);
150
- if (responseBytesChildren.length !== 2) throw new Error("responseBytes must contain responseType and response");
151
- const responseType = requireElement(responseBytesChildren[0], "responseType");
152
- const response = requireElement(responseBytesChildren[1], "response");
153
- if (response.tag !== 4) throw new Error("response must use OCTET STRING");
154
- const responseTypeOid = decodeObjectIdentifier(responseType.value);
155
- if (responseTypeOid !== OIDS.ocspBasicResponse) return {
156
- der: new Uint8Array(der),
157
- responseStatus,
158
- responseTypeOid
136
+ if (i.tag !== 160) throw Error("Malformed OCSP response");
137
+ let a = m(e, i), o = x(a[0], "responseBytes");
138
+ if (a.length !== 1 || o.tag !== 48) throw Error("Malformed OCSP response");
139
+ let s = m(e, o);
140
+ if (s.length !== 2) throw Error("responseBytes must contain responseType and response");
141
+ let c = x(s[0], "responseType"), l = x(s[1], "response");
142
+ if (l.tag !== 4) throw Error("response must use OCTET STRING");
143
+ let d = g(c.value);
144
+ if (d !== w.ocspBasicResponse) return {
145
+ der: new Uint8Array(e),
146
+ responseStatus: r,
147
+ responseTypeOid: d
159
148
  };
160
- const basicResponse = response.value;
161
- const basicChildren = readSequenceChildren(basicResponse);
162
- if (basicChildren.length < 3 || basicChildren.length > 4) throw new Error("Malformed BasicOCSPResponse");
163
- const responseData = requireElement(basicChildren[0], "responseData");
164
- const signatureAlgorithm = requireElement(basicChildren[1], "signatureAlgorithm");
165
- const signatureValue = requireElement(basicChildren[2], "signatureValue");
166
- const certificatesElement = basicChildren[3];
167
- if (certificatesElement !== void 0 && certificatesElement.tag !== 160) throw new Error("Malformed BasicOCSPResponse");
168
- const signatureAlgorithmChildren = childrenOf(basicResponse, signatureAlgorithm);
169
- const signatureAlgorithmOid = decodeObjectIdentifier(requireElement(signatureAlgorithmChildren[0], "signatureAlgorithm OID").value);
170
- const signatureAlgorithmParameters = signatureAlgorithmChildren[1];
171
- const responseDataDer = basicResponse.slice(responseData.start - responseData.headerLength, responseData.end);
172
- const signedResponseData = parseSignedOcspResponseData(responseDataDer);
149
+ let f = l.value, p = u(f);
150
+ if (p.length < 3 || p.length > 4) throw Error("Malformed BasicOCSPResponse");
151
+ let _ = x(p[0], "responseData"), y = x(p[1], "signatureAlgorithm"), b = x(p[2], "signatureValue"), S = p[3];
152
+ if (S !== void 0 && S.tag !== 160) throw Error("Malformed BasicOCSPResponse");
153
+ let C = m(f, y), T = g(x(C[0], "signatureAlgorithm OID").value), E = C[1], D = f.slice(_.start - _.headerLength, _.end), O = parseSignedOcspResponseData(D);
173
154
  return {
174
- der: new Uint8Array(der),
175
- responseStatus,
176
- responseTypeOid,
177
- responseDataDer,
178
- responderId: signedResponseData.responderId,
179
- signatureAlgorithmOid,
180
- signatureAlgorithmName: describeSignatureAlgorithm(signatureAlgorithmOid, signatureAlgorithmParameters === void 0 ? void 0 : basicResponse.slice(signatureAlgorithmParameters.start - signatureAlgorithmParameters.headerLength, signatureAlgorithmParameters.end)),
181
- signatureValue: extractBitStringValue(signatureValue),
182
- producedAt: signedResponseData.producedAt,
183
- responses: signedResponseData.responses,
184
- ...signedResponseData.nonce === void 0 ? {} : { nonce: signedResponseData.nonce },
185
- ...certificatesElement?.tag === 160 ? { certificates: parseEmbeddedCertificates(basicResponse, certificatesElement) } : {}
155
+ der: new Uint8Array(e),
156
+ responseStatus: r,
157
+ responseTypeOid: d,
158
+ responseDataDer: D,
159
+ responderId: O.responderId,
160
+ signatureAlgorithmOid: T,
161
+ signatureAlgorithmName: N(T, E === void 0 ? void 0 : f.slice(E.start - E.headerLength, E.end)),
162
+ signatureValue: v(b),
163
+ producedAt: O.producedAt,
164
+ responses: O.responses,
165
+ ...O.nonce === void 0 ? {} : { nonce: O.nonce },
166
+ ...S?.tag === 160 ? { certificates: parseEmbeddedCertificates(f, S) } : {}
186
167
  };
187
168
  }
188
169
  /**
@@ -200,8 +181,8 @@ function parseOcspResponseDerOrThrow(der) {
200
181
  * }
201
182
  * ```
202
183
  */
203
- function parseOcspResponsePemOrThrow(pem) {
204
- return parseOcspResponseDerOrThrow(pemDecodeOrThrow("OCSP RESPONSE", pem));
184
+ function parseOcspResponsePemOrThrow(e) {
185
+ return parseOcspResponseDerOrThrow(A("OCSP RESPONSE", e));
205
186
  }
206
187
  /**
207
188
  * Decodes a DER-encoded OCSP response into a structured {@linkcode ParsedOcspResponse}.
@@ -209,12 +190,11 @@ function parseOcspResponsePemOrThrow(pem) {
209
190
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
210
191
  * throwing form use {@linkcode parseOcspResponseDerOrThrow}.
211
192
  */
212
- function parseOcspResponseDer(der) {
193
+ function parseOcspResponseDer(e) {
213
194
  try {
214
- return successResult(parseOcspResponseDerOrThrow(der));
215
- } catch (error) {
216
- rethrowIfInvariant(error);
217
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed OCSP response");
195
+ return k(parseOcspResponseDerOrThrow(e));
196
+ } catch (e) {
197
+ return O(e), D("malformed", e instanceof Error ? e.message : "Malformed OCSP response");
218
198
  }
219
199
  }
220
200
  /**
@@ -223,12 +203,11 @@ function parseOcspResponseDer(der) {
223
203
  * Returns a typed failure (`code: 'malformed'`) on malformed input. For the
224
204
  * throwing form use {@linkcode parseOcspResponsePemOrThrow}.
225
205
  */
226
- function parseOcspResponsePem(pem) {
206
+ function parseOcspResponsePem(e) {
227
207
  try {
228
- return successResult(parseOcspResponsePemOrThrow(pem));
229
- } catch (error) {
230
- rethrowIfInvariant(error);
231
- return failureResult("malformed", error instanceof Error ? error.message : "Malformed OCSP response");
208
+ return k(parseOcspResponsePemOrThrow(e));
209
+ } catch (e) {
210
+ return O(e), D("malformed", e instanceof Error ? e.message : "Malformed OCSP response");
232
211
  }
233
212
  }
234
213
  /**
@@ -258,38 +237,29 @@ function parseOcspResponsePem(pem) {
258
237
  * // resp.der, resp.pem, resp.base64
259
238
  * ```
260
239
  */
261
- async function createOcspResponse(input) {
262
- const signerCertificate = await normalizeCertificate(input.signerCertificate);
263
- const signatureAlgorithm = getSignatureAlgorithm(input.signerPrivateKey);
264
- const producedAt = input.producedAt ?? /* @__PURE__ */ new Date();
265
- const hashAlgorithm = input.hashAlgorithm ?? "SHA-1";
266
- const responses = [];
267
- for (const response of input.responses) {
268
- const certificate = await normalizeCertificate(response.certificate);
269
- const issuer = await normalizeCertificate(response.issuerCertificate);
270
- responses.push(await encodeSingleResponse(certificate, issuer, response, hashAlgorithm));
271
- }
272
- const responseDataFields = [
273
- implicitPrimitiveContext(2, await digestBytes("SHA-1", extractSubjectPublicKeyBytes(signerCertificate.subjectPublicKeyInfoDer))),
274
- time(producedAt),
275
- sequence(responses)
240
+ async function createOcspResponse(i) {
241
+ let a = normalizeCertificate(i.signerCertificate), c = R(i.signerPrivateKey), l = i.producedAt ?? /* @__PURE__ */ new Date(), u = i.hashAlgorithm ?? "SHA-1", m = [];
242
+ for (let e of i.responses) {
243
+ let t = normalizeCertificate(e.certificate), n = normalizeCertificate(e.issuerCertificate);
244
+ m.push(await encodeSingleResponse(t, n, e, u));
245
+ }
246
+ let h = [
247
+ r(2, await digestBytes("SHA-1", extractSubjectPublicKeyBytes(a.subjectPublicKeyInfoDer))),
248
+ f(l),
249
+ d(m)
276
250
  ];
277
- if (input.nonce !== void 0) responseDataFields.push(explicitContext(1, sequence([sequence([objectIdentifier(OIDS.ocspNonce), octetString(octetString(input.nonce))])])));
278
- const responseData = sequence(responseDataFields);
279
- const signature = await signBytes(input.signerPrivateKey, signatureAlgorithm, responseData);
280
- const includedCertificates = input.includedCertificates === void 0 ? [] : await Promise.all(input.includedCertificates.map(normalizeCertificate));
281
- const basicResponseFields = [
282
- responseData,
283
- encodeAlgorithmIdentifier(signatureAlgorithm),
284
- bitString(signature)
251
+ i.nonce !== void 0 && h.push(n(1, d([d([o(w.ocspNonce), s(s(i.nonce))])])));
252
+ let g = d(h), _ = await z(i.signerPrivateKey, c, g), v = i.includedCertificates === void 0 ? [] : await Promise.all(i.includedCertificates.map(normalizeCertificate)), y = [
253
+ g,
254
+ L(c),
255
+ e(_)
285
256
  ];
286
- if (includedCertificates.length > 0) basicResponseFields.push(explicitContext(0, concatBytes(includedCertificates.map((certificate) => certificate.der))));
287
- const basicResponse = sequence(basicResponseFields);
288
- const der = sequence([tlv(10, Uint8Array.of(0)), explicitContext(0, sequence([objectIdentifier(OIDS.ocspBasicResponse), octetString(basicResponse)]))]);
257
+ v.length > 0 && y.push(n(0, t(v.map((e) => e.der))));
258
+ let b = d(y), x = d([p(10, Uint8Array.of(0)), n(0, d([o(w.ocspBasicResponse), s(b)]))]);
289
259
  return {
290
- der,
291
- pem: pemEncode("OCSP RESPONSE", der),
292
- base64: base64Encode(der)
260
+ der: x,
261
+ pem: j("OCSP RESPONSE", x),
262
+ base64: E(x)
293
263
  };
294
264
  }
295
265
  /**
@@ -298,34 +268,30 @@ async function createOcspResponse(input) {
298
268
  * Does **not** check responder binding, freshness, or nonce — use
299
269
  * {@linkcode validateOcspResponse} for full validation.
300
270
  */
301
- async function verifyOcspResponseSignature(response, signerCertificate) {
302
- let parsed;
271
+ async function verifyOcspResponseSignature(e, t) {
272
+ let n;
303
273
  try {
304
- parsed = normalizeOcspResponse(response);
274
+ n = normalizeOcspResponse(e);
305
275
  } catch {
306
276
  return verifyOcspResponseFailureResult("signature_invalid", "OCSP response signed content is malformed");
307
277
  }
308
- if (parsed.responseDataDer === void 0 || parsed.signatureAlgorithmOid === void 0 || parsed.signatureValue === void 0) return verifyOcspResponseFailureResult("signature_invalid", "OCSP response is not signed");
309
- let signer;
278
+ if (n.responseDataDer === void 0 || n.signatureAlgorithmOid === void 0 || n.signatureValue === void 0) return verifyOcspResponseFailureResult("signature_invalid", "OCSP response is not signed");
279
+ let r;
310
280
  try {
311
- signer = await normalizeCertificate(signerCertificate);
281
+ r = normalizeCertificate(t);
312
282
  } catch {
313
283
  return verifyOcspResponseFailureResult("signature_invalid", "OCSP signer certificate input is malformed");
314
284
  }
315
- let verifiedResult;
285
+ let i;
316
286
  try {
317
- verifiedResult = await verifySignedDataDetailed(parsed.signatureAlgorithmOid, void 0, signer.publicKeyAlgorithmOid, signer.publicKeyParametersOid, signer.subjectPublicKeyInfoDer, parsed.signatureValue, parsed.responseDataDer);
287
+ i = await I(n.signatureAlgorithmOid, void 0, r.publicKeyAlgorithmOid, r.publicKeyParametersOid, r.subjectPublicKeyInfoDer, n.signatureValue, n.responseDataDer);
318
288
  } catch {
319
289
  return verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed");
320
290
  }
321
- if (!verifiedResult.ok) {
322
- if (verifiedResult.code === "verification_error") return verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed");
323
- return verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature uses unsupported algorithm parameters");
324
- }
325
- return verifiedResult.valid ? {
326
- ok: true,
327
- value: parsed
328
- } : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature does not verify");
291
+ return i.ok ? i.valid ? {
292
+ ok: !0,
293
+ value: n
294
+ } : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature does not verify") : i.code === "verification_error" ? verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature verification failed") : verifyOcspResponseFailureResult("signature_invalid", "OCSP response signature uses unsupported algorithm parameters");
329
295
  }
330
296
  /**
331
297
  * Full OCSP response validation: response status check, signature verification,
@@ -348,611 +314,588 @@ async function verifyOcspResponseSignature(response, signerCertificate) {
348
314
  * }
349
315
  * ```
350
316
  */
351
- async function validateOcspResponse(input) {
352
- let parsedResponse;
317
+ async function validateOcspResponse(e) {
318
+ let t;
353
319
  try {
354
- parsedResponse = normalizeOcspResponse(input.response);
320
+ t = normalizeOcspResponse(e.response);
355
321
  } catch {
356
322
  return validateOcspResponseFailureResult("signature_invalid", "OCSP response signed content is malformed");
357
323
  }
358
- if (parsedResponse.responseStatus !== "successful") return validateOcspResponseFailureResult("response_status_invalid", `OCSP response status is ${parsedResponse.responseStatus}`);
359
- let issuer;
324
+ if (t.responseStatus !== "successful") return validateOcspResponseFailureResult("response_status_invalid", `OCSP response status is ${t.responseStatus}`);
325
+ let n = await normalizeOcspValidationInput(e, t);
326
+ if (!n.ok) return n;
327
+ let { issuer: r, trustedResponders: i, signer: a } = n, o = await verifyOcspResponseSignature(t, a);
328
+ if (!o.ok) return validateOcspResponseFailureResult(o.code, o.message);
329
+ let s = await validateOcspResponderAuthorization(e, t, r, a, i);
330
+ if (s !== void 0) return s;
331
+ let c = e.at ?? /* @__PURE__ */ new Date(), l = e.clockSkewMs ?? 0, u = await validateOcspResponseFreshness(t, r, c, l);
332
+ if (u !== void 0) return u;
333
+ if (hasDuplicateOcspResponseCertificateSerial(t.responses ?? [])) return validateOcspResponseFailureResult("signature_invalid", "OCSP response contains multiple status entries for the same certificate");
334
+ if (e.request !== void 0) {
335
+ let n = validateOcspRequestCoverage(e.request, t);
336
+ if (n !== void 0) return n;
337
+ }
338
+ return {
339
+ ok: !0,
340
+ value: t
341
+ };
342
+ }
343
+ /** Re-parses OCSP validation certificates and resolves the response signer. */
344
+ async function normalizeOcspValidationInput(e, t) {
345
+ let n;
360
346
  try {
361
- issuer = await normalizeCertificate(input.issuerCertificate);
347
+ n = normalizeCertificate(e.issuerCertificate);
362
348
  } catch {
363
349
  return validateOcspResponseFailureResult("signature_invalid", "issuer certificate input is malformed");
364
350
  }
365
- let resolvedResponder;
366
- let trustedResponders;
367
351
  try {
368
- trustedResponders = (input.trustedOcspResponders ?? []).map(normalizeCertificate);
369
- resolvedResponder = input.responderCertificate ?? await findMatchingOcspResponderCertificate(parsedResponse.certificates, parsedResponse.responderId) ?? await findMatchingOcspResponderCertificate(trustedResponders, parsedResponse.responderId) ?? parsedResponse.certificates?.[0] ?? input.issuerCertificate;
352
+ let r = (e.trustedOcspResponders ?? []).map(normalizeCertificate), i = await resolveOcspResponderCertificate(e, t, r);
353
+ return {
354
+ ok: !0,
355
+ parsedResponse: t,
356
+ issuer: n,
357
+ trustedResponders: r,
358
+ signer: normalizeCertificate(i)
359
+ };
370
360
  } catch {
371
361
  return validateOcspResponseFailureResult("signature_invalid", "OCSP responder certificate input is malformed");
372
362
  }
373
- let signer;
363
+ }
364
+ /** Selects the responder certificate from explicit, embedded, trusted, or issuer inputs. */
365
+ async function resolveOcspResponderCertificate(e, t, n) {
366
+ return e.responderCertificate ?? await findMatchingOcspResponderCertificate(t.certificates, t.responderId) ?? await findMatchingOcspResponderCertificate(n, t.responderId) ?? t.certificates?.[0] ?? e.issuerCertificate;
367
+ }
368
+ async function validateOcspResponderAuthorization(e, t, n, r, i) {
369
+ let a = await safeValidateOcspResponderIdBinding(t, r);
370
+ if (!a.ok) return a;
371
+ let o = i.some((e) => isSameOcspCertificate(r, e));
372
+ if (!(isSameOcspCertificate(r, n) || o)) return await validateDelegatedOcspResponder(e, t, n, r);
373
+ }
374
+ async function safeValidateOcspResponderIdBinding(e, t) {
374
375
  try {
375
- signer = await normalizeCertificate(resolvedResponder);
376
+ return await validateOcspResponderIdBinding(e.responderId, t);
376
377
  } catch {
377
378
  return validateOcspResponseFailureResult("signature_invalid", "OCSP responder certificate input is malformed");
378
379
  }
379
- const signature = await verifyOcspResponseSignature(parsedResponse, signer);
380
- if (!signature.ok) return validateOcspResponseFailureResult(signature.code, signature.message);
381
- let responderBinding;
380
+ }
381
+ async function validateDelegatedOcspResponder(e, t, n, r) {
382
+ let i = e.allowChainedResponderCertificate === !0;
383
+ if (!i && !isDirectlyIssuedByOcspIssuer(r, n)) return validateOcspResponseFailureResult("responder_chain_invalid", "Delegated OCSP responder must be directly issued by issuer certificate");
384
+ if (!(await W({
385
+ leaf: r.der,
386
+ intermediates: i ? buildOcspResponderIntermediates(t.certificates, r, n) : [],
387
+ roots: [n.der],
388
+ ...e.at === void 0 ? {} : { at: e.at }
389
+ })).ok) return validateOcspResponseFailureResult("responder_chain_invalid", "OCSP responder certificate chain does not validate");
390
+ if (r.extendedKeyUsage === void 0 || !r.extendedKeyUsage.includes("ocspSigning")) return validateOcspResponseFailureResult("ocsp_signing_missing", "Delegated OCSP responder lacks ocspSigning EKU");
391
+ let a = await checkDelegatedResponderRevocation(r, n, e);
392
+ return a.ok ? void 0 : a;
393
+ }
394
+ /** Checks response-level and per-certificate OCSP timestamps against the validation time. */
395
+ async function validateOcspResponseFreshness(e, t, n, r) {
396
+ if (e.producedAt !== void 0 && e.producedAt.getTime() - r > n.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response producedAt is later than requested time");
397
+ for (let i of e.responses ?? []) {
398
+ let a = await validateOcspSingleResponseFreshness(i, e.producedAt, t, n, r);
399
+ if (a !== void 0) return a;
400
+ }
401
+ }
402
+ async function validateOcspSingleResponseFreshness(e, t, n, r, i) {
403
+ let a;
382
404
  try {
383
- responderBinding = await validateOcspResponderIdBinding(parsedResponse.responderId, signer);
405
+ a = await buildParsedOcspCertId(e.certId.hashAlgorithmOid, n, e.certId.serialNumberHex);
384
406
  } catch {
385
- return validateOcspResponseFailureResult("signature_invalid", "OCSP responder certificate input is malformed");
407
+ return validateOcspResponseFailureResult("signature_invalid", "OCSP response CertID hash algorithm is unsupported");
386
408
  }
387
- if (!responderBinding.ok) return responderBinding;
388
- const isLocallyTrustedResponder = trustedResponders.some((trusted) => isSameOcspCertificate(signer, trusted));
389
- if (!isSameOcspCertificate(signer, issuer) && !isLocallyTrustedResponder) {
390
- const allowChainedResponderCertificate = input.allowChainedResponderCertificate === true;
391
- if (!allowChainedResponderCertificate && !isDirectlyIssuedByOcspIssuer(signer, issuer)) return validateOcspResponseFailureResult("responder_chain_invalid", "Delegated OCSP responder must be directly issued by issuer certificate");
392
- if (!(await verifyCertificateChain({
393
- leaf: signer.der,
394
- intermediates: allowChainedResponderCertificate ? buildOcspResponderIntermediates(parsedResponse.certificates, signer, issuer) : [],
395
- roots: [issuer.der],
396
- ...input.at !== void 0 ? { at: input.at } : {}
397
- })).ok) return validateOcspResponseFailureResult("responder_chain_invalid", "OCSP responder certificate chain does not validate");
398
- if (signer.extendedKeyUsage === void 0 || !signer.extendedKeyUsage.includes("ocspSigning")) return validateOcspResponseFailureResult("ocsp_signing_missing", "Delegated OCSP responder lacks ocspSigning EKU");
399
- const responderRevocation = await checkDelegatedResponderRevocation(signer, issuer, input);
400
- if (!responderRevocation.ok) return responderRevocation;
401
- }
402
- const at = input.at ?? /* @__PURE__ */ new Date();
403
- const skew = input.clockSkewMs ?? 0;
404
- if (parsedResponse.producedAt !== void 0 && parsedResponse.producedAt.getTime() - skew > at.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response producedAt is later than requested time");
405
- for (const response of parsedResponse.responses ?? []) {
406
- let expected;
407
- try {
408
- expected = await buildParsedOcspCertId(response.certId.hashAlgorithmOid, issuer, response.certId.serialNumberHex);
409
- } catch {
410
- return validateOcspResponseFailureResult("signature_invalid", "OCSP response CertID hash algorithm is unsupported");
411
- }
412
- if (response.certId.issuerNameHashHex !== expected.issuerNameHashHex || response.certId.issuerKeyHashHex !== expected.issuerKeyHashHex) return validateOcspResponseFailureResult("issuer_mismatch", "OCSP response certId does not match issuer certificate");
413
- if (response.thisUpdate.getTime() - skew > at.getTime() || response.nextUpdate !== void 0 && response.nextUpdate.getTime() + skew < at.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response is not valid at requested time");
414
- if (parsedResponse.producedAt !== void 0 && response.nextUpdate !== void 0 && parsedResponse.producedAt.getTime() - skew > response.nextUpdate.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response producedAt is later than nextUpdate");
415
- }
416
- if (hasDuplicateOcspResponseCertificateSerial(parsedResponse.responses ?? [])) return validateOcspResponseFailureResult("signature_invalid", "OCSP response contains multiple status entries for the same certificate");
417
- if (input.request !== void 0) {
418
- let request;
419
- try {
420
- request = normalizeOcspRequest(input.request);
421
- } catch {
422
- return validateOcspResponseFailureResult("request_mismatch", "OCSP request input is malformed");
423
- }
424
- if (request.nonce !== void 0 && request.nonce !== parsedResponse.nonce) return validateOcspResponseFailureResult("nonce_mismatch", "OCSP response nonce does not match request nonce");
425
- const requestIds = new Set(request.requests.map((entry) => serializeCertId(entry)));
426
- const responseIds = new Set((parsedResponse.responses ?? []).map((response) => serializeCertId(response.certId)));
427
- for (const response of parsedResponse.responses ?? []) if (!requestIds.has(serializeCertId(response.certId))) return validateOcspResponseFailureResult("request_mismatch", "OCSP response includes a certId not present in request");
428
- for (const requestId of requestIds) if (!responseIds.has(requestId)) return validateOcspResponseFailureResult("request_mismatch", "OCSP response does not cover every requested certId");
409
+ return e.certId.issuerNameHashHex !== a.issuerNameHashHex || e.certId.issuerKeyHashHex !== a.issuerKeyHashHex ? validateOcspResponseFailureResult("issuer_mismatch", "OCSP response certId does not match issuer certificate") : validateOcspSingleResponseTimes(e, t, r, i);
410
+ }
411
+ function validateOcspSingleResponseTimes(e, t, n, r) {
412
+ if (e.thisUpdate.getTime() - r > n.getTime() || e.nextUpdate !== void 0 && e.nextUpdate.getTime() + r < n.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response is not valid at requested time");
413
+ if (t !== void 0 && e.nextUpdate !== void 0 && t.getTime() - r > e.nextUpdate.getTime()) return validateOcspResponseFailureResult("stale_response", "OCSP response producedAt is later than nextUpdate");
414
+ }
415
+ function validateOcspRequestCoverage(e, t) {
416
+ let n;
417
+ try {
418
+ n = normalizeOcspRequest(e);
419
+ } catch {
420
+ return validateOcspResponseFailureResult("request_mismatch", "OCSP request input is malformed");
429
421
  }
430
- return {
431
- ok: true,
432
- value: parsedResponse
433
- };
422
+ return n.nonce !== void 0 && n.nonce !== t.nonce ? validateOcspResponseFailureResult("nonce_mismatch", "OCSP response nonce does not match request nonce") : validateOcspRequestIdCoverage(new Set(n.requests.map((e) => serializeCertId(e))), new Set((t.responses ?? []).map((e) => serializeCertId(e.certId))), t.responses ?? []);
423
+ }
424
+ function validateOcspRequestIdCoverage(e, t, n) {
425
+ for (let t of n) if (!e.has(serializeCertId(t.certId))) return validateOcspResponseFailureResult("request_mismatch", "OCSP response includes a certId not present in request");
426
+ for (let n of e) if (!t.has(n)) return validateOcspResponseFailureResult("request_mismatch", "OCSP response does not cover every requested certId");
434
427
  }
435
428
  /** Builds a `VerifyOcspResponseSignatureFailureResult`. */
436
- function verifyOcspResponseFailureResult(code, message) {
437
- return failureResult(code, message);
429
+ function verifyOcspResponseFailureResult(e, t) {
430
+ return D(e, t);
438
431
  }
439
432
  /** Builds a `ValidateOcspResponseFailureResult`. */
440
- function validateOcspResponseFailureResult(code, message) {
441
- return failureResult(code, message);
433
+ function validateOcspResponseFailureResult(e, t) {
434
+ return D(e, t);
442
435
  }
443
436
  /**
444
437
  * Reports whether a certificate carries the `id-pkix-ocsp-nocheck` extension
445
438
  * (RFC 6960 §4.2.2.2.1) — the CA's assertion that relying parties may trust
446
439
  * this OCSP responder certificate for its lifetime without revocation checks.
447
440
  */
448
- function hasOcspNoCheckExtension(certificate) {
449
- return normalizeCertificate(certificate).extensions.some((extension) => extension.oid === OIDS.ocspNoCheck);
441
+ function hasOcspNoCheckExtension(e) {
442
+ return normalizeCertificate(e).extensions.some((e) => e.oid === w.ocspNoCheck);
450
443
  }
451
444
  /** Parses a CRL from PEM string, DER bytes, or an already-parsed CRL. */
452
- function parseResponderCrlFromSource(source) {
453
- if (typeof source === "object" && "issuer" in source) return source;
454
- if (typeof source === "string") return parseCertificateRevocationListPemOrThrow(source);
455
- return parseCertificateRevocationListDerOrThrow(source);
445
+ function parseResponderCrlFromSource(e) {
446
+ return typeof e == "object" && "issuer" in e ? e : typeof e == "string" ? U(e) : H(e);
456
447
  }
457
448
  /**
458
449
  * Applies the delegated-responder revocation policy (RFC 6960 §4.2.2.2.1).
459
450
  * See {@linkcode OcspResponderRevocationPolicy} for the policy semantics.
460
451
  */
461
- async function checkDelegatedResponderRevocation(signer, issuer, input) {
462
- const policy = input.responderRevocationPolicy ?? "honor-nocheck";
463
- if (policy === "skip") return { ok: true };
464
- if (policy === "honor-nocheck" && hasOcspNoCheckExtension(signer)) return { ok: true };
465
- const at = input.at ?? /* @__PURE__ */ new Date();
466
- let sawGood = false;
467
- for (const source of input.responderRevocationCrls ?? []) {
468
- let crl;
452
+ async function checkDelegatedResponderRevocation(e, t, n) {
453
+ let r = n.responderRevocationPolicy ?? "honor-nocheck";
454
+ if (r === "skip" || r === "honor-nocheck" && hasOcspNoCheckExtension(e)) return { ok: !0 };
455
+ let i = n.at ?? /* @__PURE__ */ new Date(), a = !1;
456
+ for (let r of n.responderRevocationCrls ?? []) {
457
+ let n;
469
458
  try {
470
- crl = parseResponderCrlFromSource(source);
459
+ n = parseResponderCrlFromSource(r);
471
460
  } catch {
472
461
  continue;
473
462
  }
474
- const result = await checkCertificateRevocationAgainstCrl({
475
- certificate: signer,
476
- issuerCertificate: issuer,
477
- crl,
478
- at
463
+ let o = await V({
464
+ certificate: e,
465
+ issuerCertificate: t,
466
+ crl: n,
467
+ at: i
479
468
  });
480
- if (!result.ok) continue;
481
- if (result.value.status === "revoked") return validateOcspResponseFailureResult("responder_revoked", "Delegated OCSP responder certificate is revoked");
482
- if (result.value.status === "good") sawGood = true;
469
+ if (o.ok) {
470
+ if (o.value.status === "revoked") return validateOcspResponseFailureResult("responder_revoked", "Delegated OCSP responder certificate is revoked");
471
+ o.value.status === "good" && (a = !0);
472
+ }
483
473
  }
484
- if (sawGood || policy === "honor-nocheck") return { ok: true };
485
- return validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder revocation status could not be established");
474
+ return a || r === "honor-nocheck" ? { ok: !0 } : validateOcspResponseFailureResult("responder_revocation_unknown", "Delegated OCSP responder revocation status could not be established");
486
475
  }
487
476
  /** Accepts PEM, DER, or already-parsed OCSP response and returns a parsed response. */
488
- function normalizeOcspResponse(response) {
489
- if (typeof response === "string") return parseOcspResponsePemOrThrow(response);
490
- if (response instanceof Uint8Array) return parseOcspResponseDerOrThrow(response);
491
- if (hasReparseableOcspResponseShape(response)) return parseOcspResponseDerOrThrow(new Uint8Array(response.der));
492
- throw new Error("OCSP response input is malformed");
477
+ function normalizeOcspResponse(e) {
478
+ if (typeof e == "string") return parseOcspResponsePemOrThrow(e);
479
+ if (e instanceof Uint8Array) return parseOcspResponseDerOrThrow(e);
480
+ if (hasReparseableOcspResponseShape(e)) return parseOcspResponseDerOrThrow(new Uint8Array(e.der));
481
+ throw Error("OCSP response input is malformed");
493
482
  }
494
483
  /** Accepts PEM, DER, or already-parsed OCSP request and returns a parsed request. */
495
- function normalizeOcspRequest(request) {
496
- if (typeof request === "string") return parseOcspRequestPemOrThrow(request);
497
- if (request instanceof Uint8Array) return parseOcspRequestDerOrThrow(request);
498
- if (hasReparseableOcspRequestShape(request)) return parseOcspRequestDerOrThrow(new Uint8Array(request.der));
499
- throw new Error("OCSP request input is malformed");
500
- }
501
- function parseSignedOcspResponseData(responseDataDer) {
502
- const responseDataChildren = readSequenceChildren(responseDataDer);
503
- if (responseDataChildren.length < 3 || responseDataChildren.length > 5) throw new Error("Malformed OCSP responseData");
504
- let index = 0;
505
- if (responseDataChildren[index]?.tag === 160) {
506
- const versionFields = childrenOf(responseDataDer, requireElement(responseDataChildren[index], "version"));
507
- const versionElement = requireElement(versionFields[0], "version");
508
- if (versionFields.length !== 1 || versionElement.tag !== 2) throw new Error("version must use INTEGER");
509
- if (decodeNonNegativeIntegerNumber(versionElement.value, "OCSP response version") !== 0) throw new Error("Unsupported OCSP response version");
510
- index += 1;
511
- }
512
- const responderId = parseOcspResponderId(responseDataDer, requireElement(responseDataChildren[index], "responderID"));
513
- index += 1;
514
- const producedAtElement = requireElement(responseDataChildren[index], "producedAt");
515
- const responsesElement = requireElement(responseDataChildren[index + 1], "responses");
516
- if (responsesElement.tag !== 48) throw new Error("responses must use SEQUENCE");
517
- if (childrenOf(responseDataDer, responsesElement).length === 0) throw new Error("responses must not be empty");
518
- const responseExtensions = responseDataChildren[index + 2];
519
- if (responseExtensions !== void 0 && responseExtensions.tag !== 161) throw new Error("Malformed OCSP responseData");
520
- if (responseDataChildren.length !== index + 2 + (responseExtensions === void 0 ? 0 : 1)) throw new Error("Malformed OCSP responseData");
521
- const nonce = responseExtensions === void 0 ? void 0 : parseOcspNonceFromExtensions(responseDataDer, responseExtensions);
522
- const parsedResponses = childrenOf(responseDataDer, responsesElement).map((singleResponse) => parseSingleResponse(responseDataDer, singleResponse));
523
- assertUniqueOcspResponseCertIds(parsedResponses);
524
- return {
525
- responderId,
526
- producedAt: parseTime(producedAtElement),
527
- responses: parsedResponses,
528
- ...nonce === void 0 ? {} : { nonce }
484
+ function normalizeOcspRequest(e) {
485
+ if (typeof e == "string") return parseOcspRequestPemOrThrow(e);
486
+ if (e instanceof Uint8Array) return parseOcspRequestDerOrThrow(e);
487
+ if (hasReparseableOcspRequestShape(e)) return parseOcspRequestDerOrThrow(new Uint8Array(e.der));
488
+ throw Error("OCSP request input is malformed");
489
+ }
490
+ function parseSignedOcspResponseData(e) {
491
+ let t = u(e);
492
+ if (t.length < 3 || t.length > 5) throw Error("Malformed OCSP responseData");
493
+ let n = 0;
494
+ if (t[n]?.tag === 160) {
495
+ let r = m(e, x(t[n], "version")), i = x(r[0], "version");
496
+ if (r.length !== 1 || i.tag !== 2) throw Error("version must use INTEGER");
497
+ if (h(i.value, "OCSP response version") !== 0) throw Error("Unsupported OCSP response version");
498
+ n += 1;
499
+ }
500
+ let r = parseOcspResponderId(e, x(t[n], "responderID"));
501
+ n += 1;
502
+ let i = x(t[n], "producedAt"), a = x(t[n + 1], "responses");
503
+ if (a.tag !== 48) throw Error("responses must use SEQUENCE");
504
+ if (m(e, a).length === 0) throw Error("responses must not be empty");
505
+ let o = t[n + 2];
506
+ if (o !== void 0 && o.tag !== 161 || t.length !== n + 2 + (o === void 0 ? 0 : 1)) throw Error("Malformed OCSP responseData");
507
+ let s = o === void 0 ? void 0 : parseOcspNonceFromExtensions(e, o), c = m(e, a).map((t) => parseSingleResponse(e, t));
508
+ return assertUniqueOcspResponseCertIds(c), {
509
+ responderId: r,
510
+ producedAt: b(i),
511
+ responses: c,
512
+ ...s === void 0 ? {} : { nonce: s }
529
513
  };
530
514
  }
531
515
  /** Searches embedded certificates for one whose subject or key hash matches the responder ID. */
532
- async function findMatchingOcspResponderCertificate(certificates, responderId) {
533
- if (certificates === void 0 || responderId === void 0) return;
534
- for (const certificate of certificates) if (await matchesOcspResponderId(responderId, certificate)) return certificate;
516
+ async function findMatchingOcspResponderCertificate(e, t) {
517
+ if (!(e === void 0 || t === void 0)) {
518
+ for (let n of e) if (await matchesOcspResponderId(t, n)) return n;
519
+ }
535
520
  }
536
521
  /** Verifies that the signer certificate matches the response's responder ID (byName or byKeyHash). */
537
- async function validateOcspResponderIdBinding(responderId, signer) {
538
- if (responderId === void 0) return { ok: true };
539
- if (await matchesOcspResponderId(responderId, signer)) return { ok: true };
540
- return responderId.type === "byName" ? validateOcspResponseFailureResult("responder_id_mismatch", "OCSP responder certificate subject does not match responderID byName") : validateOcspResponseFailureResult("responder_id_mismatch", "OCSP responder certificate public key does not match responderID byKeyHash");
522
+ async function validateOcspResponderIdBinding(e, t) {
523
+ return e === void 0 || await matchesOcspResponderId(e, t) ? { ok: !0 } : e.type === "byName" ? validateOcspResponseFailureResult("responder_id_mismatch", "OCSP responder certificate subject does not match responderID byName") : validateOcspResponseFailureResult("responder_id_mismatch", "OCSP responder certificate public key does not match responderID byKeyHash");
541
524
  }
542
525
  /** Returns `true` if the certificate matches the responder ID (subject name or key hash). */
543
- async function matchesOcspResponderId(responderId, certificate) {
544
- if (responderId.type === "byName") return compareOcspResponderNames(responderId.name, certificate.subject);
545
- return toHex(await digestBytes("SHA-1", extractSubjectPublicKeyBytes(certificate.subjectPublicKeyInfoDer))) === responderId.keyHashHex;
526
+ async function matchesOcspResponderId(e, t) {
527
+ return e.type === "byName" ? compareOcspResponderNames(e.name, t.subject) : C(await digestBytes("SHA-1", extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))) === e.keyHashHex;
546
528
  }
547
529
  /** Identity check — same serial, issuer, subject, and SPKI. */
548
- function isSameOcspCertificate(left, right) {
549
- return left.serialNumberHex === right.serialNumberHex && compareDistinguishedNames(left.issuer, right.issuer) && compareDistinguishedNames(left.subject, right.subject) && left.subjectPublicKeyInfoDer.length === right.subjectPublicKeyInfoDer.length && left.subjectPublicKeyInfoDer.every((byte, index) => byte === right.subjectPublicKeyInfoDer[index]);
530
+ function isSameOcspCertificate(e, t) {
531
+ return e.serialNumberHex === t.serialNumberHex && B(e.issuer, t.issuer) && B(e.subject, t.subject) && e.subjectPublicKeyInfoDer.length === t.subjectPublicKeyInfoDer.length && e.subjectPublicKeyInfoDer.every((e, n) => e === t.subjectPublicKeyInfoDer[n]);
550
532
  }
551
533
  /** Returns `true` if `signer` was directly issued by `issuer` (name + AKI match). */
552
- function isDirectlyIssuedByOcspIssuer(signer, issuer) {
553
- if (!compareDistinguishedNames(signer.issuer, issuer.subject)) return false;
554
- if (signer.authorityKeyIdentifier !== void 0 && issuer.subjectKeyIdentifier !== void 0 && signer.authorityKeyIdentifier !== issuer.subjectKeyIdentifier) return false;
555
- return true;
534
+ function isDirectlyIssuedByOcspIssuer(e, t) {
535
+ return !(!B(e.issuer, t.subject) || e.authorityKeyIdentifier !== void 0 && t.subjectKeyIdentifier !== void 0 && e.authorityKeyIdentifier !== t.subjectKeyIdentifier);
556
536
  }
557
537
  /** Filters embedded certificates to produce an intermediate chain (excluding signer and issuer). */
558
- function buildOcspResponderIntermediates(certificates, signer, issuer) {
559
- if (certificates === void 0) return [];
560
- const intermediates = [];
561
- for (const certificate of certificates) {
562
- if (isSameOcspCertificate(certificate, signer) || isSameOcspCertificate(certificate, issuer)) continue;
563
- intermediates.push(certificate.der);
564
- }
565
- return intermediates;
538
+ function buildOcspResponderIntermediates(e, t, n) {
539
+ if (e === void 0) return [];
540
+ let r = [];
541
+ for (let i of e) isSameOcspCertificate(i, t) || isSameOcspCertificate(i, n) || r.push(i.der);
542
+ return r;
566
543
  }
567
544
  /** DER-encodes a CertID SEQUENCE (hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber). */
568
- async function encodeOcspCertId(certificate, issuer, hashAlgorithm) {
569
- const hashAlgorithmOid = hashAlgorithm === "SHA-1" ? OIDS.sha1 : OIDS.sha256;
570
- const parsed = await buildParsedOcspCertId(hashAlgorithmOid, issuer, certificate.serialNumberHex);
571
- return sequence([
572
- sequence([objectIdentifier(hashAlgorithmOid), nullValue()]),
573
- octetString(hexToBytes(parsed.issuerNameHashHex)),
574
- octetString(hexToBytes(parsed.issuerKeyHashHex)),
575
- integer(hexToBytes(parsed.serialNumberHex))
545
+ async function encodeOcspCertId(e, t, n) {
546
+ let r = n === "SHA-1" ? w.sha1 : w.sha256, c = await buildParsedOcspCertId(r, t, e.serialNumberHex);
547
+ return d([
548
+ d([o(r), a()]),
549
+ s(y(c.issuerNameHashHex)),
550
+ s(y(c.issuerKeyHashHex)),
551
+ i(y(c.serialNumberHex))
576
552
  ]);
577
553
  }
578
554
  /** Computes issuer name/key hashes for a CertID given the hash algorithm OID and issuer certificate. */
579
- async function buildParsedOcspCertId(hashAlgorithmOid, issuer, serialNumberHex) {
580
- const hashAlgorithm = ocspHashAlgorithmFromOid(hashAlgorithmOid);
555
+ async function buildParsedOcspCertId(e, t, n) {
556
+ let r = ocspHashAlgorithmFromOid(e);
581
557
  return {
582
- hashAlgorithmOid,
583
- hashAlgorithmName: describeHashAlgorithm(hashAlgorithmOid),
584
- issuerNameHashHex: toHex(await digestBytes(hashAlgorithm, hexToBytes(issuer.subject.derHex))),
585
- issuerKeyHashHex: toHex(await digestBytes(hashAlgorithm, extractSubjectPublicKeyBytes(issuer.subjectPublicKeyInfoDer))),
586
- serialNumberHex
558
+ hashAlgorithmOid: e,
559
+ hashAlgorithmName: M(e),
560
+ issuerNameHashHex: C(await digestBytes(r, y(t.subject.derHex))),
561
+ issuerKeyHashHex: C(await digestBytes(r, extractSubjectPublicKeyBytes(t.subjectPublicKeyInfoDer))),
562
+ serialNumberHex: n
587
563
  };
588
564
  }
589
565
  /** Hashes `bytes` with the given WebCrypto algorithm name. */
590
- async function digestBytes(algorithm, bytes) {
591
- return new Uint8Array(await getCrypto().subtle.digest(algorithm, toArrayBuffer(bytes)));
566
+ async function digestBytes(e, t) {
567
+ return new Uint8Array(await T().subtle.digest(e, S(t)));
592
568
  }
593
569
  /** DER-encodes a SingleResponse (certId, certStatus, thisUpdate, optional nextUpdate). */
594
- async function encodeSingleResponse(certificate, issuer, input, hashAlgorithm) {
595
- return sequence([
596
- await encodeOcspCertId(certificate, issuer, hashAlgorithm),
597
- encodeOcspCertStatus(input),
598
- time(input.thisUpdate ?? /* @__PURE__ */ new Date()),
599
- ...input.nextUpdate === void 0 ? [] : [explicitContext(0, time(input.nextUpdate))]
570
+ async function encodeSingleResponse(e, t, r, i) {
571
+ return d([
572
+ await encodeOcspCertId(e, t, i),
573
+ encodeOcspCertStatus(r),
574
+ f(r.thisUpdate ?? /* @__PURE__ */ new Date()),
575
+ ...r.nextUpdate === void 0 ? [] : [n(0, f(r.nextUpdate))]
600
576
  ]);
601
577
  }
602
578
  /** DER-encodes the CertStatus CHOICE (good [0], revoked [1], unknown [2]). */
603
- function encodeOcspCertStatus(input) {
604
- switch (input.certStatus) {
605
- case "good": return tlv(128, /* @__PURE__ */ new Uint8Array());
606
- case "unknown": return tlv(130, /* @__PURE__ */ new Uint8Array());
579
+ function encodeOcspCertStatus(e) {
580
+ switch (e.certStatus) {
581
+ case "good": return p(128, /* @__PURE__ */ new Uint8Array());
582
+ case "unknown": return p(130, /* @__PURE__ */ new Uint8Array());
607
583
  case "revoked": {
608
- const revokedFields = [time(input.revokedAt ?? input.thisUpdate ?? /* @__PURE__ */ new Date())];
609
- if (input.revocationReasonCode !== void 0) revokedFields.push(explicitContext(0, tlv(10, Uint8Array.of(input.revocationReasonCode))));
610
- return tlv(161, concatBytes(revokedFields));
584
+ let r = [f(e.revokedAt ?? e.thisUpdate ?? /* @__PURE__ */ new Date())];
585
+ return e.revocationReasonCode !== void 0 && r.push(n(0, p(10, Uint8Array.of(e.revocationReasonCode)))), p(161, t(r));
611
586
  }
612
587
  }
613
588
  }
614
589
  /** Accepts PEM, DER, or already-parsed certificate and returns a parsed certificate. */
615
- function normalizeCertificate(source) {
616
- if (hasParsedCertificateShape(source)) return parseCertificateDerOrThrow(new Uint8Array(source.der));
617
- return parseCertificateFromSource(source);
590
+ function normalizeCertificate(e) {
591
+ return hasParsedCertificateShape(e) ? P(new Uint8Array(e.der)) : F(e);
618
592
  }
619
593
  /** Type guard: distinguishes a `ParsedCertificate` from raw `Uint8Array`. */
620
- function hasParsedCertificateShape(value) {
621
- return typeof value !== "string" && "subjectPublicKeyInfoDer" in value;
594
+ function hasParsedCertificateShape(e) {
595
+ return typeof e != "string" && "subjectPublicKeyInfoDer" in e;
622
596
  }
623
597
  /** Decodes a DER-encoded CertID SEQUENCE into a {@linkcode ParsedOcspCertId}. */
624
- function parseOcspCertId(der) {
625
- const root = readRootElement(der, { maxDepth: 64 });
626
- if (root.tag !== 48) throw new Error("CertID must use SEQUENCE");
627
- const children = childrenOf(der, root);
628
- if (children.length !== 4) throw new Error("CertID must contain hashAlgorithm, issuerNameHash, issuerKeyHash, and serialNumber");
629
- const hashAlgorithm = requireElement(children[0], "hashAlgorithm");
630
- if (hashAlgorithm.tag !== 48) throw new Error("hashAlgorithm must use SEQUENCE");
631
- const algorithmChildren = childrenOf(der, hashAlgorithm);
632
- if (algorithmChildren.length < 1 || algorithmChildren.length > 2) throw new Error("Malformed hashAlgorithm");
633
- const hashAlgorithmOid = decodeObjectIdentifier(requireElement(algorithmChildren[0], "hashAlgorithm OID").value);
634
- if (requireElement(children[1], "issuerNameHash").tag !== 4) throw new Error("issuerNameHash must use OCTET STRING");
635
- if (requireElement(children[2], "issuerKeyHash").tag !== 4) throw new Error("issuerKeyHash must use OCTET STRING");
636
- const serialNumber = requireElement(children[3], "serialNumber");
637
- if (serialNumber.tag !== 2) throw new Error("serialNumber must use INTEGER");
598
+ function parseOcspCertId(e) {
599
+ let t = l(e, { maxDepth: 64 });
600
+ if (t.tag !== 48) throw Error("CertID must use SEQUENCE");
601
+ let n = m(e, t);
602
+ if (n.length !== 4) throw Error("CertID must contain hashAlgorithm, issuerNameHash, issuerKeyHash, and serialNumber");
603
+ let r = x(n[0], "hashAlgorithm");
604
+ if (r.tag !== 48) throw Error("hashAlgorithm must use SEQUENCE");
605
+ let i = m(e, r);
606
+ if (i.length < 1 || i.length > 2) throw Error("Malformed hashAlgorithm");
607
+ let a = g(x(i[0], "hashAlgorithm OID").value);
608
+ if (x(n[1], "issuerNameHash").tag !== 4) throw Error("issuerNameHash must use OCTET STRING");
609
+ if (x(n[2], "issuerKeyHash").tag !== 4) throw Error("issuerKeyHash must use OCTET STRING");
610
+ let o = x(n[3], "serialNumber");
611
+ if (o.tag !== 2) throw Error("serialNumber must use INTEGER");
638
612
  return {
639
- hashAlgorithmOid,
640
- hashAlgorithmName: describeHashAlgorithm(hashAlgorithmOid),
641
- issuerNameHashHex: toHex(requireElement(children[1], "issuerNameHash").value),
642
- issuerKeyHashHex: toHex(requireElement(children[2], "issuerKeyHash").value),
643
- serialNumberHex: toHex(serialNumber.value)
613
+ hashAlgorithmOid: a,
614
+ hashAlgorithmName: M(a),
615
+ issuerNameHashHex: C(x(n[1], "issuerNameHash").value),
616
+ issuerKeyHashHex: C(x(n[2], "issuerKeyHash").value),
617
+ serialNumberHex: C(o.value)
644
618
  };
645
619
  }
646
620
  /** Decodes a SingleResponse from its ASN.1 element within the ResponseData. */
647
- function parseSingleResponse(source, element) {
648
- const children = childrenOf(source, element);
649
- if (children.length < 3 || children.length > 5) throw new Error("Malformed OCSP SingleResponse");
650
- const certId = requireElement(children[0], "certId");
651
- const certStatus = requireElement(children[1], "certStatus");
652
- const thisUpdate = requireElement(children[2], "thisUpdate");
653
- let cursor = 3;
654
- const nextUpdateElement = children[cursor]?.tag === 160 ? children[cursor] : void 0;
655
- if (nextUpdateElement !== void 0) {
656
- validateOcspSingleResponseNextUpdate(source, nextUpdateElement);
657
- cursor += 1;
658
- }
659
- const singleExtensions = children[cursor];
660
- if (singleExtensions !== void 0 && singleExtensions.tag !== 161) throw new Error("Malformed OCSP SingleResponse");
661
- if (children.length !== cursor + (singleExtensions === void 0 ? 0 : 1)) throw new Error("Malformed OCSP SingleResponse");
662
- let revokedAt;
663
- let revocationReasonCode;
664
- if (certStatus.tag === 128) {
665
- if (certStatus.value.length !== 0) throw new Error("OCSP good certStatus must be empty");
666
- return {
667
- certId: parseOcspCertId(source.slice(certId.start - certId.headerLength, certId.end)),
668
- certStatus: "good",
669
- thisUpdate: parseTime(thisUpdate),
670
- ...nextUpdateElement === void 0 ? {} : { nextUpdate: parseTime(requireElement(childrenOf(source, nextUpdateElement)[0], "nextUpdate")) }
671
- };
621
+ function parseSingleResponse(e, t) {
622
+ let n = m(e, t);
623
+ if (n.length < 3 || n.length > 5) throw Error("Malformed OCSP SingleResponse");
624
+ let r = x(n[0], "certId"), i = x(n[1], "certStatus"), a = x(n[2], "thisUpdate"), o = 3, s = n[o]?.tag === 160 ? n[o] : void 0;
625
+ s !== void 0 && (validateOcspSingleResponseNextUpdate(e, s), o += 1);
626
+ let c = n[o];
627
+ if (c !== void 0 && c.tag !== 161 || n.length !== o + (c === void 0 ? 0 : 1)) throw Error("Malformed OCSP SingleResponse");
628
+ let l = parseOcspCertStatusFields(e, i);
629
+ return {
630
+ certId: parseOcspCertId(e.slice(r.start - r.headerLength, r.end)),
631
+ certStatus: l.certStatus,
632
+ thisUpdate: b(a),
633
+ ...parseOcspSingleResponseNextUpdate(e, s),
634
+ ...l.revokedAt === void 0 ? {} : { revokedAt: l.revokedAt },
635
+ ...l.revocationReasonCode === void 0 ? {} : { revocationReasonCode: l.revocationReasonCode }
636
+ };
637
+ }
638
+ function parseOcspSingleResponseNextUpdate(e, t) {
639
+ return t === void 0 ? {} : { nextUpdate: b(x(m(e, t)[0], "nextUpdate")) };
640
+ }
641
+ function parseOcspCertStatusFields(e, t) {
642
+ if (t.tag === 128) {
643
+ if (t.value.length !== 0) throw Error("OCSP good certStatus must be empty");
644
+ return { certStatus: "good" };
672
645
  }
673
- if (certStatus.tag === 161) {
674
- const revokedInfo = childrenOf(source, certStatus);
675
- if (revokedInfo.length < 1 || revokedInfo.length > 2) throw new Error("Malformed OCSP revoked certStatus");
676
- revokedAt = parseTime(requireElement(revokedInfo[0], "revocationTime"));
677
- const reason = revokedInfo[1];
678
- if (reason?.tag === 160) {
679
- const reasonChildren = childrenOf(source, reason);
680
- const enumerated = requireElement(reasonChildren[0], "revocationReason");
681
- if (reasonChildren.length !== 1 || enumerated.tag !== 10) throw new Error("revocationReason must use ENUMERATED");
682
- revocationReasonCode = decodeNonNegativeIntegerNumber(enumerated.value, "OCSP revocationReason");
683
- } else if (reason !== void 0) throw new Error("Malformed OCSP revoked certStatus");
684
- } else if (certStatus.tag !== 130) throw new Error(`Unsupported OCSP certStatus tag: ${String(certStatus.tag)}`);
685
- else if (certStatus.value.length !== 0) throw new Error("OCSP unknown certStatus must be empty");
646
+ if (t.tag === 130) {
647
+ if (t.value.length !== 0) throw Error("OCSP unknown certStatus must be empty");
648
+ return { certStatus: "unknown" };
649
+ }
650
+ if (t.tag !== 161) throw Error(`Unsupported OCSP certStatus tag: ${String(t.tag)}`);
651
+ let n = m(e, t);
652
+ if (n.length < 1 || n.length > 2) throw Error("Malformed OCSP revoked certStatus");
686
653
  return {
687
- certId: parseOcspCertId(source.slice(certId.start - certId.headerLength, certId.end)),
688
- certStatus: certStatus.tag === 130 ? "unknown" : "revoked",
689
- thisUpdate: parseTime(thisUpdate),
690
- ...nextUpdateElement === void 0 ? {} : { nextUpdate: parseTime(requireElement(childrenOf(source, nextUpdateElement)[0], "nextUpdate")) },
691
- ...revokedAt === void 0 ? {} : { revokedAt },
692
- ...revocationReasonCode === void 0 ? {} : { revocationReasonCode }
654
+ certStatus: "revoked",
655
+ revokedAt: b(x(n[0], "revocationTime")),
656
+ ...parseOcspRevocationReason(e, n[1])
693
657
  };
694
658
  }
659
+ function parseOcspRevocationReason(e, t) {
660
+ if (t === void 0) return {};
661
+ if (t.tag !== 160) throw Error("Malformed OCSP revoked certStatus");
662
+ let n = m(e, t), r = x(n[0], "revocationReason");
663
+ if (n.length !== 1 || r.tag !== 10) throw Error("revocationReason must use ENUMERATED");
664
+ return { revocationReasonCode: h(r.value, "OCSP revocationReason") };
665
+ }
695
666
  /** Decodes a ResponderID from its context-tagged ASN.1 element (byName [1] or byKeyHash [2]). */
696
- function parseOcspResponderId(source, element) {
697
- switch (element.tag) {
667
+ function parseOcspResponderId(e, t) {
668
+ switch (t.tag) {
698
669
  case 130:
699
- if (element.value.length === 0) throw new Error("ResponderID byKeyHash must not be empty");
670
+ if (t.value.length === 0) throw Error("ResponderID byKeyHash must not be empty");
700
671
  return {
701
672
  type: "byKeyHash",
702
- keyHashHex: toHex(element.value)
673
+ keyHashHex: C(t.value)
703
674
  };
704
675
  case 161:
705
- if (childrenOf(source, element).length !== 1) throw new Error("ResponderID byName must wrap exactly one Name");
676
+ if (m(e, t).length !== 1) throw Error("ResponderID byName must wrap exactly one Name");
706
677
  return {
707
678
  type: "byName",
708
- name: parseResponderName(source, requireElement(childrenOf(source, element)[0], "ResponderID byName"))
679
+ name: parseResponderName(e, x(m(e, t)[0], "ResponderID byName"))
709
680
  };
710
- default: throw new Error(`Unsupported OCSP responderID tag: ${String(element.tag)}`);
681
+ default: throw Error(`Unsupported OCSP responderID tag: ${String(t.tag)}`);
711
682
  }
712
683
  }
713
684
  /** Decodes a Name SEQUENCE from the ResponderID byName form. */
714
- function parseResponderName(source, element) {
715
- if (element.tag !== 48) throw new Error("ResponderID byName must use Name SEQUENCE");
716
- const rdns = [];
717
- const attributes = [];
718
- const values = {};
719
- for (const setElement of childrenOf(source, element)) {
720
- const rdn = parseResponderNameAttributeSet(source, setElement);
721
- rdns.push(rdn);
722
- for (const attribute of rdn.attributes) {
723
- attributes.push(attribute);
724
- if (attribute.key !== void 0 && values[attribute.key] === void 0) values[attribute.key] = attribute.value;
725
- }
685
+ function parseResponderName(e, t) {
686
+ if (t.tag !== 48) throw Error("ResponderID byName must use Name SEQUENCE");
687
+ let n = [], r = [], i = {};
688
+ for (let a of m(e, t)) {
689
+ let t = parseResponderNameAttributeSet(e, a);
690
+ n.push(t);
691
+ for (let e of t.attributes) r.push(e), e.key !== void 0 && i[e.key] === void 0 && (i[e.key] = e.value);
726
692
  }
727
693
  return {
728
- derHex: toHex(source.slice(element.start - element.headerLength, element.end)),
729
- rdns,
730
- attributes,
731
- values
694
+ derHex: C(e.slice(t.start - t.headerLength, t.end)),
695
+ rdns: n,
696
+ attributes: r,
697
+ values: i
732
698
  };
733
699
  }
734
700
  /** Decodes one RDN SET from a responder name. */
735
- function parseResponderNameAttributeSet(source, setElement) {
736
- const attributes = [];
737
- const values = {};
738
- for (const attributeSequence of childrenOf(source, setElement)) {
739
- const parts = childrenOf(source, attributeSequence);
740
- const oid = decodeObjectIdentifier(requireElement(parts[0], "name OID").value);
741
- const valueElement = requireElement(parts[1], "name value");
742
- const key = responderNameKeyFromOid(oid);
743
- const value = decodeString(valueElement.tag, valueElement.value);
744
- const attribute = key === void 0 ? {
745
- oid,
746
- valueTag: valueElement.tag,
747
- value
701
+ function parseResponderNameAttributeSet(e, t) {
702
+ let n = [], r = {};
703
+ for (let i of m(e, t)) {
704
+ let t = m(e, i), a = g(x(t[0], "name OID").value), o = x(t[1], "name value"), s = responderNameKeyFromOid(a), c = _(o.tag, o.value), l = s === void 0 ? {
705
+ oid: a,
706
+ valueTag: o.tag,
707
+ value: c
748
708
  } : {
749
- oid,
750
- key,
751
- valueTag: valueElement.tag,
752
- value
709
+ oid: a,
710
+ key: s,
711
+ valueTag: o.tag,
712
+ value: c
753
713
  };
754
- attributes.push(attribute);
755
- if (key !== void 0 && values[key] === void 0) values[key] = value;
714
+ n.push(l), s !== void 0 && r[s] === void 0 && (r[s] = c);
756
715
  }
757
716
  return {
758
- derHex: toHex(source.slice(setElement.start - setElement.headerLength, setElement.end)),
759
- attributes,
760
- values
717
+ derHex: C(e.slice(t.start - t.headerLength, t.end)),
718
+ attributes: n,
719
+ values: r
761
720
  };
762
721
  }
763
722
  /** RDN-by-RDN responder name comparison with RFC 4518 string prep. */
764
- function compareOcspResponderNames(left, right) {
765
- if (left.rdns.length !== right.rdns.length) return false;
766
- for (let index = 0; index < left.rdns.length; index += 1) {
767
- const leftRdn = left.rdns[index];
768
- const rightRdn = right.rdns[index];
769
- if (leftRdn === void 0 || rightRdn === void 0) return false;
770
- if (!compareOcspRelativeDistinguishedNames(leftRdn, rightRdn)) return false;
723
+ function compareOcspResponderNames(e, t) {
724
+ if (e.rdns.length !== t.rdns.length) return !1;
725
+ for (let n = 0; n < e.rdns.length; n += 1) {
726
+ let r = e.rdns[n], i = t.rdns[n];
727
+ if (r === void 0 || i === void 0 || !compareOcspRelativeDistinguishedNames(r, i)) return !1;
771
728
  }
772
- return true;
729
+ return !0;
773
730
  }
774
731
  /** Set-equality comparison for RDN attribute sets (order-independent). */
775
- function compareOcspRelativeDistinguishedNames(left, right) {
776
- if (left.attributes.length !== right.attributes.length) return false;
777
- const matched = new Array(right.attributes.length).fill(false);
778
- for (const leftAttribute of left.attributes) {
779
- let found = false;
780
- for (let index = 0; index < right.attributes.length; index += 1) {
781
- const rightAttribute = right.attributes[index];
782
- if (rightAttribute === void 0 || matched[index]) continue;
783
- if (!compareOcspNameAttributeValue(leftAttribute, rightAttribute)) continue;
784
- matched[index] = true;
785
- found = true;
786
- break;
732
+ function compareOcspRelativeDistinguishedNames(e, t) {
733
+ if (e.attributes.length !== t.attributes.length) return !1;
734
+ let n = Array(t.attributes.length).fill(!1);
735
+ for (let r of e.attributes) {
736
+ let e = !1;
737
+ for (let i = 0; i < t.attributes.length; i += 1) {
738
+ let a = t.attributes[i];
739
+ if (!(a === void 0 || n[i]) && compareOcspNameAttributeValue(r, a)) {
740
+ n[i] = !0, e = !0;
741
+ break;
742
+ }
787
743
  }
788
- if (!found) return false;
744
+ if (!e) return !1;
789
745
  }
790
- return true;
746
+ return !0;
791
747
  }
792
748
  /** Compares two name attributes with RFC 4518 string prep for directory-string types. */
793
- function compareOcspNameAttributeValue(left, right) {
794
- if (left.oid !== right.oid) return false;
795
- if (isOcspDirectoryStringTag(left.valueTag) && isOcspDirectoryStringTag(right.valueTag)) {
796
- const preparedLeft = prepareOcspNameCompareString(left.value);
797
- const preparedRight = prepareOcspNameCompareString(right.value);
798
- if (preparedLeft === void 0 || preparedRight === void 0) return false;
799
- return preparedLeft === preparedRight;
749
+ function compareOcspNameAttributeValue(e, t) {
750
+ if (e.oid !== t.oid) return !1;
751
+ if (isOcspDirectoryStringTag(e.valueTag) && isOcspDirectoryStringTag(t.valueTag)) {
752
+ let n = prepareOcspNameCompareString(e.value), r = prepareOcspNameCompareString(t.value);
753
+ return n === void 0 || r === void 0 ? !1 : n === r;
800
754
  }
801
- return left.valueTag === right.valueTag && left.value === right.value;
755
+ return e.valueTag === t.valueTag && e.value === t.value;
802
756
  }
803
757
  /** Returns `true` for UTF8String (0x0c) and PrintableString (0x13). */
804
- function isOcspDirectoryStringTag(tag) {
805
- return tag === 12 || tag === 19;
758
+ function isOcspDirectoryStringTag(e) {
759
+ return e === 12 || e === 19;
806
760
  }
807
761
  /** NFKC-normalises, lowercases, trims, and collapses whitespace for RFC 4518 name comparison. */
808
- function prepareOcspNameCompareString(value) {
809
- const normalized = value.normalize("NFKC");
810
- if (/[^\P{Cc}\t\n\r]/u.test(normalized)) return;
811
- return normalized.toLowerCase().trim().replace(/\s+/gu, " ");
762
+ function prepareOcspNameCompareString(e) {
763
+ let t = e.normalize("NFKC");
764
+ if (!/[^\P{Cc}\t\n\r]/u.test(t)) return t.toLowerCase().trim().replace(/\s+/gu, " ");
812
765
  }
813
766
  /** Maps an X.500 attribute type OID to its friendly key name for responder name parsing. */
814
- function responderNameKeyFromOid(oid) {
815
- switch (oid) {
816
- case OIDS.commonName: return "commonName";
817
- case OIDS.surname: return "surname";
818
- case OIDS.serialNumber: return "serialNumber";
819
- case OIDS.countryName: return "country";
820
- case OIDS.localityName: return "locality";
821
- case OIDS.stateOrProvinceName: return "state";
822
- case OIDS.streetAddress: return "street";
823
- case OIDS.organizationName: return "organization";
824
- case OIDS.organizationalUnitName: return "organizationalUnit";
825
- case OIDS.title: return "title";
826
- case OIDS.givenName: return "givenName";
827
- case OIDS.emailAddress: return "emailAddress";
767
+ function responderNameKeyFromOid(e) {
768
+ switch (e) {
769
+ case w.commonName: return "commonName";
770
+ case w.surname: return "surname";
771
+ case w.serialNumber: return "serialNumber";
772
+ case w.countryName: return "country";
773
+ case w.localityName: return "locality";
774
+ case w.stateOrProvinceName: return "state";
775
+ case w.streetAddress: return "street";
776
+ case w.organizationName: return "organization";
777
+ case w.organizationalUnitName: return "organizationalUnit";
778
+ case w.title: return "title";
779
+ case w.givenName: return "givenName";
780
+ case w.emailAddress: return "emailAddress";
828
781
  default: return;
829
782
  }
830
783
  }
831
784
  /** Extracts the nonce value (as hex) from an OCSP extensions wrapper, if present. */
832
- function parseOcspNonceFromExtensions(source, element) {
833
- const extensionsChildren = childrenOf(source, element);
834
- const extensionsSequence = requireElement(extensionsChildren[0], "extensions");
835
- if (extensionsChildren.length !== 1 || extensionsSequence.tag !== 48) throw new Error("Malformed OCSP extensions");
836
- const seenOids = /* @__PURE__ */ new Set();
837
- let nonce;
838
- for (const extension of childrenOf(source, extensionsSequence)) {
839
- const parts = childrenOf(source, extension);
840
- if (parts.length < 2 || parts.length > 3) throw new Error("Malformed OCSP extension");
841
- if (parts.length === 3 && parts[1]?.tag !== 1) throw new Error("Malformed OCSP extension");
842
- const oid = decodeObjectIdentifier(requireElement(parts[0], "extension OID").value);
843
- if (seenOids.has(oid)) throw new Error(`Duplicate OCSP extension OID: ${oid}`);
844
- seenOids.add(oid);
845
- const extnValue = requireElement(parts[parts.length - 1], "extnValue");
846
- if (extnValue.tag !== 4) throw new Error("OCSP extension value must use OCTET STRING");
847
- if (oid !== OIDS.ocspNonce) continue;
848
- const nonceElement = readRootElement(extnValue.value, { maxDepth: 64 });
849
- if (nonceElement.tag !== 4) throw new Error("OCSP nonce extension value must use OCTET STRING");
850
- nonce = toHex(nonceElement.value);
851
- }
852
- return nonce;
785
+ function parseOcspNonceFromExtensions(e, t) {
786
+ let n = m(e, t), r = x(n[0], "extensions");
787
+ if (n.length !== 1 || r.tag !== 48) throw Error("Malformed OCSP extensions");
788
+ let i = /* @__PURE__ */ new Set(), a;
789
+ for (let t of m(e, r)) {
790
+ let n = m(e, t);
791
+ if (n.length < 2 || n.length > 3 || n.length === 3 && n[1]?.tag !== 1) throw Error("Malformed OCSP extension");
792
+ let r = g(x(n[0], "extension OID").value);
793
+ if (i.has(r)) throw Error(`Duplicate OCSP extension OID: ${r}`);
794
+ i.add(r);
795
+ let o = x(n[n.length - 1], "extnValue");
796
+ if (o.tag !== 4) throw Error("OCSP extension value must use OCTET STRING");
797
+ if (r !== w.ocspNonce) continue;
798
+ let s = l(o.value, { maxDepth: 64 });
799
+ if (s.tag !== 4) throw Error("OCSP nonce extension value must use OCTET STRING");
800
+ a = C(s.value);
801
+ }
802
+ return a;
853
803
  }
854
804
  /** Decodes the optional `certs [0]` field from a BasicOCSPResponse. */
855
- function parseEmbeddedCertificates(source, element) {
856
- const certificates = [];
857
- let offset = element.start;
858
- while (offset < element.end) {
859
- const child = readElement(source, offset);
860
- certificates.push(parseCertificateDerOrThrow(source.slice(offset, child.end)));
861
- offset = child.end;
805
+ function parseEmbeddedCertificates(e, t) {
806
+ let n = [], r = t.start;
807
+ for (; r < t.end;) {
808
+ let t = c(e, r);
809
+ n.push(P(e.slice(r, t.end))), r = t.end;
862
810
  }
863
- return certificates;
811
+ return n;
864
812
  }
865
813
  /** Extracts the raw public key bytes (without BIT STRING padding byte) from SPKI DER. */
866
- function extractSubjectPublicKeyBytes(spkiDer) {
867
- const bitStringElement = requireElement(childrenOf(spkiDer, readElement(spkiDer))[1], "subjectPublicKey BIT STRING");
868
- if (bitStringElement.tag !== 3) throw new Error("SPKI missing subjectPublicKey BIT STRING");
869
- return bitStringElement.value.slice(1);
814
+ function extractSubjectPublicKeyBytes(e) {
815
+ let t = x(m(e, c(e))[1], "subjectPublicKey BIT STRING");
816
+ if (t.tag !== 3) throw Error("SPKI missing subjectPublicKey BIT STRING");
817
+ return t.value.slice(1);
870
818
  }
871
819
  /** Maps an integer response-status code to its {@linkcode OcspResponseStatus} string. */
872
- function ocspResponseStatusFromCode(code) {
873
- switch (code) {
820
+ function ocspResponseStatusFromCode(e) {
821
+ switch (e) {
874
822
  case 0: return "successful";
875
823
  case 1: return "malformedRequest";
876
824
  case 2: return "internalError";
877
825
  case 3: return "tryLater";
878
826
  case 5: return "sigRequired";
879
827
  case 6: return "unauthorized";
880
- default: throw new Error(`Unsupported OCSP responseStatus value: ${String(code)}`);
881
- }
882
- }
883
- function hasReparseableOcspRequestShape(request) {
884
- return "der" in request && request.der instanceof Uint8Array;
885
- }
886
- function hasReparseableOcspResponseShape(response) {
887
- return "der" in response && response.der instanceof Uint8Array;
888
- }
889
- function assertUniqueOcspResponseCertIds(responses) {
890
- const seen = /* @__PURE__ */ new Set();
891
- for (const response of responses) {
892
- const key = serializeCertId(response.certId);
893
- if (seen.has(key)) throw new Error("Duplicate OCSP response CertID");
894
- seen.add(key);
895
- }
896
- }
897
- function hasDuplicateOcspResponseCertificateSerial(responses) {
898
- const seen = /* @__PURE__ */ new Set();
899
- for (const response of responses) {
900
- const serial = normalizeHex(response.certId.serialNumberHex);
901
- if (seen.has(serial)) return true;
902
- seen.add(serial);
903
- }
904
- return false;
905
- }
906
- function validateOcspRequestorName(source, element) {
907
- const children = childrenOf(source, element);
908
- const requestorName = requireElement(children[0], "requestorName");
909
- if (children.length !== 1 || (requestorName.tag & 192) !== 128) throw new Error("requestorName must wrap exactly one GeneralName");
910
- }
911
- function validateOcspOptionalSignature(source, element) {
912
- const wrapperChildren = childrenOf(source, element);
913
- const signatureSequence = requireElement(wrapperChildren[0], "optionalSignature");
914
- if (wrapperChildren.length !== 1 || signatureSequence.tag !== 48) throw new Error("optionalSignature must wrap exactly one Signature");
915
- const signatureChildren = childrenOf(source, signatureSequence);
916
- if (signatureChildren.length < 2 || signatureChildren.length > 3 || signatureChildren[0]?.tag !== 48 || signatureChildren[2] !== void 0 && signatureChildren[2]?.tag !== 160) throw new Error("Malformed optionalSignature");
917
- const signatureAlgorithm = requireElement(signatureChildren[0], "signatureAlgorithm");
918
- const signatureValue = requireElement(signatureChildren[1], "signature");
919
- const certificates = signatureChildren[2];
920
- validateAlgorithmIdentifierShape(source, signatureAlgorithm, "optionalSignature algorithm");
921
- extractBitStringValue(signatureValue);
922
- if (certificates !== void 0) {
923
- const certificateChildren = childrenOf(source, certificates);
924
- if (certificateChildren.length !== 1 || certificateChildren[0]?.tag !== 48) throw new Error("optionalSignature certs must use SEQUENCE OF Certificate");
925
- }
926
- }
927
- function validateOcspSingleResponseNextUpdate(source, element) {
928
- const children = childrenOf(source, element);
929
- const nextUpdate = requireElement(children[0], "nextUpdate");
930
- if (children.length !== 1 || nextUpdate.tag !== 23 && nextUpdate.tag !== 24) throw new Error("nextUpdate must wrap exactly one time value");
931
- }
932
- function validateAlgorithmIdentifierShape(source, element, label) {
933
- const children = childrenOf(source, element);
934
- if (element.tag !== 48 || children.length < 1 || children.length > 2 || children[0]?.tag !== 6) throw new Error(`${label} must use AlgorithmIdentifier SEQUENCE`);
935
- decodeObjectIdentifier(requireElement(children[0], `${label} OID`).value);
936
- }
937
- function normalizeHex(value) {
938
- return value.toLowerCase();
828
+ default: throw Error(`Unsupported OCSP responseStatus value: ${String(e)}`);
829
+ }
830
+ }
831
+ function hasReparseableOcspRequestShape(e) {
832
+ return "der" in e && e.der instanceof Uint8Array;
833
+ }
834
+ function hasReparseableOcspResponseShape(e) {
835
+ return "der" in e && e.der instanceof Uint8Array;
836
+ }
837
+ function assertUniqueOcspResponseCertIds(e) {
838
+ let t = /* @__PURE__ */ new Set();
839
+ for (let n of e) {
840
+ let e = serializeCertId(n.certId);
841
+ if (t.has(e)) throw Error("Duplicate OCSP response CertID");
842
+ t.add(e);
843
+ }
844
+ }
845
+ function hasDuplicateOcspResponseCertificateSerial(e) {
846
+ let t = /* @__PURE__ */ new Set();
847
+ for (let n of e) {
848
+ let e = normalizeHex(n.certId.serialNumberHex);
849
+ if (t.has(e)) return !0;
850
+ t.add(e);
851
+ }
852
+ return !1;
853
+ }
854
+ function validateOcspRequestorName(e, t) {
855
+ let n = m(e, t), r = x(n[0], "requestorName");
856
+ if (n.length !== 1 || (r.tag & 192) != 128) throw Error("requestorName must wrap exactly one GeneralName");
857
+ }
858
+ function validateOcspOptionalSignature(e, t) {
859
+ let n = m(e, t), r = x(n[0], "optionalSignature");
860
+ if (n.length !== 1 || r.tag !== 48) throw Error("optionalSignature must wrap exactly one Signature");
861
+ let i = m(e, r);
862
+ if (i.length < 2 || i.length > 3 || i[0]?.tag !== 48 || i[2] !== void 0 && i[2]?.tag !== 160) throw Error("Malformed optionalSignature");
863
+ let a = x(i[0], "signatureAlgorithm"), o = x(i[1], "signature"), s = i[2];
864
+ if (validateAlgorithmIdentifierShape(e, a, "optionalSignature algorithm"), v(o), s !== void 0) {
865
+ let t = m(e, s);
866
+ if (t.length !== 1 || t[0]?.tag !== 48) throw Error("optionalSignature certs must use SEQUENCE OF Certificate");
867
+ }
868
+ }
869
+ function validateOcspSingleResponseNextUpdate(e, t) {
870
+ let n = m(e, t), r = x(n[0], "nextUpdate");
871
+ if (n.length !== 1 || r.tag !== 23 && r.tag !== 24) throw Error("nextUpdate must wrap exactly one time value");
872
+ }
873
+ function validateAlgorithmIdentifierShape(e, t, n) {
874
+ let r = m(e, t);
875
+ if (t.tag !== 48 || r.length < 1 || r.length > 2 || r[0]?.tag !== 6) throw Error(`${n} must use AlgorithmIdentifier SEQUENCE`);
876
+ g(x(r[0], `${n} OID`).value);
877
+ }
878
+ function normalizeHex(e) {
879
+ return e.toLowerCase();
939
880
  }
940
881
  /** Maps a hash algorithm OID to the WebCrypto algorithm name. Throws on unsupported OIDs. */
941
- function ocspHashAlgorithmFromOid(oid) {
942
- switch (oid) {
943
- case OIDS.sha1: return "SHA-1";
944
- case OIDS.sha256: return "SHA-256";
945
- default: throw new Error(`Unsupported OCSP hash algorithm OID: ${oid}`);
882
+ function ocspHashAlgorithmFromOid(e) {
883
+ switch (e) {
884
+ case w.sha1: return "SHA-1";
885
+ case w.sha256: return "SHA-256";
886
+ default: throw Error(`Unsupported OCSP hash algorithm OID: ${e}`);
946
887
  }
947
888
  }
948
889
  /** Produces a colon-delimited canonical string for CertID set comparison. */
949
- function serializeCertId(certId) {
890
+ function serializeCertId(e) {
950
891
  return [
951
- certId.hashAlgorithmOid,
952
- certId.issuerNameHashHex,
953
- certId.issuerKeyHashHex,
954
- certId.serialNumberHex
892
+ e.hashAlgorithmOid,
893
+ e.issuerNameHashHex,
894
+ e.issuerKeyHashHex,
895
+ e.serialNumberHex
955
896
  ].join(":");
956
897
  }
957
898
  //#endregion
958
899
  export { createOcspRequest, createOcspResponse, hasOcspNoCheckExtension, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, validateOcspResponse, verifyOcspResponseSignature };
900
+
901
+ //# sourceMappingURL=ocsp.js.map