micro509 0.11.0 → 0.12.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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset="https://github.com/kjanat/micro509/raw/c5720af044fd9cc8f3c33e3bb91f79e6d5567454/site/assets/icon-light.svg">
3
- <source media="(prefers-color-scheme: light)" srcset="https://github.com/kjanat/micro509/raw/c5720af044fd9cc8f3c33e3bb91f79e6d5567454/site/assets/icon.svg">
4
- <img alt="" src="https://github.com/kjanat/micro509/raw/c5720af044fd9cc8f3c33e3bb91f79e6d5567454/site/assets/icon.svg" width="64" height="64" align="left">
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon-light.svg">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg">
4
+ <img alt="" src="https://github.com/kjanat/micro509/raw/e7e2007bfd7a18f6f247864b14ef60d54ed91dd6/site/assets/icon.svg" width="64" height="64" align="left">
5
5
  </picture>
6
6
 
7
7
  # micro509
@@ -26,6 +26,20 @@ Zero dependencies. Tree-shakeable subpath entrypoints. Pure WebCrypto. Runs ever
26
26
  npm install micro509
27
27
  ```
28
28
 
29
+ In a browser, no build step — it is WebCrypto and nothing else:
30
+
31
+ ```html
32
+ <script type="module">
33
+ import { createSelfSignedCertificate } from 'https://esm.run/micro509';
34
+ </script>
35
+ ```
36
+
37
+ Two runnable examples: [`examples/browser`] is one HTML file you can open, and
38
+ [`examples/vite`] is the same demo with types and a dev server. Both open in StackBlitz.
39
+
40
+ [`examples/browser`]: ./examples/browser/README.md
41
+ [`examples/vite`]: ./examples/vite/README.md
42
+
29
43
  ## Why micro509
30
44
 
31
45
  JavaScript PKI libraries usually force a bad tradeoff:
package/dist/index.d.ts CHANGED
@@ -18,4 +18,5 @@ import { ConstrainedPolicy, PolicyValidationInput, PolicyValidationOutcome } fro
18
18
  import { BuildCandidatePathInput, BuildCandidatePathResult, CandidatePath, CertificateSource, ChainRevocationInput, CsrSource, EkuCheckFailure, EkuCheckPurpose, EkuCheckResult, TrustAnchor, VERIFY_ERROR_CODES, ValidateCandidatePathInput, ValidateCandidatePathResult, ValidateCandidatePathSuccess, ValidateForCaInput, ValidateForCodeSigningInput, ValidateForTlsClientInput, ValidateForTlsServerInput, VerifiedCertificateChain, VerifyCertificateChainInput, VerifyChainFailure, VerifyChainResult, VerifyErrorCode, VerifyFailureDetails, VerifyPurpose, VerifyRequestFailure, VerifyRequestResult, buildCandidatePath, checkExtendedKeyUsage, trustAnchorFromCertificate, validateCandidatePath, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, verifyCertificateChain, verifyCertificateSigningRequest } from "./verify/verify.js";
19
19
  import { CreateCsrInput, CsrMaterial, createCertificateSigningRequest } from "./x509/csr.js";
20
20
  import { CertificateFingerprint, CertificateFingerprintAlgorithm, CertificateFingerprintSource, certificateFingerprint } from "./x509/fingerprint.js";
21
- export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizePemBlocksResult, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateFingerprint, type CertificateFingerprintAlgorithm, type CertificateFingerprintSource, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlErrorCode, type CheckCertificateRevocationAgainstCrlFailure, type CheckCertificateRevocationAgainstCrlFailureDetails, type CheckCertificateRevocationAgainstCrlGoodValue, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationAgainstCrlRevokedValue, type CheckCertificateRevocationAgainstCrlValue, type CheckCertificateRevocationErrorCode, type CheckCertificateRevocationFailureDetails, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckCertificateRevocationValue, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type ConfiguredOcspResponderCertificate, type ConstrainedPolicy, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxErrorCode, type CreatePfxFailure, type CreatePfxInput, type CreatePfxResult, type CreatePkcs7CertBagErrorCode, type CreatePkcs7CertBagFailure, type CreatePkcs7CertBagResult, type CreatePkcs7SignedDataErrorCode, type CreatePkcs7SignedDataFailure, type CreatePkcs7SignedDataInput, type CreatePkcs7SignedDataResult, type CreateSelfSignedCertificateInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DecryptRsaOaepErrorCode, type DecryptRsaOaepFailure, type DecryptRsaOaepResult, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptRsaOaepErrorCode, type EncryptRsaOaepFailure, type EncryptRsaOaepResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchCertificatePrivateKeyErrorCode, type MatchCertificatePrivateKeyFailure, type MatchCertificatePrivateKeyFailureResult, type MatchCertificatePrivateKeyResult, type MatchCertificatePrivateKeySuccess, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, type MatchServiceIdentityFailureDetails, type MatchServiceIdentityFailureResult, type MatchServiceIdentityInput, type MatchServiceIdentityResult, type MatchServiceIdentitySuccess, type Micro509Error, type NameAttribute, type NameConstraintForm, type NameConstraints, type NameFieldKey, type NameInput, type NameObject, type OcspCertStatus, type OcspCertificateSource, type OcspHashAlgorithm, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderRevocationPolicy, type OcspResponderSource, type OcspResponseMaterial, type OcspResponseSource, type OcspResponseStatus, type ParseCertificateErrorCode, type ParseCertificateFailure, type ParseCertificateResult, type ParseCertificateRevocationListErrorCode, type ParseCertificateRevocationListFailure, type ParseCertificateRevocationListResult, type ParseCertificateSigningRequestErrorCode, type ParseCertificateSigningRequestFailure, type ParseCertificateSigningRequestResult, type ParseOcspRequestErrorCode, type ParseOcspRequestFailure, type ParseOcspRequestResult, type ParseOcspResponseErrorCode, type ParseOcspResponseFailure, type ParseOcspResponseResult, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, type ParsePkcs7CertBagResult, type ParsePkcs7ErrorCode, type ParsePkcs7Failure, type ParsePkcs7SignedDataResult, type ParsedBitFlags, type ParsedCertificate, type ParsedCertificateRevocationList, type ParsedCertificateSigningRequest, type ParsedDistributionPoint, type ParsedDistributionPointName, type ParsedExtension, type ParsedIssuingDistributionPoint, type ParsedName, type ParsedNameAttribute, type ParsedNameConstraintForm, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedPfx, type ParsedPfxAttribute, type ParsedPfxBag, type ParsedPfxBagAttributes, type ParsedPkcs12MacData, type ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedPkcs7SignerInfoBase, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type PemBlock, type PemDecodeResult, type PemErrorCode, type PemFailure, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs12MacOptions, type Pkcs7CertBagMaterial, type Pkcs7CertificateSource, type Pkcs7SignedDataMaterial, type Pkcs7Signer, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PolicyValidationOutcome, type PrivateKeyImportInput, type PublicKeyImportInput, REVOCATION_INDETERMINATE_REASONS, REVOCATION_INDETERMINATE_REASON_CODES, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type ResultError, type RevocationCertificateSource, type RevocationCheckGoodValue, type RevocationCheckIndeterminateValue, type RevocationCheckRevokedValue, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateEvidence, type RevocationIndeterminateReason, type RevocationIndeterminateReasonCode, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaOaepOptions, type RsaScheme, type RsaSignatureScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SplitPemBlocksResult, type SrvServiceIdentityInput, type SubjectAltName, type TrustAnchor, type UriServiceIdentityInput, VERIFY_ERROR_CODES, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseErrorCode, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListSignatureFailure, type VerifyCertificateRevocationListSignatureResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseSignatureFailure, type VerifyOcspResponseSignatureResult, type VerifyPkcs7SignedDataErrorCode, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataOptions, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, buildCandidatePath, categorizePemBlocks, categorizePemBlocksOrThrow, certificateFingerprint, certificateMatchesPrivateKey, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBag, createPkcs7SignedData, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, decryptRsaOaep, decryptRsaOaepOrThrow, defineExtensionDecoder, defineExtensionDecoderMap, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, getSubjectPublicKey, getSubjectPublicKeyOrThrow, hasOcspNoCheckExtension, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, isCertificateRevoked, isResultError, matchCertificatePrivateKey, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificatePem, parseCertificatePemOrThrow, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemDecodeOrThrow, pemEncode, resolveOcspResponderCandidates, splitPemBlocks, splitPemBlocksOrThrow, trustAnchorFromCertificate, unwrap, unwrapOr, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationListSignature, verifyCertificateSigningRequest, verifyOcspResponseSignature, verifyPkcs7SignedData };
21
+ import { SubjectAltNameTextOptions, distinguishedNameToString, relativeDistinguishedNameToString, subjectAltNameLabel, subjectAltNameToString } from "./x509/name-text.js";
22
+ export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizePemBlocksResult, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateFingerprint, type CertificateFingerprintAlgorithm, type CertificateFingerprintSource, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlErrorCode, type CheckCertificateRevocationAgainstCrlFailure, type CheckCertificateRevocationAgainstCrlFailureDetails, type CheckCertificateRevocationAgainstCrlGoodValue, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationAgainstCrlRevokedValue, type CheckCertificateRevocationAgainstCrlValue, type CheckCertificateRevocationErrorCode, type CheckCertificateRevocationFailureDetails, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckCertificateRevocationValue, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type ConfiguredOcspResponderCertificate, type ConstrainedPolicy, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxErrorCode, type CreatePfxFailure, type CreatePfxInput, type CreatePfxResult, type CreatePkcs7CertBagErrorCode, type CreatePkcs7CertBagFailure, type CreatePkcs7CertBagResult, type CreatePkcs7SignedDataErrorCode, type CreatePkcs7SignedDataFailure, type CreatePkcs7SignedDataInput, type CreatePkcs7SignedDataResult, type CreateSelfSignedCertificateInput, type CrlApplicabilityFailureReason, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DecryptRsaOaepErrorCode, type DecryptRsaOaepFailure, type DecryptRsaOaepResult, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptRsaOaepErrorCode, type EncryptRsaOaepFailure, type EncryptRsaOaepResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type IssuingDistributionPointBase, type IssuingDistributionPointForAttributeCerts, type IssuingDistributionPointForCaCerts, type IssuingDistributionPointForUserCerts, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchCertificatePrivateKeyErrorCode, type MatchCertificatePrivateKeyFailure, type MatchCertificatePrivateKeyFailureResult, type MatchCertificatePrivateKeyResult, type MatchCertificatePrivateKeySuccess, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, type MatchServiceIdentityFailureDetails, type MatchServiceIdentityFailureResult, type MatchServiceIdentityInput, type MatchServiceIdentityResult, type MatchServiceIdentitySuccess, type Micro509Error, type NameAttribute, type NameConstraintForm, type NameConstraints, type NameFieldKey, type NameInput, type NameObject, type OcspCertStatus, type OcspCertificateSource, type OcspHashAlgorithm, type OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderRevocationPolicy, type OcspResponderSource, type OcspResponseMaterial, type OcspResponseSource, type OcspResponseStatus, type ParseCertificateErrorCode, type ParseCertificateFailure, type ParseCertificateResult, type ParseCertificateRevocationListErrorCode, type ParseCertificateRevocationListFailure, type ParseCertificateRevocationListResult, type ParseCertificateSigningRequestErrorCode, type ParseCertificateSigningRequestFailure, type ParseCertificateSigningRequestResult, type ParseOcspRequestErrorCode, type ParseOcspRequestFailure, type ParseOcspRequestResult, type ParseOcspResponseErrorCode, type ParseOcspResponseFailure, type ParseOcspResponseResult, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, type ParsePkcs7CertBagResult, type ParsePkcs7ErrorCode, type ParsePkcs7Failure, type ParsePkcs7SignedDataResult, type ParsedBitFlags, type ParsedCertificate, type ParsedCertificateRevocationList, type ParsedCertificateSigningRequest, type ParsedDistributionPoint, type ParsedDistributionPointName, type ParsedExtension, type ParsedIssuingDistributionPoint, type ParsedName, type ParsedNameAttribute, type ParsedNameConstraintForm, type ParsedOcspCertId, type ParsedOcspRequest, type ParsedOcspResponderId, type ParsedOcspResponse, type ParsedOcspSingleResponse, type ParsedPfx, type ParsedPfxAttribute, type ParsedPfxBag, type ParsedPfxBagAttributes, type ParsedPkcs12MacData, type ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedPkcs7SignerInfoBase, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type PemBlock, type PemDecodeResult, type PemErrorCode, type PemFailure, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs12MacOptions, type Pkcs7CertBagMaterial, type Pkcs7CertificateSource, type Pkcs7SignedDataMaterial, type Pkcs7Signer, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PolicyValidationOutcome, type PrivateKeyImportInput, type PublicKeyImportInput, REVOCATION_INDETERMINATE_REASONS, REVOCATION_INDETERMINATE_REASON_CODES, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type ResultError, type RevocationCertificateSource, type RevocationCheckGoodValue, type RevocationCheckIndeterminateValue, type RevocationCheckRevokedValue, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateEvidence, type RevocationIndeterminateReason, type RevocationIndeterminateReasonCode, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaOaepOptions, type RsaScheme, type RsaSignatureScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SplitPemBlocksResult, type SrvServiceIdentityInput, type SubjectAltName, type SubjectAltNameTextOptions, type TrustAnchor, type UriServiceIdentityInput, VERIFY_ERROR_CODES, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseErrorCode, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListSignatureFailure, type VerifyCertificateRevocationListSignatureResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseSignatureFailure, type VerifyOcspResponseSignatureResult, type VerifyPkcs7SignedDataErrorCode, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataOptions, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, buildCandidatePath, categorizePemBlocks, categorizePemBlocksOrThrow, certificateFingerprint, certificateMatchesPrivateKey, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBag, createPkcs7SignedData, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, decryptRsaOaep, decryptRsaOaepOrThrow, defineExtensionDecoder, defineExtensionDecoderMap, derivePublicKey, distinguishedNameToString, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, getSubjectPublicKey, getSubjectPublicKeyOrThrow, hasOcspNoCheckExtension, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, isCertificateRevoked, isResultError, matchCertificatePrivateKey, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificateDerOrThrow, parseCertificatePem, parseCertificatePemOrThrow, parseCertificateRevocationListDer, parseCertificateRevocationListDerOrThrow, parseCertificateRevocationListPem, parseCertificateRevocationListPemOrThrow, parseCertificateSigningRequestDer, parseCertificateSigningRequestDerOrThrow, parseCertificateSigningRequestPem, parseCertificateSigningRequestPemOrThrow, parseOcspRequestDer, parseOcspRequestDerOrThrow, parseOcspRequestPem, parseOcspRequestPemOrThrow, parseOcspResponseDer, parseOcspResponseDerOrThrow, parseOcspResponsePem, parseOcspResponsePemOrThrow, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemDecodeOrThrow, pemEncode, relativeDistinguishedNameToString, resolveOcspResponderCandidates, splitPemBlocks, splitPemBlocksOrThrow, subjectAltNameLabel, subjectAltNameToString, trustAnchorFromCertificate, unwrap, unwrapOr, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationListSignature, verifyCertificateSigningRequest, verifyOcspResponseSignature, verifyPkcs7SignedData };
package/dist/index.js CHANGED
@@ -13,4 +13,5 @@ import { REVOCATION_INDETERMINATE_REASON_CODES as xt, checkCertificateRevocation
13
13
  import { createCertificate as Tt, createSelfSignedCertificate as Et } from "./x509/certificate.js";
14
14
  import { createCertificateSigningRequest as Dt } from "./x509/csr.js";
15
15
  import { certificateFingerprint as Ot } from "./x509/fingerprint.js";
16
- export { yt as REVOCATION_INDETERMINATE_REASONS, xt as REVOCATION_INDETERMINATE_REASON_CODES, Ye as VERIFY_ERROR_CODES, Xe as buildCandidatePath, r as categorizePemBlocks, i as categorizePemBlocksOrThrow, Ot as certificateFingerprint, le as certificateMatchesPrivateKey, St as checkCertificateRevocation, Re as checkCertificateRevocationAgainstCrl, bt as checkChainRevocation, Ze as checkExtendedKeyUsage, Tt as createCertificate, ze as createCertificateRevocationList, Dt as createCertificateSigningRequest, ot as createOcspRequest, st as createOcspResponse, Oe as createPfx, je as createPkcs7CertBag, Me as createPkcs7SignedData, Et as createSelfSignedCertificate, ue as decodeExtension, de as decodeExtensionMap, fe as decodeExtensions, u as decryptRsaOaep, d as decryptRsaOaepOrThrow, pe as defineExtensionDecoder, me as defineExtensionDecoderMap, f as derivePublicKey, p as encryptRsaOaep, m as encryptRsaOaepOrThrow, h as exportBinaryBase64, g as exportEncryptedPkcs1Pem, _ as exportEncryptedPkcs8Der, v as exportEncryptedPkcs8Pem, y as exportEncryptedSec1Pem, b as exportPkcs1Der, x as exportPkcs1Pem, S as exportPkcs8Der, C as exportPkcs8Pem, w as exportPrivateJwk, T as exportPublicJwk, E as exportSec1Der, D as exportSec1Pem, O as exportSpkiDer, k as exportSpkiPem, he as findExtension, A as generateKeyPair, Ct as getCertificateOcspResponderUris, ge as getSubjectPublicKey, _e as getSubjectPublicKeyOrThrow, ct as hasOcspNoCheckExtension, j as importEncryptedPkcs1Pem, M as importEncryptedPkcs1PemOrThrow, N as importEncryptedPkcs8Der, P as importEncryptedPkcs8DerOrThrow, F as importEncryptedPkcs8Pem, I as importEncryptedPkcs8PemOrThrow, L as importEncryptedSec1Pem, R as importEncryptedSec1PemOrThrow, z as importPkcs1Der, B as importPkcs1DerOrThrow, V as importPkcs1Pem, H as importPkcs1PemOrThrow, U as importPkcs8Base64, W as importPkcs8Base64OrThrow, G as importPkcs8Der, K as importPkcs8DerOrThrow, q as importPkcs8Pem, J as importPkcs8PemOrThrow, Y as importPrivateJwk, X as importPrivateJwkOrThrow, Z as importPublicJwk, Q as importPublicJwkOrThrow, $ as importSec1Der, ee as importSec1DerOrThrow, te as importSec1Pem, ne as importSec1PemOrThrow, re as importSpkiBase64, ie as importSpkiBase64OrThrow, ae as importSpkiDer, oe as importSpkiDerOrThrow, se as importSpkiPem, ce as importSpkiPemOrThrow, Be as isCertificateRevoked, e as isResultError, ve as matchCertificatePrivateKey, qe as matchCertificateServiceIdentity, Je as matchServiceIdentity, ye as parseCertificateChainPem, be as parseCertificateDer, xe as parseCertificateDerOrThrow, Se as parseCertificatePem, Ce as parseCertificatePemOrThrow, Ve as parseCertificateRevocationListDer, He as parseCertificateRevocationListDerOrThrow, Ue as parseCertificateRevocationListPem, We as parseCertificateRevocationListPemOrThrow, we as parseCertificateSigningRequestDer, Te as parseCertificateSigningRequestDerOrThrow, Ee as parseCertificateSigningRequestPem, De as parseCertificateSigningRequestPemOrThrow, lt as parseOcspRequestDer, ut as parseOcspRequestDerOrThrow, dt as parseOcspRequestPem, ft as parseOcspRequestPemOrThrow, pt as parseOcspResponseDer, mt as parseOcspResponseDerOrThrow, ht as parseOcspResponsePem, gt as parseOcspResponsePemOrThrow, ke as parsePfxDer, Ae as parsePfxPem, Ne as parsePkcs7CertBagDer, Pe as parsePkcs7CertBagPem, Fe as parsePkcs7SignedDataDer, Ie as parsePkcs7SignedDataPem, a as pemDecode, o as pemDecodeOrThrow, s as pemEncode, wt as resolveOcspResponderCandidates, c as splitPemBlocks, l as splitPemBlocksOrThrow, Qe as trustAnchorFromCertificate, t as unwrap, n as unwrapOr, $e as validateCandidatePath, Ge as validateCertificateRevocationList, et as validateForCa, tt as validateForCodeSigning, nt as validateForTlsClient, rt as validateForTlsServer, _t as validateOcspResponse, it as verifyCertificateChain, Ke as verifyCertificateRevocationListSignature, at as verifyCertificateSigningRequest, vt as verifyOcspResponseSignature, Le as verifyPkcs7SignedData };
16
+ import { distinguishedNameToString as kt, relativeDistinguishedNameToString as At, subjectAltNameLabel as jt, subjectAltNameToString as Mt } from "./x509/name-text.js";
17
+ export { yt as REVOCATION_INDETERMINATE_REASONS, xt as REVOCATION_INDETERMINATE_REASON_CODES, Ye as VERIFY_ERROR_CODES, Xe as buildCandidatePath, r as categorizePemBlocks, i as categorizePemBlocksOrThrow, Ot as certificateFingerprint, le as certificateMatchesPrivateKey, St as checkCertificateRevocation, Re as checkCertificateRevocationAgainstCrl, bt as checkChainRevocation, Ze as checkExtendedKeyUsage, Tt as createCertificate, ze as createCertificateRevocationList, Dt as createCertificateSigningRequest, ot as createOcspRequest, st as createOcspResponse, Oe as createPfx, je as createPkcs7CertBag, Me as createPkcs7SignedData, Et as createSelfSignedCertificate, ue as decodeExtension, de as decodeExtensionMap, fe as decodeExtensions, u as decryptRsaOaep, d as decryptRsaOaepOrThrow, pe as defineExtensionDecoder, me as defineExtensionDecoderMap, f as derivePublicKey, kt as distinguishedNameToString, p as encryptRsaOaep, m as encryptRsaOaepOrThrow, h as exportBinaryBase64, g as exportEncryptedPkcs1Pem, _ as exportEncryptedPkcs8Der, v as exportEncryptedPkcs8Pem, y as exportEncryptedSec1Pem, b as exportPkcs1Der, x as exportPkcs1Pem, S as exportPkcs8Der, C as exportPkcs8Pem, w as exportPrivateJwk, T as exportPublicJwk, E as exportSec1Der, D as exportSec1Pem, O as exportSpkiDer, k as exportSpkiPem, he as findExtension, A as generateKeyPair, Ct as getCertificateOcspResponderUris, ge as getSubjectPublicKey, _e as getSubjectPublicKeyOrThrow, ct as hasOcspNoCheckExtension, j as importEncryptedPkcs1Pem, M as importEncryptedPkcs1PemOrThrow, N as importEncryptedPkcs8Der, P as importEncryptedPkcs8DerOrThrow, F as importEncryptedPkcs8Pem, I as importEncryptedPkcs8PemOrThrow, L as importEncryptedSec1Pem, R as importEncryptedSec1PemOrThrow, z as importPkcs1Der, B as importPkcs1DerOrThrow, V as importPkcs1Pem, H as importPkcs1PemOrThrow, U as importPkcs8Base64, W as importPkcs8Base64OrThrow, G as importPkcs8Der, K as importPkcs8DerOrThrow, q as importPkcs8Pem, J as importPkcs8PemOrThrow, Y as importPrivateJwk, X as importPrivateJwkOrThrow, Z as importPublicJwk, Q as importPublicJwkOrThrow, $ as importSec1Der, ee as importSec1DerOrThrow, te as importSec1Pem, ne as importSec1PemOrThrow, re as importSpkiBase64, ie as importSpkiBase64OrThrow, ae as importSpkiDer, oe as importSpkiDerOrThrow, se as importSpkiPem, ce as importSpkiPemOrThrow, Be as isCertificateRevoked, e as isResultError, ve as matchCertificatePrivateKey, qe as matchCertificateServiceIdentity, Je as matchServiceIdentity, ye as parseCertificateChainPem, be as parseCertificateDer, xe as parseCertificateDerOrThrow, Se as parseCertificatePem, Ce as parseCertificatePemOrThrow, Ve as parseCertificateRevocationListDer, He as parseCertificateRevocationListDerOrThrow, Ue as parseCertificateRevocationListPem, We as parseCertificateRevocationListPemOrThrow, we as parseCertificateSigningRequestDer, Te as parseCertificateSigningRequestDerOrThrow, Ee as parseCertificateSigningRequestPem, De as parseCertificateSigningRequestPemOrThrow, lt as parseOcspRequestDer, ut as parseOcspRequestDerOrThrow, dt as parseOcspRequestPem, ft as parseOcspRequestPemOrThrow, pt as parseOcspResponseDer, mt as parseOcspResponseDerOrThrow, ht as parseOcspResponsePem, gt as parseOcspResponsePemOrThrow, ke as parsePfxDer, Ae as parsePfxPem, Ne as parsePkcs7CertBagDer, Pe as parsePkcs7CertBagPem, Fe as parsePkcs7SignedDataDer, Ie as parsePkcs7SignedDataPem, a as pemDecode, o as pemDecodeOrThrow, s as pemEncode, At as relativeDistinguishedNameToString, wt as resolveOcspResponderCandidates, c as splitPemBlocks, l as splitPemBlocksOrThrow, jt as subjectAltNameLabel, Mt as subjectAltNameToString, Qe as trustAnchorFromCertificate, t as unwrap, n as unwrapOr, $e as validateCandidatePath, Ge as validateCertificateRevocationList, et as validateForCa, tt as validateForCodeSigning, nt as validateForTlsClient, rt as validateForTlsServer, _t as validateOcspResponse, it as verifyCertificateChain, Ke as verifyCertificateRevocationListSignature, at as verifyCertificateSigningRequest, vt as verifyOcspResponseSignature, Le as verifyPkcs7SignedData };
@@ -1,6 +1,28 @@
1
1
  //#region src/internal/asn1/oids.json
2
2
  var e = {
3
3
  $schema: "./oids.schema.json",
4
+ ituT: {
5
+ arc: "0",
6
+ children: { data: {
7
+ arc: "9",
8
+ children: { pss: {
9
+ arc: "2342",
10
+ children: { ucl: {
11
+ arc: "19200300",
12
+ children: { pilot: {
13
+ arc: "100",
14
+ children: { pilotAttributeType: {
15
+ arc: "1",
16
+ oids: {
17
+ userId: "1",
18
+ domainComponent: "25"
19
+ }
20
+ } }
21
+ } }
22
+ } }
23
+ } }
24
+ } }
25
+ },
4
26
  iso: {
5
27
  arc: "1",
6
28
  children: {
@@ -29,7 +29,7 @@ function isWithinDirectoryNameSubtree(e, t) {
29
29
  /** Order-independent RDN equality: same attribute count, each pair matched exactly once. */
30
30
  function compareRelativeDistinguishedNames(e, t) {
31
31
  if (e.attributes.length !== t.attributes.length) return !1;
32
- let n = Array(t.attributes.length).fill(!1);
32
+ let n = Array.from({ length: t.attributes.length }, () => !1);
33
33
  for (let r of e.attributes) {
34
34
  let e = !1;
35
35
  for (let i = 0; i < t.attributes.length; i += 1) {
@@ -1 +1 @@
1
- {"version":3,"file":"dn.js","names":[],"sources":["../../../src/internal/shared/dn.ts"],"sourcesContent":["/**\n * RFC 5280 §7.1 distinguished name comparison utilities.\n *\n * Provides semantic DN equality (case-folding, NFKC normalization,\n * whitespace collapse) and a canonical string key for O(1) Map lookups.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-7.1 | RFC 5280 §7.1}. Internationalized Names in Distinguished Names\n * @module\n */\n\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\n\n// Public API\n\n/** RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) semantic equality: same RDN count, each pair matches attribute-by-attribute. */\nexport function compareDistinguishedNames(left: ParsedName, right: ParsedName): boolean {\n\tif (left.rdns.length !== right.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.rdns.length; index += 1) {\n\t\tconst leftRdn = left.rdns[index];\n\t\tconst rightRdn = right.rdns[index];\n\t\tif (leftRdn === undefined || rightRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(leftRdn, rightRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Produces a deterministic string key for a parsed DN, suitable as a Map key.\n * Semantically equal DNs (per RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1)) produce identical keys.\n *\n * Format: RDNs joined by `,`, attributes within each RDN sorted by OID then by prepared value, joined by `+`.\n */\nexport function canonicalDnKey(name: ParsedName): string {\n\treturn name.rdns.map(canonicalRdnKey).join(',');\n}\n\n/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */\nexport function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean {\n\tif (constraint.rdns.length > subject.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < constraint.rdns.length; index += 1) {\n\t\tconst subjectRdn = subject.rdns[index];\n\t\tconst constraintRdn = constraint.rdns[index];\n\t\tif (subjectRdn === undefined || constraintRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(subjectRdn, constraintRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n// RDN / attribute comparison\n\n/** Order-independent RDN equality: same attribute count, each pair matched exactly once. */\nexport function compareRelativeDistinguishedNames(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): boolean {\n\tif (left.attributes.length !== right.attributes.length) {\n\t\treturn false;\n\t}\n\tconst matched = new Array<boolean>(right.attributes.length).fill(false);\n\tfor (const leftAttribute of left.attributes) {\n\t\tlet found = false;\n\t\tfor (let index = 0; index < right.attributes.length; index += 1) {\n\t\t\tconst rightAttribute = right.attributes[index];\n\t\t\tif (rightAttribute === undefined || matched[index]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!compareNameAttributeValue(leftAttribute, rightAttribute)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmatched[index] = true;\n\t\t\tfound = true;\n\t\t\tbreak;\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/** Compares two AttributeTypeAndValue pairs using RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) string-prep for DirectoryString tags. */\nexport function compareNameAttributeValue(\n\tleft: ParsedNameAttribute,\n\tright: ParsedNameAttribute,\n): boolean {\n\tif (left.oid !== right.oid) {\n\t\treturn false;\n\t}\n\tif (isDirectoryStringTag(left.valueTag) && isDirectoryStringTag(right.valueTag)) {\n\t\tconst preparedLeft = prepareNameCompareString(left.value);\n\t\tconst preparedRight = prepareNameCompareString(right.value);\n\t\tif (preparedLeft === undefined || preparedRight === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\treturn preparedLeft === preparedRight;\n\t}\n\treturn left.valueTag === right.valueTag && left.value === right.value;\n}\n\n// Helpers\n\n/** True for UTF8String (0x0C) and PrintableString (0x13) — the DirectoryString types we normalize. */\nexport function isDirectoryStringTag(tag: number): boolean {\n\treturn tag === 0x0c || tag === 0x13;\n}\n\n/** NFKC-normalizes, lowercases, trims, and collapses whitespace for RFC 5280 §7.1 comparison. */\nexport function prepareNameCompareString(value: string): string | undefined {\n\tconst normalized = value.normalize('NFKC');\n\tif (/[^\\P{Cc}\\t\\n\\r]/u.test(normalized)) {\n\t\treturn undefined;\n\t}\n\treturn normalized.toLowerCase().trim().replace(/\\s+/gu, ' ');\n}\n\n/** Canonical string for a single RDN: attributes sorted, values prepared. */\nfunction canonicalRdnKey(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes\n\t\t.map((attr) => {\n\t\t\tconst val = isDirectoryStringTag(attr.valueTag)\n\t\t\t\t? (prepareNameCompareString(attr.value) ?? `[raw:${attr.valueTag}]${attr.value}`)\n\t\t\t\t: `[${String(attr.valueTag)}]${attr.value}`;\n\t\t\treturn `${attr.oid}=${escapeCanonicalDnValue(val)}`;\n\t\t})\n\t\t.sort()\n\t\t.join('+');\n}\n\nfunction escapeCanonicalDnValue(value: string): string {\n\treturn value\n\t\t.replaceAll('\\\\', '\\\\\\\\')\n\t\t.replaceAll(',', '\\\\,')\n\t\t.replaceAll('+', '\\\\+')\n\t\t.replaceAll('=', '\\\\=');\n}\n"],"mappings":";;AAmBA,SAAgB,0BAA0B,GAAkB,GAA4B;CACvF,IAAI,EAAK,KAAK,WAAW,EAAM,KAAK,QACnC,OAAO;CAER,KAAK,IAAI,IAAQ,GAAG,IAA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Q,GAAG;EAChF,IAAM,IAAe,yBAAyB,EAAK,KAAK,GAClD,IAAgB,yBAAyB,EAAM,KAAK;EAI1D,OAHI,MAAiB,KAAA,KAAa,MAAkB,KAAA,IAC5C,KAED,MAAiB;CACzB;CACA,OAAO,EAAK,aAAa,EAAM,YAAY,EAAK,UAAU,EAAM;AACjE;;AAKA,SAAgB,qBAAqB,GAAsB;CAC1D,OAAO,MAAQ,MAAQ,MAAQ;AAChC;;AAGA,SAAgB,yBAAyB,GAAmC;CAC3E,IAAM,IAAa,EAAM,UAAU,MAAM;CACrC,wBAAmB,KAAK,CAAU,GAGtC,OAAO,EAAW,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;AAC5D;;AAGA,SAAS,gBAAgB,GAA8C;CACtE,OAAO,EAAI,WACT,KAAK,MAAS;EACd,IAAM,IAAM,qBAAqB,EAAK,QAAQ,IAC1C,yBAAyB,EAAK,KAAK,KAAK,QAAQ,EAAK,SAAS,GAAG,EAAK,UACvE,IAAI,OAAO,EAAK,QAAQ,EAAE,GAAG,EAAK;EACrC,OAAO,GAAG,EAAK,IAAI,GAAG,uBAAuB,CAAG;CACjD,CAAC,CAAC,CACD,KAAK,CAAC,CACN,KAAK,GAAG;AACX;AAEA,SAAS,uBAAuB,GAAuB;CACtD,OAAO,EACL,WAAW,MAAM,MAAM,CAAC,CACxB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK;AACxB"}
1
+ {"version":3,"file":"dn.js","names":[],"sources":["../../../src/internal/shared/dn.ts"],"sourcesContent":["/**\n * RFC 5280 §7.1 distinguished name comparison utilities.\n *\n * Provides semantic DN equality (case-folding, NFKC normalization,\n * whitespace collapse) and a canonical string key for O(1) Map lookups.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc5280#section-7.1 | RFC 5280 §7.1}. Internationalized Names in Distinguished Names\n * @module\n */\n\nimport type {\n\tParsedName,\n\tParsedNameAttribute,\n\tParsedRelativeDistinguishedName,\n} from '#micro509/x509/parse';\n\n// Public API\n\n/** RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) semantic equality: same RDN count, each pair matches attribute-by-attribute. */\nexport function compareDistinguishedNames(left: ParsedName, right: ParsedName): boolean {\n\tif (left.rdns.length !== right.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < left.rdns.length; index += 1) {\n\t\tconst leftRdn = left.rdns[index];\n\t\tconst rightRdn = right.rdns[index];\n\t\tif (leftRdn === undefined || rightRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(leftRdn, rightRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Produces a deterministic string key for a parsed DN, suitable as a Map key.\n * Semantically equal DNs (per RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1)) produce identical keys.\n *\n * Format: RDNs joined by `,`, attributes within each RDN sorted by OID then by prepared value, joined by `+`.\n */\nexport function canonicalDnKey(name: ParsedName): string {\n\treturn name.rdns.map(canonicalRdnKey).join(',');\n}\n\n/** True when `subject` equals or is subordinate to `constraint` (RDN prefix match). */\nexport function isWithinDirectoryNameSubtree(subject: ParsedName, constraint: ParsedName): boolean {\n\tif (constraint.rdns.length > subject.rdns.length) {\n\t\treturn false;\n\t}\n\tfor (let index = 0; index < constraint.rdns.length; index += 1) {\n\t\tconst subjectRdn = subject.rdns[index];\n\t\tconst constraintRdn = constraint.rdns[index];\n\t\tif (subjectRdn === undefined || constraintRdn === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!compareRelativeDistinguishedNames(subjectRdn, constraintRdn)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n// RDN / attribute comparison\n\n/** Order-independent RDN equality: same attribute count, each pair matched exactly once. */\nexport function compareRelativeDistinguishedNames(\n\tleft: ParsedRelativeDistinguishedName,\n\tright: ParsedRelativeDistinguishedName,\n): boolean {\n\tif (left.attributes.length !== right.attributes.length) {\n\t\treturn false;\n\t}\n\tconst matched = Array.from({ length: right.attributes.length }, () => false);\n\tfor (const leftAttribute of left.attributes) {\n\t\tlet found = false;\n\t\tfor (let index = 0; index < right.attributes.length; index += 1) {\n\t\t\tconst rightAttribute = right.attributes[index];\n\t\t\tif (rightAttribute === undefined || matched[index]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!compareNameAttributeValue(leftAttribute, rightAttribute)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmatched[index] = true;\n\t\t\tfound = true;\n\t\t\tbreak;\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/** Compares two AttributeTypeAndValue pairs using RFC 5280 [§7.1](https://datatracker.ietf.org/doc/html/rfc5280#section-7.1) string-prep for DirectoryString tags. */\nexport function compareNameAttributeValue(\n\tleft: ParsedNameAttribute,\n\tright: ParsedNameAttribute,\n): boolean {\n\tif (left.oid !== right.oid) {\n\t\treturn false;\n\t}\n\tif (isDirectoryStringTag(left.valueTag) && isDirectoryStringTag(right.valueTag)) {\n\t\tconst preparedLeft = prepareNameCompareString(left.value);\n\t\tconst preparedRight = prepareNameCompareString(right.value);\n\t\tif (preparedLeft === undefined || preparedRight === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\treturn preparedLeft === preparedRight;\n\t}\n\treturn left.valueTag === right.valueTag && left.value === right.value;\n}\n\n// Helpers\n\n/** True for UTF8String (0x0C) and PrintableString (0x13) — the DirectoryString types we normalize. */\nexport function isDirectoryStringTag(tag: number): boolean {\n\treturn tag === 0x0c || tag === 0x13;\n}\n\n/** NFKC-normalizes, lowercases, trims, and collapses whitespace for RFC 5280 §7.1 comparison. */\nexport function prepareNameCompareString(value: string): string | undefined {\n\tconst normalized = value.normalize('NFKC');\n\tif (/[^\\P{Cc}\\t\\n\\r]/u.test(normalized)) {\n\t\treturn undefined;\n\t}\n\treturn normalized.toLowerCase().trim().replace(/\\s+/gu, ' ');\n}\n\n/** Canonical string for a single RDN: attributes sorted, values prepared. */\nfunction canonicalRdnKey(rdn: ParsedRelativeDistinguishedName): string {\n\treturn rdn.attributes\n\t\t.map((attr) => {\n\t\t\tconst val = isDirectoryStringTag(attr.valueTag)\n\t\t\t\t? (prepareNameCompareString(attr.value) ?? `[raw:${attr.valueTag}]${attr.value}`)\n\t\t\t\t: `[${String(attr.valueTag)}]${attr.value}`;\n\t\t\treturn `${attr.oid}=${escapeCanonicalDnValue(val)}`;\n\t\t})\n\t\t.sort()\n\t\t.join('+');\n}\n\nfunction escapeCanonicalDnValue(value: string): string {\n\treturn value\n\t\t.replaceAll('\\\\', '\\\\\\\\')\n\t\t.replaceAll(',', '\\\\,')\n\t\t.replaceAll('+', '\\\\+')\n\t\t.replaceAll('=', '\\\\=');\n}\n"],"mappings":";;AAmBA,SAAgB,0BAA0B,GAAkB,GAA4B;CACvF,IAAI,EAAK,KAAK,WAAW,EAAM,KAAK,QACnC,OAAO;CAER,KAAK,IAAI,IAAQ,GAAG,IAAQ,EAAK,KAAK,QAAQ,KAAS,GAAG;EACzD,IAAM,IAAU,EAAK,KAAK,IACpB,IAAW,EAAM,KAAK;EAI5B,IAHI,MAAY,KAAA,KAAa,MAAa,KAAA,KAGtC,CAAC,kCAAkC,GAAS,CAAQ,GACvD,OAAO;CAET;CACA,OAAO;AACR;;;;;;;AAQA,SAAgB,eAAe,GAA0B;CACxD,OAAO,EAAK,KAAK,IAAI,eAAe,CAAC,CAAC,KAAK,GAAG;AAC/C;;AAGA,SAAgB,6BAA6B,GAAqB,GAAiC;CAClG,IAAI,EAAW,KAAK,SAAS,EAAQ,KAAK,QACzC,OAAO;CAER,KAAK,IAAI,IAAQ,GAAG,IAAQ,EAAW,KAAK,QAAQ,KAAS,GAAG;EAC/D,IAAM,IAAa,EAAQ,KAAK,IAC1B,IAAgB,EAAW,KAAK;EAItC,IAHI,M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,IAAM,IAAM,qBAAqB,EAAK,QAAQ,IAC1C,yBAAyB,EAAK,KAAK,KAAK,QAAQ,EAAK,SAAS,GAAG,EAAK,UACvE,IAAI,OAAO,EAAK,QAAQ,EAAE,GAAG,EAAK;EACrC,OAAO,GAAG,EAAK,IAAI,GAAG,uBAAuB,CAAG;CACjD,CAAC,CAAC,CACD,KAAK,CAAC,CACN,KAAK,GAAG;AACX;AAEA,SAAS,uBAAuB,GAAuB;CACtD,OAAO,EACL,WAAW,MAAM,MAAM,CAAC,CACxB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK,CAAC,CACtB,WAAW,KAAK,KAAK;AACxB"}
@@ -283,7 +283,7 @@ function getPolicyGraphNode(e, t) {
283
283
  function prunePolicyGraph(e, t) {
284
284
  for (let n = t; n >= 0; --n) {
285
285
  let t = e.nodesByDepth[n];
286
- if (t !== void 0) for (let n of [...t.keys()]) {
286
+ if (t !== void 0) for (let n of t.keys()) {
287
287
  let r = t.get(n);
288
288
  r === void 0 || r.childKeys.size > 0 || deletePolicyGraphNode(e, n);
289
289
  }
@@ -1 +1 @@
1
- {"version":3,"file":"policy-engine.js","names":[],"sources":["../../../src/internal/verify/policy-engine.ts"],"sourcesContent":["/**\n * Internal RFC 9618 policy-validation engine.\n *\n * Tracks the policy graph and counter state through each certificate in a\n * chain, then derives the {@linkcode PolicyValidationOutcome}.\n *\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { compareDistinguishedNames } from '#micro509/internal/shared/dn';\nimport type { Micro509Error, Result } from '#micro509/result/result';\nimport type {\n\tConstrainedPolicy,\n\tPolicyValidationInput,\n\tPolicyValidationOutcome,\n} from '#micro509/verify/policy';\nimport type { PolicyInformation, PolicyQualifierInfo } from '#micro509/x509/extensions';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\n\n/**\n * Mutable state threaded through each step of the policy-validation walk.\n *\n * Created by {@linkcode createPolicyValidationState}, consumed by\n * {@linkcode evaluatePolicyChain}.\n */\nexport interface PolicyValidationState {\n\t/** Caller-requested acceptable policies, or `'any'`. */\n\treadonly initialPolicySet: readonly string[] | 'any';\n\t/** Remaining certificates before explicit-policy enforcement kicks in. */\n\texplicitPolicy: number;\n\t/** Remaining certificates before policy mappings are disallowed. */\n\tinhibitPolicyMapping: number;\n\t/** Remaining certificates before anyPolicy expansion stops. */\n\tinhibitAnyPolicy: number;\n\t/** The RFC 9618 policy graph; `null` when the graph has been emptied. */\n\tvalidPolicyGraph: PolicyGraph | null;\n}\n\n/** Discriminant codes for policy-validation failures. */\nexport type PolicyValidationFailureCode =\n\t| 'explicit_policy_required'\n\t| 'initial_policy_set_not_satisfied';\n\n/** Diagnostic context for a policy-validation failure. */\nexport interface PolicyValidationFailureDetails {\n\t/** Description of the policies the caller expected. */\n\treadonly expected: string;\n\t/** Comma-joined OIDs (or `\"<none>\"`) that actually survived processing. */\n\treadonly actual: string;\n}\n\n/** A policy-validation failure with structured diagnostic details. */\nexport interface PolicyValidationFailure\n\textends Micro509Error<PolicyValidationFailureCode, PolicyValidationFailureDetails> {}\n\n/** Success with {@linkcode PolicyValidationOutcome}, or a {@linkcode PolicyValidationFailure}. */\nexport type PolicyValidationResult = Result<PolicyValidationOutcome, PolicyValidationFailure>;\n\n/** One node in the RFC 9618 policy graph, keyed by `depth:policyOID`. */\nexport interface PolicyGraphNode {\n\t/** Graph depth (0 = root anyPolicy node). */\n\tdepth: number;\n\t/** The policy OID this node represents at its depth. */\n\tvalidPolicy: string;\n\t/** Policy qualifiers inherited from the certificate that created this node. */\n\tqualifierSet?: readonly PolicyQualifierInfo[];\n\t/** OIDs this node expects to see in the next certificate's policies. */\n\texpectedPolicySet: Set<string>;\n\t/** Keys of parent nodes in the previous depth level. */\n\tparentKeys: Set<string>;\n\t/** Keys of child nodes in the next depth level. */\n\tchildKeys: Set<string>;\n}\n\n/** The full RFC 9618 valid-policy graph, indexed by depth level. */\nexport interface PolicyGraph {\n\t/** Each index `i` holds the nodes at depth `i`, keyed by `\"depth:oid\"`. */\n\tnodesByDepth: Map<string, PolicyGraphNode>[];\n}\n\n/**\n * Initializes mutable policy state from caller options.\n *\n * Counter values default to `chainLength + 1` (effectively disabled) unless\n * the corresponding input flag is `true`.\n */\nexport function createPolicyValidationState(\n\tinput: PolicyValidationInput,\n\tchainLength: number,\n): PolicyValidationState {\n\tconst disabledCounter = chainLength + 1;\n\treturn {\n\t\tinitialPolicySet: input.initialPolicySet ?? 'any',\n\t\texplicitPolicy: input.requireExplicitPolicy === true ? 0 : disabledCounter,\n\t\tinhibitPolicyMapping: input.inhibitPolicyMapping === true ? 0 : disabledCounter,\n\t\tinhibitAnyPolicy: input.inhibitAnyPolicy === true ? 0 : disabledCounter,\n\t\tvalidPolicyGraph: createInitialPolicyGraph(),\n\t};\n}\n\n/**\n * Walks the chain root-to-leaf, updating policy state per certificate,\n * then checks whether the resulting policy set satisfies caller requirements.\n */\nexport function evaluatePolicyChain(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): PolicyValidationResult {\n\tif (chain.length === 0) {\n\t\tthrow new RangeError('policy validation requires at least one certificate');\n\t}\n\tprocessPolicyState(chain, state);\n\tconst outcome = derivePolicyValidationOutcome(chain, state);\n\tif (state.explicitPolicy === 0 && outcome.userConstrainedPolicies.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: {\n\t\t\t\tcode: 'explicit_policy_required',\n\t\t\t\tmessage: 'policy validation requires an explicit permitted policy',\n\t\t\t\tdetails: {\n\t\t\t\t\texpected:\n\t\t\t\t\t\tstate.initialPolicySet === 'any' ? 'explicit policy' : state.initialPolicySet.join(','),\n\t\t\t\t\tactual: describeFinalPolicies(outcome.userConstrainedPolicies),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tif (state.initialPolicySet !== 'any' && outcome.userConstrainedPolicies.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: {\n\t\t\t\tcode: 'initial_policy_set_not_satisfied',\n\t\t\t\tmessage: 'certificate chain does not satisfy the requested initial policy set',\n\t\t\t\tdetails: {\n\t\t\t\t\texpected: state.initialPolicySet.join(','),\n\t\t\t\t\tactual: describeFinalPolicies(outcome.userConstrainedPolicies),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn { ok: true, value: outcome };\n}\n\n/** Builds the depth-0 graph with a single anyPolicy root node. */\nfunction createInitialPolicyGraph(): PolicyGraph {\n\tconst rootNode = createPolicyGraphNode(0, OIDS.anyPolicy, undefined, [OIDS.anyPolicy], []);\n\treturn {\n\t\tnodesByDepth: [new Map([[policyNodeKey(0, OIDS.anyPolicy), rootNode]])],\n\t};\n}\n\n/** Constructs a new {@linkcode PolicyGraphNode} with empty child-key set. */\nfunction createPolicyGraphNode(\n\tdepth: number,\n\tvalidPolicy: string,\n\tqualifierSet: readonly PolicyQualifierInfo[] | undefined,\n\texpectedPolicySet: readonly string[],\n\tparentKeys: readonly string[],\n): PolicyGraphNode {\n\treturn {\n\t\tdepth,\n\t\tvalidPolicy,\n\t\t...(qualifierSet === undefined ? {} : { qualifierSet }),\n\t\texpectedPolicySet: new Set(expectedPolicySet),\n\t\tparentKeys: new Set(parentKeys),\n\t\tchildKeys: new Set<string>(),\n\t};\n}\n\n/** Canonical map key for a graph node: `\"depth:policyOID\"`. */\nfunction policyNodeKey(depth: number, validPolicy: string): string {\n\treturn `${String(depth)}:${validPolicy}`;\n}\n\n/** Iterates root-to-leaf (skipping root), applying each certificate's policies to the state. */\nfunction processPolicyState(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): void {\n\tif (chain.length === 1) {\n\t\tconst certificate = chain[0];\n\t\tif (certificate === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`missing certificate at chain index 0 (chain length ${String(chain.length)})`,\n\t\t\t);\n\t\t}\n\t\tprocessPolicyCertificate(state, certificate, 1, true);\n\t\treturn;\n\t}\n\tconst leafDepth = chain.length - 1;\n\tfor (let index = chain.length - 2; index >= 0; index -= 1) {\n\t\tconst certificate = chain[index];\n\t\tif (certificate === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`missing certificate at chain index ${String(index)} (chain length ${String(chain.length)})`,\n\t\t\t);\n\t\t}\n\t\tconst depth = leafDepth - index;\n\t\tprocessPolicyCertificate(state, certificate, depth, depth === leafDepth);\n\t}\n}\n\n/** Extracts the final authority- and user-constrained policy sets from the completed graph. */\nfunction derivePolicyValidationOutcome(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): PolicyValidationOutcome {\n\tconst authorityConstrainedPolicies = collectAuthorityConstrainedPolicies(\n\t\tchain,\n\t\tstate.validPolicyGraph,\n\t);\n\tconst rootDomainPolicies = collectRootDomainPolicies(chain, state.validPolicyGraph);\n\treturn {\n\t\tauthorityConstrainedPolicies: [...authorityConstrainedPolicies.values()].sort(comparePolicies),\n\t\tuserConstrainedPolicies: deriveUserConstrainedPolicies(\n\t\t\tauthorityConstrainedPolicies,\n\t\t\trootDomainPolicies,\n\t\t\tstate.initialPolicySet,\n\t\t),\n\t};\n}\n\n/** Collects leaf-depth policies whose graph paths trace back to the anyPolicy root. */\nfunction collectAuthorityConstrainedPolicies(\n\tchain: readonly ParsedCertificate[],\n\tgraph: PolicyGraph | null,\n): ReadonlyMap<string, ConstrainedPolicy> {\n\tif (graph === null) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst leafDepth = Math.max(1, chain.length - 1);\n\tconst finalDepth = graph.nodesByDepth[leafDepth];\n\tif (finalDepth === undefined) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst authorityPolicies = new Map<string, ConstrainedPolicy>();\n\tfor (const [key, node] of finalDepth) {\n\t\tif (node.validPolicy === OIDS.anyPolicy) {\n\t\t\tauthorityPolicies.set(\n\t\t\t\tOIDS.anyPolicy,\n\t\t\t\tbuildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (reachesAuthorityRoot(graph, key)) {\n\t\t\tauthorityPolicies.set(\n\t\t\t\tnode.validPolicy,\n\t\t\t\tbuildConstrainedPolicy(node.validPolicy, node.qualifierSet),\n\t\t\t);\n\t\t}\n\t}\n\treturn authorityPolicies;\n}\n\n/** DFS upward through parent links to check if the node ultimately connects to the depth-0 anyPolicy root. */\nfunction reachesAuthorityRoot(graph: PolicyGraph, nodeKey: string): boolean {\n\tconst pending = [nodeKey];\n\tconst visited = new Set<string>();\n\twhile (pending.length > 0) {\n\t\tconst currentKey = pending.pop();\n\t\tif (currentKey === undefined || visited.has(currentKey)) {\n\t\t\tcontinue;\n\t\t}\n\t\tvisited.add(currentKey);\n\t\tconst node = getPolicyGraphNode(graph, currentKey);\n\t\tif (node === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const parentKey of node.parentKeys) {\n\t\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\t\tif (parent === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (parent.depth === 0 && parent.validPolicy === OIDS.anyPolicy) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tpending.push(parentKey);\n\t\t}\n\t}\n\treturn false;\n}\n\n/** Like authority-constrained, but records the OID at the depth-1 node that connects to root. */\nfunction collectRootDomainPolicies(\n\tchain: readonly ParsedCertificate[],\n\tgraph: PolicyGraph | null,\n): ReadonlyMap<string, ConstrainedPolicy> {\n\tif (graph === null) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst leafDepth = Math.max(1, chain.length - 1);\n\tconst finalDepth = graph.nodesByDepth[leafDepth];\n\tif (finalDepth === undefined) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst rootPolicies = new Map<string, ConstrainedPolicy>();\n\tfor (const [key, node] of finalDepth) {\n\t\tif (node.validPolicy === OIDS.anyPolicy) {\n\t\t\trootPolicies.set(OIDS.anyPolicy, buildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet));\n\t\t\tcontinue;\n\t\t}\n\t\tcollectAuthorityConstrainedPolicyRoots(graph, key, rootPolicies);\n\t}\n\treturn rootPolicies;\n}\n\n/** Walks parent links upward, collecting the depth-1 OID that first connects to the root anyPolicy. */\nfunction collectAuthorityConstrainedPolicyRoots(\n\tgraph: PolicyGraph,\n\tnodeKey: string,\n\tauthorityPolicies: Map<string, ConstrainedPolicy>,\n): void {\n\tconst pending = [nodeKey];\n\tconst visited = new Set<string>();\n\twhile (pending.length > 0) {\n\t\tconst currentKey = pending.pop();\n\t\tif (currentKey === undefined || visited.has(currentKey)) {\n\t\t\tcontinue;\n\t\t}\n\t\tvisited.add(currentKey);\n\t\tconst node = getPolicyGraphNode(graph, currentKey);\n\t\tif (node === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const parentKey of node.parentKeys) {\n\t\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\t\tif (parent === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (parent.depth === 0 && parent.validPolicy === OIDS.anyPolicy) {\n\t\t\t\t// Record the depth-1 policy that connects to root\n\t\t\t\t// If the depth-1 node is anyPolicy itself, record anyPolicy so it can satisfy\n\t\t\t\t// any policy in the initial-policy-set via deriveUserConstrainedPolicies\n\t\t\t\tauthorityPolicies.set(\n\t\t\t\t\tnode.validPolicy,\n\t\t\t\t\tbuildConstrainedPolicy(\n\t\t\t\t\t\tnode.validPolicy,\n\t\t\t\t\t\tcurrentKey === nodeKey ? node.qualifierSet : undefined,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tpending.push(parentKey);\n\t\t}\n\t}\n}\n\n/** Intersects root-domain policies with the caller's initial-policy-set. */\nfunction deriveUserConstrainedPolicies(\n\tfinalAuthorityConstrainedPolicies: ReadonlyMap<string, ConstrainedPolicy>,\n\trootDomainPolicies: ReadonlyMap<string, ConstrainedPolicy>,\n\tinitialPolicySet: readonly string[] | 'any',\n): readonly ConstrainedPolicy[] {\n\tif (initialPolicySet === 'any') {\n\t\treturn [...finalAuthorityConstrainedPolicies.values()].sort(comparePolicies);\n\t}\n\tconst anyPolicy = rootDomainPolicies.get(OIDS.anyPolicy);\n\t// If the EE asserts anyPolicy, it satisfies any policy in initial-policy-set\n\tconst eeHasAnyPolicy = finalAuthorityConstrainedPolicies.has(OIDS.anyPolicy);\n\tconst constrained = new Map<string, ConstrainedPolicy>();\n\tfor (const policyIdentifier of initialPolicySet) {\n\t\tconst direct = rootDomainPolicies.get(policyIdentifier);\n\t\tif (direct !== undefined) {\n\t\t\tconstrained.set(policyIdentifier, direct);\n\t\t\tcontinue;\n\t\t}\n\t\t// anyPolicy can satisfy a requested policy if:\n\t\t// 1. The EE asserts the specific policy (finalAuthorityConstrainedPolicies.has), OR\n\t\t// 2. The EE itself asserts anyPolicy (eeHasAnyPolicy)\n\t\tif (\n\t\t\tanyPolicy !== undefined &&\n\t\t\t(finalAuthorityConstrainedPolicies.has(policyIdentifier) || eeHasAnyPolicy)\n\t\t) {\n\t\t\tconstrained.set(\n\t\t\t\tpolicyIdentifier,\n\t\t\t\tbuildConstrainedPolicy(policyIdentifier, anyPolicy.policyQualifiers),\n\t\t\t);\n\t\t}\n\t}\n\treturn [...constrained.values()].sort(comparePolicies);\n}\n\n/** Constructs a {@linkcode ConstrainedPolicy}, omitting qualifiers when absent. */\nfunction buildConstrainedPolicy(\n\tpolicyIdentifier: string,\n\tpolicyQualifiers: readonly PolicyQualifierInfo[] | undefined,\n): ConstrainedPolicy {\n\treturn {\n\t\tpolicyIdentifier,\n\t\t...(policyQualifiers === undefined ? {} : { policyQualifiers }),\n\t};\n}\n\n/** Lexicographic comparator for sorting policies by OID string. */\nfunction comparePolicies(left: ConstrainedPolicy, right: ConstrainedPolicy): number {\n\treturn left.policyIdentifier.localeCompare(right.policyIdentifier);\n}\n\n/** Human-readable comma-joined OID list for error messages; `\"<none>\"` when empty. */\nfunction describeFinalPolicies(policies: readonly ConstrainedPolicy[]): string {\n\treturn policies.length === 0\n\t\t? '<none>'\n\t\t: policies.map((policy) => policy.policyIdentifier).join(',');\n}\n\n/** Applies one certificate's policies, mappings, and constraints to the running state. */\nfunction processPolicyCertificate(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n\tdepth: number,\n\tisLeaf: boolean,\n): void {\n\tconst certificatePolicies = normalizeCertificatePolicies(certificate.certificatePolicies);\n\tif (state.validPolicyGraph !== null && certificatePolicies === undefined) {\n\t\tstate.validPolicyGraph = null;\n\t} else if (state.validPolicyGraph !== null && certificatePolicies !== undefined) {\n\t\tapplyCertificatePolicyStep(\n\t\t\tstate.validPolicyGraph,\n\t\t\tcertificatePolicies,\n\t\t\tdepth,\n\t\t\tstate.inhibitAnyPolicy > 0 || (!isLeaf && isSelfIssued(certificate)),\n\t\t);\n\t\tif (certificate.policyMappings !== undefined) {\n\t\t\tapplyPolicyMappingsStep(\n\t\t\t\tstate.validPolicyGraph,\n\t\t\t\tdepth,\n\t\t\t\tcertificate.policyMappings,\n\t\t\t\tstate.inhibitPolicyMapping > 0,\n\t\t\t);\n\t\t}\n\t}\n\tupdatePolicyCounters(state, certificate, isLeaf);\n}\n\n/** Deduplicates certificate policies by OID, keeping the first occurrence. */\nfunction normalizeCertificatePolicies(\n\tpolicies: readonly PolicyInformation[] | undefined,\n): Map<string, PolicyInformation> | undefined {\n\tif (policies === undefined) {\n\t\treturn undefined;\n\t}\n\tconst byOid = new Map<string, PolicyInformation>();\n\tfor (const policy of policies) {\n\t\tif (!byOid.has(policy.policyIdentifier)) {\n\t\t\tbyOid.set(policy.policyIdentifier, policy);\n\t\t}\n\t}\n\treturn byOid;\n}\n\n/** Extends the policy graph by one depth level using a certificate's policy extension. */\nfunction applyCertificatePolicyStep(\n\tgraph: PolicyGraph,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n\tallowAnyPolicyExpansion: boolean,\n): void {\n\tconst previousDepth = graph.nodesByDepth[depth - 1] ?? new Map<string, PolicyGraphNode>();\n\tconst currentDepth = new Map<string, PolicyGraphNode>();\n\tgraph.nodesByDepth[depth] = currentDepth;\n\tconst anyPolicyInfo = certificatePolicies.get(OIDS.anyPolicy);\n\tconst previousAnyPolicy = previousDepth.get(policyNodeKey(depth - 1, OIDS.anyPolicy));\n\tconst previousAnyPolicyKey = policyNodeKey(depth - 1, OIDS.anyPolicy);\n\n\taddPolicyNodesFromExpectedParents(graph, currentDepth, previousDepth, certificatePolicies, depth);\n\n\tif (previousAnyPolicy !== undefined) {\n\t\taddPolicyNodesFromPreviousAnyPolicy(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tcertificatePolicies,\n\t\t\tdepth,\n\t\t\tpreviousAnyPolicyKey,\n\t\t);\n\t}\n\n\tif (anyPolicyInfo !== undefined && allowAnyPolicyExpansion) {\n\t\taddAnyPolicyExpansionNodes(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tpreviousDepth,\n\t\t\tdepth,\n\t\t\tanyPolicyInfo,\n\t\t\tpreviousAnyPolicyKey,\n\t\t\tpreviousAnyPolicy !== undefined,\n\t\t);\n\t}\n\n\tprunePolicyGraph(graph, depth - 1);\n}\n\n/** Adds explicit certificate-policy nodes whose expected policies match parent nodes. */\nfunction addPolicyNodesFromExpectedParents(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tpreviousDepth: ReadonlyMap<string, PolicyGraphNode>,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n): void {\n\tfor (const policy of certificatePolicies.values()) {\n\t\tif (policy.policyIdentifier === OIDS.anyPolicy) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst matchingParents = collectParentsForExpectedPolicy(previousDepth, policy.policyIdentifier);\n\t\tif (matchingParents.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tpolicy.policyIdentifier,\n\t\t\tpolicy.policyQualifiers,\n\t\t\tmatchingParents,\n\t\t\t[policy.policyIdentifier],\n\t\t);\n\t}\n}\n\nfunction addPolicyNodesFromPreviousAnyPolicy(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n\tpreviousAnyPolicyKey: string,\n): void {\n\tfor (const policy of certificatePolicies.values()) {\n\t\tif (policy.policyIdentifier === OIDS.anyPolicy) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (currentDepth.has(policyNodeKey(depth, policy.policyIdentifier))) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tpolicy.policyIdentifier,\n\t\t\tpolicy.policyQualifiers,\n\t\t\t[previousAnyPolicyKey],\n\t\t\t[policy.policyIdentifier],\n\t\t);\n\t}\n}\n\n/** Expands an accepted anyPolicy entry into the policies expected by the previous depth. */\nfunction addAnyPolicyExpansionNodes(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tpreviousDepth: ReadonlyMap<string, PolicyGraphNode>,\n\tdepth: number,\n\tanyPolicyInfo: PolicyInformation,\n\tpreviousAnyPolicyKey: string,\n\thasPreviousAnyPolicy: boolean,\n): void {\n\tfor (const [validPolicy, parentKeys] of collectExpectedPolicyParents(previousDepth)) {\n\t\tif (currentDepth.has(policyNodeKey(depth, validPolicy))) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst expansionParents = collectAnyPolicyExpansionParents(\n\t\t\tvalidPolicy,\n\t\t\tparentKeys,\n\t\t\tpreviousAnyPolicyKey,\n\t\t\thasPreviousAnyPolicy,\n\t\t);\n\t\tif (expansionParents.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tvalidPolicy,\n\t\t\tanyPolicyInfo.policyQualifiers,\n\t\t\texpansionParents,\n\t\t\t[validPolicy],\n\t\t);\n\t}\n}\n\nfunction collectAnyPolicyExpansionParents(\n\tvalidPolicy: string,\n\tparentKeys: readonly string[],\n\tpreviousAnyPolicyKey: string,\n\thasPreviousAnyPolicy: boolean,\n): readonly string[] {\n\tif (validPolicy !== OIDS.anyPolicy) {\n\t\treturn parentKeys;\n\t}\n\treturn hasPreviousAnyPolicy ? [previousAnyPolicyKey] : [];\n}\n\n/** Finds all previous-depth nodes whose expectedPolicySet contains the given OID. */\nfunction collectParentsForExpectedPolicy(\n\tnodes: ReadonlyMap<string, PolicyGraphNode>,\n\tpolicyIdentifier: string,\n): string[] {\n\tconst parents: string[] = [];\n\tfor (const [key, node] of nodes) {\n\t\tif (node.expectedPolicySet.has(policyIdentifier)) {\n\t\t\tparents.push(key);\n\t\t}\n\t}\n\treturn parents;\n}\n\n/** Groups all previous-depth nodes by each OID in their expectedPolicySet. */\nfunction collectExpectedPolicyParents(\n\tnodes: ReadonlyMap<string, PolicyGraphNode>,\n): Map<string, string[]> {\n\tconst parentsByPolicy = new Map<string, string[]>();\n\tfor (const [key, node] of nodes) {\n\t\tfor (const expectedPolicy of node.expectedPolicySet) {\n\t\t\tconst parents = parentsByPolicy.get(expectedPolicy);\n\t\t\tif (parents === undefined) {\n\t\t\t\tparentsByPolicy.set(expectedPolicy, [key]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tparents.push(key);\n\t\t}\n\t}\n\treturn parentsByPolicy;\n}\n\n/** Inserts a node at the current depth, or merges parents/expected-policies into an existing one. */\nfunction addOrMergePolicyNode(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tdepth: number,\n\tvalidPolicy: string,\n\tqualifierSet: readonly PolicyQualifierInfo[] | undefined,\n\tparentKeys: readonly string[],\n\texpectedPolicySet: readonly string[],\n): void {\n\tconst key = policyNodeKey(depth, validPolicy);\n\tconst existing = currentDepth.get(key);\n\tif (existing !== undefined) {\n\t\tfor (const parentKey of parentKeys) {\n\t\t\texisting.parentKeys.add(parentKey);\n\t\t\tgetPolicyGraphNode(graph, parentKey)?.childKeys.add(key);\n\t\t}\n\t\tfor (const expectedPolicy of expectedPolicySet) {\n\t\t\texisting.expectedPolicySet.add(expectedPolicy);\n\t\t}\n\t\tif (existing.qualifierSet === undefined && qualifierSet !== undefined) {\n\t\t\texisting.qualifierSet = qualifierSet;\n\t\t}\n\t\treturn;\n\t}\n\tconst node = createPolicyGraphNode(\n\t\tdepth,\n\t\tvalidPolicy,\n\t\tqualifierSet,\n\t\texpectedPolicySet,\n\t\tparentKeys,\n\t);\n\tcurrentDepth.set(key, node);\n\tfor (const parentKey of parentKeys) {\n\t\tgetPolicyGraphNode(graph, parentKey)?.childKeys.add(key);\n\t}\n}\n\n/** Looks up a node by its `\"depth:oid\"` key, parsing the depth prefix. */\nfunction getPolicyGraphNode(graph: PolicyGraph, key: string): PolicyGraphNode | undefined {\n\tconst separator = key.indexOf(':');\n\tif (separator <= 0) {\n\t\treturn undefined;\n\t}\n\tconst depthString = key.slice(0, separator);\n\tconst depth = Number.parseInt(depthString, 10);\n\tif (Number.isNaN(depth)) {\n\t\treturn undefined;\n\t}\n\treturn graph.nodesByDepth[depth]?.get(key);\n}\n\n/** Removes childless leaf nodes bottom-up, cascading deletions through parent links. */\nfunction prunePolicyGraph(graph: PolicyGraph, maxDepth: number): void {\n\tfor (let depth = maxDepth; depth >= 0; depth -= 1) {\n\t\tconst nodes = graph.nodesByDepth[depth];\n\t\tif (nodes === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const key of [...nodes.keys()]) {\n\t\t\tconst node = nodes.get(key);\n\t\t\tif (node === undefined || node.childKeys.size > 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdeletePolicyGraphNode(graph, key);\n\t\t}\n\t}\n}\n\n/** Removes a node and recursively prunes its parents if they become childless. */\nfunction deletePolicyGraphNode(graph: PolicyGraph, key: string): void {\n\tconst node = getPolicyGraphNode(graph, key);\n\tif (node === undefined) {\n\t\treturn;\n\t}\n\tgraph.nodesByDepth[node.depth]?.delete(key);\n\tfor (const parentKey of node.parentKeys) {\n\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\tif (parent === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tparent.childKeys.delete(key);\n\t\tif (parent.childKeys.size === 0) {\n\t\t\tdeletePolicyGraphNode(graph, parentKey);\n\t\t}\n\t}\n}\n\n/** Applies issuer→subject policy mappings at the current depth, or deletes mapped nodes when disallowed. */\nfunction applyPolicyMappingsStep(\n\tgraph: PolicyGraph,\n\tdepth: number,\n\tmappings: readonly {\n\t\treadonly issuerDomainPolicy: string;\n\t\treadonly subjectDomainPolicy: string;\n\t}[],\n\tmappingAllowed: boolean,\n): void {\n\tconst currentDepth = graph.nodesByDepth[depth];\n\tif (currentDepth === undefined) {\n\t\treturn;\n\t}\n\tconst groupedMappings = new Map<string, string[]>();\n\tfor (const mapping of mappings) {\n\t\tif (\n\t\t\tmapping.issuerDomainPolicy === OIDS.anyPolicy ||\n\t\t\tmapping.subjectDomainPolicy === OIDS.anyPolicy\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst subjectPolicies = groupedMappings.get(mapping.issuerDomainPolicy);\n\t\tif (subjectPolicies === undefined) {\n\t\t\tgroupedMappings.set(mapping.issuerDomainPolicy, [mapping.subjectDomainPolicy]);\n\t\t\tcontinue;\n\t\t}\n\t\tsubjectPolicies.push(mapping.subjectDomainPolicy);\n\t}\n\tconst anyPolicyNode = currentDepth.get(policyNodeKey(depth, OIDS.anyPolicy));\n\tfor (const [issuerDomainPolicy, subjectDomainPolicies] of groupedMappings) {\n\t\tconst nodeKey = policyNodeKey(depth, issuerDomainPolicy);\n\t\tconst node = currentDepth.get(nodeKey);\n\t\tif (mappingAllowed) {\n\t\t\tif (node !== undefined) {\n\t\t\t\tnode.expectedPolicySet = new Set(subjectDomainPolicies);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (anyPolicyNode !== undefined) {\n\t\t\t\taddOrMergePolicyNode(\n\t\t\t\t\tgraph,\n\t\t\t\t\tcurrentDepth,\n\t\t\t\t\tdepth,\n\t\t\t\t\tissuerDomainPolicy,\n\t\t\t\t\tanyPolicyNode.qualifierSet,\n\t\t\t\t\t[...anyPolicyNode.parentKeys],\n\t\t\t\t\tsubjectDomainPolicies,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (node !== undefined) {\n\t\t\tdeletePolicyGraphNode(graph, nodeKey);\n\t\t}\n\t}\n\tprunePolicyGraph(graph, depth - 1);\n}\n\n/** Decrements explicitPolicy / inhibitPolicyMapping / inhibitAnyPolicy and applies policyConstraints overrides. */\nfunction updatePolicyCounters(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n\tisLeaf: boolean,\n): void {\n\tif (isLeaf) {\n\t\tupdateLeafPolicyCounter(state, certificate);\n\t\treturn;\n\t}\n\tif (!isSelfIssued(certificate)) {\n\t\tdecrementPolicyCounters(state);\n\t}\n\tapplyPolicyCounterOverrides(state, certificate);\n}\n\nfunction updateLeafPolicyCounter(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n): void {\n\tdecrementPositiveCounter(state, 'explicitPolicy');\n\tif (certificate.policyConstraints?.requireExplicitPolicy === 0) {\n\t\tstate.explicitPolicy = 0;\n\t}\n}\n\nfunction decrementPolicyCounters(state: PolicyValidationState): void {\n\tdecrementPositiveCounter(state, 'explicitPolicy');\n\tdecrementPositiveCounter(state, 'inhibitPolicyMapping');\n\tdecrementPositiveCounter(state, 'inhibitAnyPolicy');\n}\n\nfunction decrementPositiveCounter(\n\tstate: PolicyValidationState,\n\tkey: 'explicitPolicy' | 'inhibitPolicyMapping' | 'inhibitAnyPolicy',\n): void {\n\tif (state[key] > 0) {\n\t\tstate[key] -= 1;\n\t}\n}\n\nfunction applyPolicyCounterOverrides(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n): void {\n\tconst policyConstraints = certificate.policyConstraints;\n\tif (\n\t\tisNonNegativeInteger(policyConstraints?.requireExplicitPolicy) &&\n\t\tpolicyConstraints.requireExplicitPolicy < state.explicitPolicy\n\t) {\n\t\tstate.explicitPolicy = policyConstraints.requireExplicitPolicy;\n\t}\n\tif (\n\t\tisNonNegativeInteger(policyConstraints?.inhibitPolicyMapping) &&\n\t\tpolicyConstraints.inhibitPolicyMapping < state.inhibitPolicyMapping\n\t) {\n\t\tstate.inhibitPolicyMapping = policyConstraints.inhibitPolicyMapping;\n\t}\n\tif (\n\t\tisNonNegativeInteger(certificate.inhibitAnyPolicy?.skipCerts) &&\n\t\tcertificate.inhibitAnyPolicy.skipCerts < state.inhibitAnyPolicy\n\t) {\n\t\tstate.inhibitAnyPolicy = certificate.inhibitAnyPolicy.skipCerts;\n\t}\n}\n\nfunction isNonNegativeInteger(value: number | undefined): value is number {\n\treturn value !== undefined && Number.isInteger(value) && value >= 0;\n}\n\n/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */\nfunction isSelfIssued(certificate: ParsedCertificate): boolean {\n\treturn compareDistinguishedNames(certificate.subject, certificate.issuer);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuFA,SAAgB,4BACf,GACA,GACwB;CACxB,IAAM,IAAkB,IAAc;CACtC,OAAO;EACN,kBAAkB,EAAM,oBAAoB;EAC5C,gBAAgB,EAAM,0BAA0B,KAAO,IAAI;EAC3D,sBAAsB,EAAM,yBAAyB,KAAO,IAAI;EAChE,kBAAkB,EAAM,qBAAqB,KAAO,IAAI;EACxD,kBAAkB,yBAAyB;CAC5C;AACD;;;;;AAMA,SAAgB,oBACf,GACA,GACyB;CACzB,IAAI,EAAM,WAAW,GACpB,MAAU,WAAW,qDAAqD;CAE3E,mBAAmB,GAAO,CAAK;CAC/B,IAAM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C;CACD;CAIA,AAHK,aAAa,CAAW,KAC5B,wBAAwB,CAAK,GAE9B,4BAA4B,GAAO,CAAW;AAC/C;AAEA,SAAS,wBACR,GACA,GACO;CAEP,AADA,yBAAyB,GAAO,gBAAgB,GAC5C,EAAY,mBAAmB,0BAA0B,MAC5D,EAAM,iBAAiB;AAEzB;AAEA,SAAS,wBAAwB,GAAoC;CAGpE,AAFA,yBAAyB,GAAO,gBAAgB,GAChD,yBAAyB,GAAO,sBAAsB,GACtD,yBAAyB,GAAO,kBAAkB;AACnD;AAEA,SAAS,yBACR,GACA,GACO;CACP,AAAI,EAAM,KAAO,KAChB,IAAM;AAER;AAEA,SAAS,4BACR,GACA,GACO;CACP,IAAM,IAAoB,EAAY;CAatC,AAXC,qBAAqB,GAAmB,qBAAqB,KAC7D,EAAkB,wBAAwB,EAAM,mBAEhD,EAAM,iBAAiB,EAAkB,wBAGzC,qBAAqB,GAAmB,oBAAoB,KAC5D,EAAkB,uBAAuB,EAAM,yBAE/C,EAAM,uBAAuB,EAAkB,uBAG/C,qBAAqB,EAAY,kBAAkB,SAAS,KAC5D,EAAY,iBAAiB,YAAY,EAAM,qBAE/C,EAAM,mBAAmB,EAAY,iBAAiB;AAExD;AAEA,SAAS,qBAAqB,GAA4C;CACzE,OAAO,MAAU,KAAA,KAAa,OAAO,UAAU,CAAK,KAAK,KAAS;AACnE;;AAGA,SAAS,aAAa,GAAyC;CAC9D,OAAO,EAA0B,EAAY,SAAS,EAAY,MAAM;AACzE"}
1
+ {"version":3,"file":"policy-engine.js","names":[],"sources":["../../../src/internal/verify/policy-engine.ts"],"sourcesContent":["/**\n * Internal RFC 9618 policy-validation engine.\n *\n * Tracks the policy graph and counter state through each certificate in a\n * chain, then derives the {@linkcode PolicyValidationOutcome}.\n *\n * @module\n */\n\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport { compareDistinguishedNames } from '#micro509/internal/shared/dn';\nimport type { Micro509Error, Result } from '#micro509/result/result';\nimport type {\n\tConstrainedPolicy,\n\tPolicyValidationInput,\n\tPolicyValidationOutcome,\n} from '#micro509/verify/policy';\nimport type { PolicyInformation, PolicyQualifierInfo } from '#micro509/x509/extensions';\nimport type { ParsedCertificate } from '#micro509/x509/parse';\n\n/**\n * Mutable state threaded through each step of the policy-validation walk.\n *\n * Created by {@linkcode createPolicyValidationState}, consumed by\n * {@linkcode evaluatePolicyChain}.\n */\nexport interface PolicyValidationState {\n\t/** Caller-requested acceptable policies, or `'any'`. */\n\treadonly initialPolicySet: readonly string[] | 'any';\n\t/** Remaining certificates before explicit-policy enforcement kicks in. */\n\texplicitPolicy: number;\n\t/** Remaining certificates before policy mappings are disallowed. */\n\tinhibitPolicyMapping: number;\n\t/** Remaining certificates before anyPolicy expansion stops. */\n\tinhibitAnyPolicy: number;\n\t/** The RFC 9618 policy graph; `null` when the graph has been emptied. */\n\tvalidPolicyGraph: PolicyGraph | null;\n}\n\n/** Discriminant codes for policy-validation failures. */\nexport type PolicyValidationFailureCode =\n\t| 'explicit_policy_required'\n\t| 'initial_policy_set_not_satisfied';\n\n/** Diagnostic context for a policy-validation failure. */\nexport interface PolicyValidationFailureDetails {\n\t/** Description of the policies the caller expected. */\n\treadonly expected: string;\n\t/** Comma-joined OIDs (or `\"<none>\"`) that actually survived processing. */\n\treadonly actual: string;\n}\n\n/** A policy-validation failure with structured diagnostic details. */\nexport interface PolicyValidationFailure\n\textends Micro509Error<PolicyValidationFailureCode, PolicyValidationFailureDetails> {}\n\n/** Success with {@linkcode PolicyValidationOutcome}, or a {@linkcode PolicyValidationFailure}. */\nexport type PolicyValidationResult = Result<PolicyValidationOutcome, PolicyValidationFailure>;\n\n/** One node in the RFC 9618 policy graph, keyed by `depth:policyOID`. */\nexport interface PolicyGraphNode {\n\t/** Graph depth (0 = root anyPolicy node). */\n\tdepth: number;\n\t/** The policy OID this node represents at its depth. */\n\tvalidPolicy: string;\n\t/** Policy qualifiers inherited from the certificate that created this node. */\n\tqualifierSet?: readonly PolicyQualifierInfo[];\n\t/** OIDs this node expects to see in the next certificate's policies. */\n\texpectedPolicySet: Set<string>;\n\t/** Keys of parent nodes in the previous depth level. */\n\tparentKeys: Set<string>;\n\t/** Keys of child nodes in the next depth level. */\n\tchildKeys: Set<string>;\n}\n\n/** The full RFC 9618 valid-policy graph, indexed by depth level. */\nexport interface PolicyGraph {\n\t/** Each index `i` holds the nodes at depth `i`, keyed by `\"depth:oid\"`. */\n\tnodesByDepth: Map<string, PolicyGraphNode>[];\n}\n\n/**\n * Initializes mutable policy state from caller options.\n *\n * Counter values default to `chainLength + 1` (effectively disabled) unless\n * the corresponding input flag is `true`.\n */\nexport function createPolicyValidationState(\n\tinput: PolicyValidationInput,\n\tchainLength: number,\n): PolicyValidationState {\n\tconst disabledCounter = chainLength + 1;\n\treturn {\n\t\tinitialPolicySet: input.initialPolicySet ?? 'any',\n\t\texplicitPolicy: input.requireExplicitPolicy === true ? 0 : disabledCounter,\n\t\tinhibitPolicyMapping: input.inhibitPolicyMapping === true ? 0 : disabledCounter,\n\t\tinhibitAnyPolicy: input.inhibitAnyPolicy === true ? 0 : disabledCounter,\n\t\tvalidPolicyGraph: createInitialPolicyGraph(),\n\t};\n}\n\n/**\n * Walks the chain root-to-leaf, updating policy state per certificate,\n * then checks whether the resulting policy set satisfies caller requirements.\n */\nexport function evaluatePolicyChain(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): PolicyValidationResult {\n\tif (chain.length === 0) {\n\t\tthrow new RangeError('policy validation requires at least one certificate');\n\t}\n\tprocessPolicyState(chain, state);\n\tconst outcome = derivePolicyValidationOutcome(chain, state);\n\tif (state.explicitPolicy === 0 && outcome.userConstrainedPolicies.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: {\n\t\t\t\tcode: 'explicit_policy_required',\n\t\t\t\tmessage: 'policy validation requires an explicit permitted policy',\n\t\t\t\tdetails: {\n\t\t\t\t\texpected:\n\t\t\t\t\t\tstate.initialPolicySet === 'any' ? 'explicit policy' : state.initialPolicySet.join(','),\n\t\t\t\t\tactual: describeFinalPolicies(outcome.userConstrainedPolicies),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tif (state.initialPolicySet !== 'any' && outcome.userConstrainedPolicies.length === 0) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\terror: {\n\t\t\t\tcode: 'initial_policy_set_not_satisfied',\n\t\t\t\tmessage: 'certificate chain does not satisfy the requested initial policy set',\n\t\t\t\tdetails: {\n\t\t\t\t\texpected: state.initialPolicySet.join(','),\n\t\t\t\t\tactual: describeFinalPolicies(outcome.userConstrainedPolicies),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn { ok: true, value: outcome };\n}\n\n/** Builds the depth-0 graph with a single anyPolicy root node. */\nfunction createInitialPolicyGraph(): PolicyGraph {\n\tconst rootNode = createPolicyGraphNode(0, OIDS.anyPolicy, undefined, [OIDS.anyPolicy], []);\n\treturn {\n\t\tnodesByDepth: [new Map([[policyNodeKey(0, OIDS.anyPolicy), rootNode]])],\n\t};\n}\n\n/** Constructs a new {@linkcode PolicyGraphNode} with empty child-key set. */\nfunction createPolicyGraphNode(\n\tdepth: number,\n\tvalidPolicy: string,\n\tqualifierSet: readonly PolicyQualifierInfo[] | undefined,\n\texpectedPolicySet: readonly string[],\n\tparentKeys: readonly string[],\n): PolicyGraphNode {\n\treturn {\n\t\tdepth,\n\t\tvalidPolicy,\n\t\t...(qualifierSet === undefined ? {} : { qualifierSet }),\n\t\texpectedPolicySet: new Set(expectedPolicySet),\n\t\tparentKeys: new Set(parentKeys),\n\t\tchildKeys: new Set<string>(),\n\t};\n}\n\n/** Canonical map key for a graph node: `\"depth:policyOID\"`. */\nfunction policyNodeKey(depth: number, validPolicy: string): string {\n\treturn `${String(depth)}:${validPolicy}`;\n}\n\n/** Iterates root-to-leaf (skipping root), applying each certificate's policies to the state. */\nfunction processPolicyState(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): void {\n\tif (chain.length === 1) {\n\t\tconst certificate = chain[0];\n\t\tif (certificate === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`missing certificate at chain index 0 (chain length ${String(chain.length)})`,\n\t\t\t);\n\t\t}\n\t\tprocessPolicyCertificate(state, certificate, 1, true);\n\t\treturn;\n\t}\n\tconst leafDepth = chain.length - 1;\n\tfor (let index = chain.length - 2; index >= 0; index -= 1) {\n\t\tconst certificate = chain[index];\n\t\tif (certificate === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`missing certificate at chain index ${String(index)} (chain length ${String(chain.length)})`,\n\t\t\t);\n\t\t}\n\t\tconst depth = leafDepth - index;\n\t\tprocessPolicyCertificate(state, certificate, depth, depth === leafDepth);\n\t}\n}\n\n/** Extracts the final authority- and user-constrained policy sets from the completed graph. */\nfunction derivePolicyValidationOutcome(\n\tchain: readonly ParsedCertificate[],\n\tstate: PolicyValidationState,\n): PolicyValidationOutcome {\n\tconst authorityConstrainedPolicies = collectAuthorityConstrainedPolicies(\n\t\tchain,\n\t\tstate.validPolicyGraph,\n\t);\n\tconst rootDomainPolicies = collectRootDomainPolicies(chain, state.validPolicyGraph);\n\treturn {\n\t\tauthorityConstrainedPolicies: [...authorityConstrainedPolicies.values()].sort(comparePolicies),\n\t\tuserConstrainedPolicies: deriveUserConstrainedPolicies(\n\t\t\tauthorityConstrainedPolicies,\n\t\t\trootDomainPolicies,\n\t\t\tstate.initialPolicySet,\n\t\t),\n\t};\n}\n\n/** Collects leaf-depth policies whose graph paths trace back to the anyPolicy root. */\nfunction collectAuthorityConstrainedPolicies(\n\tchain: readonly ParsedCertificate[],\n\tgraph: PolicyGraph | null,\n): ReadonlyMap<string, ConstrainedPolicy> {\n\tif (graph === null) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst leafDepth = Math.max(1, chain.length - 1);\n\tconst finalDepth = graph.nodesByDepth[leafDepth];\n\tif (finalDepth === undefined) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst authorityPolicies = new Map<string, ConstrainedPolicy>();\n\tfor (const [key, node] of finalDepth) {\n\t\tif (node.validPolicy === OIDS.anyPolicy) {\n\t\t\tauthorityPolicies.set(\n\t\t\t\tOIDS.anyPolicy,\n\t\t\t\tbuildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet),\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (reachesAuthorityRoot(graph, key)) {\n\t\t\tauthorityPolicies.set(\n\t\t\t\tnode.validPolicy,\n\t\t\t\tbuildConstrainedPolicy(node.validPolicy, node.qualifierSet),\n\t\t\t);\n\t\t}\n\t}\n\treturn authorityPolicies;\n}\n\n/** DFS upward through parent links to check if the node ultimately connects to the depth-0 anyPolicy root. */\nfunction reachesAuthorityRoot(graph: PolicyGraph, nodeKey: string): boolean {\n\tconst pending = [nodeKey];\n\tconst visited = new Set<string>();\n\twhile (pending.length > 0) {\n\t\tconst currentKey = pending.pop();\n\t\tif (currentKey === undefined || visited.has(currentKey)) {\n\t\t\tcontinue;\n\t\t}\n\t\tvisited.add(currentKey);\n\t\tconst node = getPolicyGraphNode(graph, currentKey);\n\t\tif (node === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const parentKey of node.parentKeys) {\n\t\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\t\tif (parent === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (parent.depth === 0 && parent.validPolicy === OIDS.anyPolicy) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tpending.push(parentKey);\n\t\t}\n\t}\n\treturn false;\n}\n\n/** Like authority-constrained, but records the OID at the depth-1 node that connects to root. */\nfunction collectRootDomainPolicies(\n\tchain: readonly ParsedCertificate[],\n\tgraph: PolicyGraph | null,\n): ReadonlyMap<string, ConstrainedPolicy> {\n\tif (graph === null) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst leafDepth = Math.max(1, chain.length - 1);\n\tconst finalDepth = graph.nodesByDepth[leafDepth];\n\tif (finalDepth === undefined) {\n\t\treturn new Map<string, ConstrainedPolicy>();\n\t}\n\tconst rootPolicies = new Map<string, ConstrainedPolicy>();\n\tfor (const [key, node] of finalDepth) {\n\t\tif (node.validPolicy === OIDS.anyPolicy) {\n\t\t\trootPolicies.set(OIDS.anyPolicy, buildConstrainedPolicy(OIDS.anyPolicy, node.qualifierSet));\n\t\t\tcontinue;\n\t\t}\n\t\tcollectAuthorityConstrainedPolicyRoots(graph, key, rootPolicies);\n\t}\n\treturn rootPolicies;\n}\n\n/** Walks parent links upward, collecting the depth-1 OID that first connects to the root anyPolicy. */\nfunction collectAuthorityConstrainedPolicyRoots(\n\tgraph: PolicyGraph,\n\tnodeKey: string,\n\tauthorityPolicies: Map<string, ConstrainedPolicy>,\n): void {\n\tconst pending = [nodeKey];\n\tconst visited = new Set<string>();\n\twhile (pending.length > 0) {\n\t\tconst currentKey = pending.pop();\n\t\tif (currentKey === undefined || visited.has(currentKey)) {\n\t\t\tcontinue;\n\t\t}\n\t\tvisited.add(currentKey);\n\t\tconst node = getPolicyGraphNode(graph, currentKey);\n\t\tif (node === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const parentKey of node.parentKeys) {\n\t\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\t\tif (parent === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (parent.depth === 0 && parent.validPolicy === OIDS.anyPolicy) {\n\t\t\t\t// Record the depth-1 policy that connects to root\n\t\t\t\t// If the depth-1 node is anyPolicy itself, record anyPolicy so it can satisfy\n\t\t\t\t// any policy in the initial-policy-set via deriveUserConstrainedPolicies\n\t\t\t\tauthorityPolicies.set(\n\t\t\t\t\tnode.validPolicy,\n\t\t\t\t\tbuildConstrainedPolicy(\n\t\t\t\t\t\tnode.validPolicy,\n\t\t\t\t\t\tcurrentKey === nodeKey ? node.qualifierSet : undefined,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tpending.push(parentKey);\n\t\t}\n\t}\n}\n\n/** Intersects root-domain policies with the caller's initial-policy-set. */\nfunction deriveUserConstrainedPolicies(\n\tfinalAuthorityConstrainedPolicies: ReadonlyMap<string, ConstrainedPolicy>,\n\trootDomainPolicies: ReadonlyMap<string, ConstrainedPolicy>,\n\tinitialPolicySet: readonly string[] | 'any',\n): readonly ConstrainedPolicy[] {\n\tif (initialPolicySet === 'any') {\n\t\treturn [...finalAuthorityConstrainedPolicies.values()].sort(comparePolicies);\n\t}\n\tconst anyPolicy = rootDomainPolicies.get(OIDS.anyPolicy);\n\t// If the EE asserts anyPolicy, it satisfies any policy in initial-policy-set\n\tconst eeHasAnyPolicy = finalAuthorityConstrainedPolicies.has(OIDS.anyPolicy);\n\tconst constrained = new Map<string, ConstrainedPolicy>();\n\tfor (const policyIdentifier of initialPolicySet) {\n\t\tconst direct = rootDomainPolicies.get(policyIdentifier);\n\t\tif (direct !== undefined) {\n\t\t\tconstrained.set(policyIdentifier, direct);\n\t\t\tcontinue;\n\t\t}\n\t\t// anyPolicy can satisfy a requested policy if:\n\t\t// 1. The EE asserts the specific policy (finalAuthorityConstrainedPolicies.has), OR\n\t\t// 2. The EE itself asserts anyPolicy (eeHasAnyPolicy)\n\t\tif (\n\t\t\tanyPolicy !== undefined &&\n\t\t\t(finalAuthorityConstrainedPolicies.has(policyIdentifier) || eeHasAnyPolicy)\n\t\t) {\n\t\t\tconstrained.set(\n\t\t\t\tpolicyIdentifier,\n\t\t\t\tbuildConstrainedPolicy(policyIdentifier, anyPolicy.policyQualifiers),\n\t\t\t);\n\t\t}\n\t}\n\treturn [...constrained.values()].sort(comparePolicies);\n}\n\n/** Constructs a {@linkcode ConstrainedPolicy}, omitting qualifiers when absent. */\nfunction buildConstrainedPolicy(\n\tpolicyIdentifier: string,\n\tpolicyQualifiers: readonly PolicyQualifierInfo[] | undefined,\n): ConstrainedPolicy {\n\treturn {\n\t\tpolicyIdentifier,\n\t\t...(policyQualifiers === undefined ? {} : { policyQualifiers }),\n\t};\n}\n\n/** Lexicographic comparator for sorting policies by OID string. */\nfunction comparePolicies(left: ConstrainedPolicy, right: ConstrainedPolicy): number {\n\treturn left.policyIdentifier.localeCompare(right.policyIdentifier);\n}\n\n/** Human-readable comma-joined OID list for error messages; `\"<none>\"` when empty. */\nfunction describeFinalPolicies(policies: readonly ConstrainedPolicy[]): string {\n\treturn policies.length === 0\n\t\t? '<none>'\n\t\t: policies.map((policy) => policy.policyIdentifier).join(',');\n}\n\n/** Applies one certificate's policies, mappings, and constraints to the running state. */\nfunction processPolicyCertificate(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n\tdepth: number,\n\tisLeaf: boolean,\n): void {\n\tconst certificatePolicies = normalizeCertificatePolicies(certificate.certificatePolicies);\n\tif (state.validPolicyGraph !== null && certificatePolicies === undefined) {\n\t\tstate.validPolicyGraph = null;\n\t} else if (state.validPolicyGraph !== null && certificatePolicies !== undefined) {\n\t\tapplyCertificatePolicyStep(\n\t\t\tstate.validPolicyGraph,\n\t\t\tcertificatePolicies,\n\t\t\tdepth,\n\t\t\tstate.inhibitAnyPolicy > 0 || (!isLeaf && isSelfIssued(certificate)),\n\t\t);\n\t\tif (certificate.policyMappings !== undefined) {\n\t\t\tapplyPolicyMappingsStep(\n\t\t\t\tstate.validPolicyGraph,\n\t\t\t\tdepth,\n\t\t\t\tcertificate.policyMappings,\n\t\t\t\tstate.inhibitPolicyMapping > 0,\n\t\t\t);\n\t\t}\n\t}\n\tupdatePolicyCounters(state, certificate, isLeaf);\n}\n\n/** Deduplicates certificate policies by OID, keeping the first occurrence. */\nfunction normalizeCertificatePolicies(\n\tpolicies: readonly PolicyInformation[] | undefined,\n): Map<string, PolicyInformation> | undefined {\n\tif (policies === undefined) {\n\t\treturn undefined;\n\t}\n\tconst byOid = new Map<string, PolicyInformation>();\n\tfor (const policy of policies) {\n\t\tif (!byOid.has(policy.policyIdentifier)) {\n\t\t\tbyOid.set(policy.policyIdentifier, policy);\n\t\t}\n\t}\n\treturn byOid;\n}\n\n/** Extends the policy graph by one depth level using a certificate's policy extension. */\nfunction applyCertificatePolicyStep(\n\tgraph: PolicyGraph,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n\tallowAnyPolicyExpansion: boolean,\n): void {\n\tconst previousDepth = graph.nodesByDepth[depth - 1] ?? new Map<string, PolicyGraphNode>();\n\tconst currentDepth = new Map<string, PolicyGraphNode>();\n\tgraph.nodesByDepth[depth] = currentDepth;\n\tconst anyPolicyInfo = certificatePolicies.get(OIDS.anyPolicy);\n\tconst previousAnyPolicy = previousDepth.get(policyNodeKey(depth - 1, OIDS.anyPolicy));\n\tconst previousAnyPolicyKey = policyNodeKey(depth - 1, OIDS.anyPolicy);\n\n\taddPolicyNodesFromExpectedParents(graph, currentDepth, previousDepth, certificatePolicies, depth);\n\n\tif (previousAnyPolicy !== undefined) {\n\t\taddPolicyNodesFromPreviousAnyPolicy(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tcertificatePolicies,\n\t\t\tdepth,\n\t\t\tpreviousAnyPolicyKey,\n\t\t);\n\t}\n\n\tif (anyPolicyInfo !== undefined && allowAnyPolicyExpansion) {\n\t\taddAnyPolicyExpansionNodes(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tpreviousDepth,\n\t\t\tdepth,\n\t\t\tanyPolicyInfo,\n\t\t\tpreviousAnyPolicyKey,\n\t\t\tpreviousAnyPolicy !== undefined,\n\t\t);\n\t}\n\n\tprunePolicyGraph(graph, depth - 1);\n}\n\n/** Adds explicit certificate-policy nodes whose expected policies match parent nodes. */\nfunction addPolicyNodesFromExpectedParents(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tpreviousDepth: ReadonlyMap<string, PolicyGraphNode>,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n): void {\n\tfor (const policy of certificatePolicies.values()) {\n\t\tif (policy.policyIdentifier === OIDS.anyPolicy) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst matchingParents = collectParentsForExpectedPolicy(previousDepth, policy.policyIdentifier);\n\t\tif (matchingParents.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tpolicy.policyIdentifier,\n\t\t\tpolicy.policyQualifiers,\n\t\t\tmatchingParents,\n\t\t\t[policy.policyIdentifier],\n\t\t);\n\t}\n}\n\nfunction addPolicyNodesFromPreviousAnyPolicy(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tcertificatePolicies: ReadonlyMap<string, PolicyInformation>,\n\tdepth: number,\n\tpreviousAnyPolicyKey: string,\n): void {\n\tfor (const policy of certificatePolicies.values()) {\n\t\tif (policy.policyIdentifier === OIDS.anyPolicy) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (currentDepth.has(policyNodeKey(depth, policy.policyIdentifier))) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tpolicy.policyIdentifier,\n\t\t\tpolicy.policyQualifiers,\n\t\t\t[previousAnyPolicyKey],\n\t\t\t[policy.policyIdentifier],\n\t\t);\n\t}\n}\n\n/** Expands an accepted anyPolicy entry into the policies expected by the previous depth. */\nfunction addAnyPolicyExpansionNodes(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tpreviousDepth: ReadonlyMap<string, PolicyGraphNode>,\n\tdepth: number,\n\tanyPolicyInfo: PolicyInformation,\n\tpreviousAnyPolicyKey: string,\n\thasPreviousAnyPolicy: boolean,\n): void {\n\tfor (const [validPolicy, parentKeys] of collectExpectedPolicyParents(previousDepth)) {\n\t\tif (currentDepth.has(policyNodeKey(depth, validPolicy))) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst expansionParents = collectAnyPolicyExpansionParents(\n\t\t\tvalidPolicy,\n\t\t\tparentKeys,\n\t\t\tpreviousAnyPolicyKey,\n\t\t\thasPreviousAnyPolicy,\n\t\t);\n\t\tif (expansionParents.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\taddOrMergePolicyNode(\n\t\t\tgraph,\n\t\t\tcurrentDepth,\n\t\t\tdepth,\n\t\t\tvalidPolicy,\n\t\t\tanyPolicyInfo.policyQualifiers,\n\t\t\texpansionParents,\n\t\t\t[validPolicy],\n\t\t);\n\t}\n}\n\nfunction collectAnyPolicyExpansionParents(\n\tvalidPolicy: string,\n\tparentKeys: readonly string[],\n\tpreviousAnyPolicyKey: string,\n\thasPreviousAnyPolicy: boolean,\n): readonly string[] {\n\tif (validPolicy !== OIDS.anyPolicy) {\n\t\treturn parentKeys;\n\t}\n\treturn hasPreviousAnyPolicy ? [previousAnyPolicyKey] : [];\n}\n\n/** Finds all previous-depth nodes whose expectedPolicySet contains the given OID. */\nfunction collectParentsForExpectedPolicy(\n\tnodes: ReadonlyMap<string, PolicyGraphNode>,\n\tpolicyIdentifier: string,\n): string[] {\n\tconst parents: string[] = [];\n\tfor (const [key, node] of nodes) {\n\t\tif (node.expectedPolicySet.has(policyIdentifier)) {\n\t\t\tparents.push(key);\n\t\t}\n\t}\n\treturn parents;\n}\n\n/** Groups all previous-depth nodes by each OID in their expectedPolicySet. */\nfunction collectExpectedPolicyParents(\n\tnodes: ReadonlyMap<string, PolicyGraphNode>,\n): Map<string, string[]> {\n\tconst parentsByPolicy = new Map<string, string[]>();\n\tfor (const [key, node] of nodes) {\n\t\tfor (const expectedPolicy of node.expectedPolicySet) {\n\t\t\tconst parents = parentsByPolicy.get(expectedPolicy);\n\t\t\tif (parents === undefined) {\n\t\t\t\tparentsByPolicy.set(expectedPolicy, [key]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tparents.push(key);\n\t\t}\n\t}\n\treturn parentsByPolicy;\n}\n\n/** Inserts a node at the current depth, or merges parents/expected-policies into an existing one. */\nfunction addOrMergePolicyNode(\n\tgraph: PolicyGraph,\n\tcurrentDepth: Map<string, PolicyGraphNode>,\n\tdepth: number,\n\tvalidPolicy: string,\n\tqualifierSet: readonly PolicyQualifierInfo[] | undefined,\n\tparentKeys: readonly string[],\n\texpectedPolicySet: readonly string[],\n): void {\n\tconst key = policyNodeKey(depth, validPolicy);\n\tconst existing = currentDepth.get(key);\n\tif (existing !== undefined) {\n\t\tfor (const parentKey of parentKeys) {\n\t\t\texisting.parentKeys.add(parentKey);\n\t\t\tgetPolicyGraphNode(graph, parentKey)?.childKeys.add(key);\n\t\t}\n\t\tfor (const expectedPolicy of expectedPolicySet) {\n\t\t\texisting.expectedPolicySet.add(expectedPolicy);\n\t\t}\n\t\tif (existing.qualifierSet === undefined && qualifierSet !== undefined) {\n\t\t\texisting.qualifierSet = qualifierSet;\n\t\t}\n\t\treturn;\n\t}\n\tconst node = createPolicyGraphNode(\n\t\tdepth,\n\t\tvalidPolicy,\n\t\tqualifierSet,\n\t\texpectedPolicySet,\n\t\tparentKeys,\n\t);\n\tcurrentDepth.set(key, node);\n\tfor (const parentKey of parentKeys) {\n\t\tgetPolicyGraphNode(graph, parentKey)?.childKeys.add(key);\n\t}\n}\n\n/** Looks up a node by its `\"depth:oid\"` key, parsing the depth prefix. */\nfunction getPolicyGraphNode(graph: PolicyGraph, key: string): PolicyGraphNode | undefined {\n\tconst separator = key.indexOf(':');\n\tif (separator <= 0) {\n\t\treturn undefined;\n\t}\n\tconst depthString = key.slice(0, separator);\n\tconst depth = Number.parseInt(depthString, 10);\n\tif (Number.isNaN(depth)) {\n\t\treturn undefined;\n\t}\n\treturn graph.nodesByDepth[depth]?.get(key);\n}\n\n/** Removes childless leaf nodes bottom-up, cascading deletions through parent links. */\nfunction prunePolicyGraph(graph: PolicyGraph, maxDepth: number): void {\n\tfor (let depth = maxDepth; depth >= 0; depth -= 1) {\n\t\tconst nodes = graph.nodesByDepth[depth];\n\t\tif (nodes === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const key of nodes.keys()) {\n\t\t\tconst node = nodes.get(key);\n\t\t\tif (node === undefined || node.childKeys.size > 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdeletePolicyGraphNode(graph, key);\n\t\t}\n\t}\n}\n\n/** Removes a node and recursively prunes its parents if they become childless. */\nfunction deletePolicyGraphNode(graph: PolicyGraph, key: string): void {\n\tconst node = getPolicyGraphNode(graph, key);\n\tif (node === undefined) {\n\t\treturn;\n\t}\n\tgraph.nodesByDepth[node.depth]?.delete(key);\n\tfor (const parentKey of node.parentKeys) {\n\t\tconst parent = getPolicyGraphNode(graph, parentKey);\n\t\tif (parent === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tparent.childKeys.delete(key);\n\t\tif (parent.childKeys.size === 0) {\n\t\t\tdeletePolicyGraphNode(graph, parentKey);\n\t\t}\n\t}\n}\n\n/** Applies issuer→subject policy mappings at the current depth, or deletes mapped nodes when disallowed. */\nfunction applyPolicyMappingsStep(\n\tgraph: PolicyGraph,\n\tdepth: number,\n\tmappings: readonly {\n\t\treadonly issuerDomainPolicy: string;\n\t\treadonly subjectDomainPolicy: string;\n\t}[],\n\tmappingAllowed: boolean,\n): void {\n\tconst currentDepth = graph.nodesByDepth[depth];\n\tif (currentDepth === undefined) {\n\t\treturn;\n\t}\n\tconst groupedMappings = new Map<string, string[]>();\n\tfor (const mapping of mappings) {\n\t\tif (\n\t\t\tmapping.issuerDomainPolicy === OIDS.anyPolicy ||\n\t\t\tmapping.subjectDomainPolicy === OIDS.anyPolicy\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst subjectPolicies = groupedMappings.get(mapping.issuerDomainPolicy);\n\t\tif (subjectPolicies === undefined) {\n\t\t\tgroupedMappings.set(mapping.issuerDomainPolicy, [mapping.subjectDomainPolicy]);\n\t\t\tcontinue;\n\t\t}\n\t\tsubjectPolicies.push(mapping.subjectDomainPolicy);\n\t}\n\tconst anyPolicyNode = currentDepth.get(policyNodeKey(depth, OIDS.anyPolicy));\n\tfor (const [issuerDomainPolicy, subjectDomainPolicies] of groupedMappings) {\n\t\tconst nodeKey = policyNodeKey(depth, issuerDomainPolicy);\n\t\tconst node = currentDepth.get(nodeKey);\n\t\tif (mappingAllowed) {\n\t\t\tif (node !== undefined) {\n\t\t\t\tnode.expectedPolicySet = new Set(subjectDomainPolicies);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (anyPolicyNode !== undefined) {\n\t\t\t\taddOrMergePolicyNode(\n\t\t\t\t\tgraph,\n\t\t\t\t\tcurrentDepth,\n\t\t\t\t\tdepth,\n\t\t\t\t\tissuerDomainPolicy,\n\t\t\t\t\tanyPolicyNode.qualifierSet,\n\t\t\t\t\t[...anyPolicyNode.parentKeys],\n\t\t\t\t\tsubjectDomainPolicies,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (node !== undefined) {\n\t\t\tdeletePolicyGraphNode(graph, nodeKey);\n\t\t}\n\t}\n\tprunePolicyGraph(graph, depth - 1);\n}\n\n/** Decrements explicitPolicy / inhibitPolicyMapping / inhibitAnyPolicy and applies policyConstraints overrides. */\nfunction updatePolicyCounters(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n\tisLeaf: boolean,\n): void {\n\tif (isLeaf) {\n\t\tupdateLeafPolicyCounter(state, certificate);\n\t\treturn;\n\t}\n\tif (!isSelfIssued(certificate)) {\n\t\tdecrementPolicyCounters(state);\n\t}\n\tapplyPolicyCounterOverrides(state, certificate);\n}\n\nfunction updateLeafPolicyCounter(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n): void {\n\tdecrementPositiveCounter(state, 'explicitPolicy');\n\tif (certificate.policyConstraints?.requireExplicitPolicy === 0) {\n\t\tstate.explicitPolicy = 0;\n\t}\n}\n\nfunction decrementPolicyCounters(state: PolicyValidationState): void {\n\tdecrementPositiveCounter(state, 'explicitPolicy');\n\tdecrementPositiveCounter(state, 'inhibitPolicyMapping');\n\tdecrementPositiveCounter(state, 'inhibitAnyPolicy');\n}\n\nfunction decrementPositiveCounter(\n\tstate: PolicyValidationState,\n\tkey: 'explicitPolicy' | 'inhibitPolicyMapping' | 'inhibitAnyPolicy',\n): void {\n\tif (state[key] > 0) {\n\t\tstate[key] -= 1;\n\t}\n}\n\nfunction applyPolicyCounterOverrides(\n\tstate: PolicyValidationState,\n\tcertificate: ParsedCertificate,\n): void {\n\tconst policyConstraints = certificate.policyConstraints;\n\tif (\n\t\tisNonNegativeInteger(policyConstraints?.requireExplicitPolicy) &&\n\t\tpolicyConstraints.requireExplicitPolicy < state.explicitPolicy\n\t) {\n\t\tstate.explicitPolicy = policyConstraints.requireExplicitPolicy;\n\t}\n\tif (\n\t\tisNonNegativeInteger(policyConstraints?.inhibitPolicyMapping) &&\n\t\tpolicyConstraints.inhibitPolicyMapping < state.inhibitPolicyMapping\n\t) {\n\t\tstate.inhibitPolicyMapping = policyConstraints.inhibitPolicyMapping;\n\t}\n\tif (\n\t\tisNonNegativeInteger(certificate.inhibitAnyPolicy?.skipCerts) &&\n\t\tcertificate.inhibitAnyPolicy.skipCerts < state.inhibitAnyPolicy\n\t) {\n\t\tstate.inhibitAnyPolicy = certificate.inhibitAnyPolicy.skipCerts;\n\t}\n}\n\nfunction isNonNegativeInteger(value: number | undefined): value is number {\n\treturn value !== undefined && Number.isInteger(value) && value >= 0;\n}\n\n/** A certificate is self-issued when subject and issuer DNs are semantically equal (RFC 5280 §7.1). */\nfunction isSelfIssued(certificate: ParsedCertificate): boolean {\n\treturn compareDistinguishedNames(certificate.subject, certificate.issuer);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuFA,SAAgB,4BACf,GACA,GACwB;CACxB,IAAM,IAAkB,IAAc;CACtC,OAAO;EACN,kBAAkB,EAAM,oBAAoB;EAC5C,gBAAgB,EAAM,0BAA0B,KAAO,IAAI;EAC3D,sBA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 new Map();
79
- for (let e of a) o.set(i[e].oid, e);
78
+ ], o = {
79
+ [r.commonName]: "CN",
80
+ [r.surname]: "SN",
81
+ [r.serialNumber]: "serialNumber",
82
+ [r.countryName]: "C",
83
+ [r.localityName]: "L",
84
+ [r.stateOrProvinceName]: "ST",
85
+ [r.streetAddress]: "STREET",
86
+ [r.organizationName]: "O",
87
+ [r.organizationalUnitName]: "OU",
88
+ [r.title]: "title",
89
+ [r.givenName]: "GN",
90
+ [r.emailAddress]: "emailAddress",
91
+ [r.userId]: "UID",
92
+ [r.domainComponent]: "DC"
93
+ }, s = /* @__PURE__ */ new Map();
94
+ for (let e of a) s.set(i[e].oid, e);
80
95
  /** Resolves a dotted-decimal OID to its {@linkcode NameFieldKey}, or `undefined` if unknown. */
81
96
  function nameFieldKeyFromOid(e) {
82
- return o.get(e);
97
+ return s.get(e);
83
98
  }
84
99
  //#endregion
85
- export { i as NAME_FIELD_DEFINITIONS, a as NAME_OBJECT_ORDER, nameFieldKeyFromOid };
100
+ export { o as DN_ATTRIBUTE_KEYWORDS, i as NAME_FIELD_DEFINITIONS, a as NAME_OBJECT_ORDER, nameFieldKeyFromOid };
86
101
 
87
102
  //# sourceMappingURL=name-fields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"name-fields.js","names":[],"sources":["../../../src/internal/x509/name-fields.ts"],"sourcesContent":["/**\n * Distinguished-name field metadata.\n *\n * Maps friendly {@linkcode NameFieldKey} names to their ASN.1 OIDs and string-encoding functions.\n * @module\n */\n\nimport { ia5String, printableString, utf8String } from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { NameFieldKey } from '#micro509/x509/name';\n\n/**\n * OID and ASN.1 string encoder for one distinguished-name attribute type.\n */\nexport interface NameFieldDefinition {\n\t/** Dotted-decimal OID (e.g. `\"2.5.4.3\"` for commonName). */\n\treadonly oid: string;\n\t/** Encodes the attribute value to the correct ASN.1 string type (UTF8, PrintableString, IA5). */\n\treadonly encode: (value: string) => Uint8Array;\n}\n\n/**\n * Registry mapping every {@linkcode NameFieldKey} to its OID and ASN.1 encoder.\n *\n * Country and serialNumber use PrintableString; emailAddress uses IA5String;\n * all others use UTF8String.\n */\nexport const NAME_FIELD_DEFINITIONS: Record<NameFieldKey, NameFieldDefinition> = {\n\tcommonName: { oid: OIDS.commonName, encode: utf8String },\n\tsurname: { oid: OIDS.surname, encode: utf8String },\n\tserialNumber: { oid: OIDS.serialNumber, encode: printableString },\n\tcountry: { oid: OIDS.countryName, encode: printableString },\n\tlocality: { oid: OIDS.localityName, encode: utf8String },\n\tstate: { oid: OIDS.stateOrProvinceName, encode: utf8String },\n\tstreet: { oid: OIDS.streetAddress, encode: utf8String },\n\torganization: { oid: OIDS.organizationName, encode: utf8String },\n\torganizationalUnit: { oid: OIDS.organizationalUnitName, encode: utf8String },\n\ttitle: { oid: OIDS.title, encode: utf8String },\n\tgivenName: { oid: OIDS.givenName, encode: utf8String },\n\temailAddress: { oid: OIDS.emailAddress, encode: ia5String },\n};\n\n/**\n * Canonical emission order when converting a {@linkcode NameObject} to RDN attributes.\n *\n * Follows the conventional `C/ST/L/STREET/O/OU/CN/…` ordering.\n */\nexport const NAME_OBJECT_ORDER: readonly NameFieldKey[] = [\n\t'country',\n\t'state',\n\t'locality',\n\t'street',\n\t'organization',\n\t'organizationalUnit',\n\t'commonName',\n\t'givenName',\n\t'surname',\n\t'title',\n\t'serialNumber',\n\t'emailAddress',\n];\n\n/** Reverse lookup table: OID string → friendly {@linkcode NameFieldKey}. */\nconst NAME_FIELD_KEYS_BY_OID = new Map<string, NameFieldKey>();\nfor (const key of NAME_OBJECT_ORDER) {\n\tNAME_FIELD_KEYS_BY_OID.set(NAME_FIELD_DEFINITIONS[key].oid, key);\n}\n\n/** Resolves a dotted-decimal OID to its {@linkcode NameFieldKey}, or `undefined` if unknown. */\nexport function nameFieldKeyFromOid(oid: string): NameFieldKey | undefined {\n\treturn NAME_FIELD_KEYS_BY_OID.get(oid);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,IAAoE;CAChF,YAAY;EAAE,KAAK,EAAK;EAAY,QAAQ;CAAW;CACvD,SAAS;EAAE,KAAK,EAAK;EAAS,QAAQ;CAAW;CACjD,cAAc;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAgB;CAChE,SAAS;EAAE,KAAK,EAAK;EAAa,QAAQ;CAAgB;CAC1D,UAAU;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAW;CACvD,OAAO;EAAE,KAAK,EAAK;EAAqB,QAAQ;CAAW;CAC3D,QAAQ;EAAE,KAAK,EAAK;EAAe,QAAQ;CAAW;CACtD,cAAc;EAAE,KAAK,EAAK;EAAkB,QAAQ;CAAW;CAC/D,oBAAoB;EAAE,KAAK,EAAK;EAAwB,QAAQ;CAAW;CAC3E,OAAO;EAAE,KAAK,EAAK;EAAO,QAAQ;CAAW;CAC7C,WAAW;EAAE,KAAK,EAAK;EAAW,QAAQ;CAAW;CACrD,cAAc;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAU;AAC3D,GAOa,IAA6C;CACzD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,GAGM,oBAAyB,IAAI,IAA0B;AAC7D,KAAK,IAAM,KAAO,GACjB,EAAuB,IAAI,EAAuB,EAAI,CAAC,KAAK,CAAG;;AAIhE,SAAgB,oBAAoB,GAAuC;CAC1E,OAAO,EAAuB,IAAI,CAAG;AACtC"}
1
+ {"version":3,"file":"name-fields.js","names":[],"sources":["../../../src/internal/x509/name-fields.ts"],"sourcesContent":["/**\n * Distinguished-name field metadata.\n *\n * Maps friendly {@linkcode NameFieldKey} names to their ASN.1 OIDs and string-encoding functions.\n * @module\n */\n\nimport { ia5String, printableString, utf8String } from '#micro509/internal/asn1/der';\nimport { OIDS } from '#micro509/internal/asn1/oids';\nimport type { NameFieldKey } from '#micro509/x509/name';\n\n/**\n * OID and ASN.1 string encoder for one distinguished-name attribute type.\n */\nexport interface NameFieldDefinition {\n\t/** Dotted-decimal OID (e.g. `\"2.5.4.3\"` for commonName). */\n\treadonly oid: string;\n\t/** Encodes the attribute value to the correct ASN.1 string type (UTF8, PrintableString, IA5). */\n\treadonly encode: (value: string) => Uint8Array;\n}\n\n/**\n * Registry mapping every {@linkcode NameFieldKey} to its OID and ASN.1 encoder.\n *\n * Country and serialNumber use PrintableString; emailAddress uses IA5String;\n * all others use UTF8String.\n */\nexport const NAME_FIELD_DEFINITIONS: Record<NameFieldKey, NameFieldDefinition> = {\n\tcommonName: { oid: OIDS.commonName, encode: utf8String },\n\tsurname: { oid: OIDS.surname, encode: utf8String },\n\tserialNumber: { oid: OIDS.serialNumber, encode: printableString },\n\tcountry: { oid: OIDS.countryName, encode: printableString },\n\tlocality: { oid: OIDS.localityName, encode: utf8String },\n\tstate: { oid: OIDS.stateOrProvinceName, encode: utf8String },\n\tstreet: { oid: OIDS.streetAddress, encode: utf8String },\n\torganization: { oid: OIDS.organizationName, encode: utf8String },\n\torganizationalUnit: { oid: OIDS.organizationalUnitName, encode: utf8String },\n\ttitle: { oid: OIDS.title, encode: utf8String },\n\tgivenName: { oid: OIDS.givenName, encode: utf8String },\n\temailAddress: { oid: OIDS.emailAddress, encode: ia5String },\n};\n\n/**\n * Canonical emission order when converting a {@linkcode NameObject} to RDN attributes.\n *\n * Follows the conventional `C/ST/L/STREET/O/OU/CN/…` ordering.\n */\nexport const NAME_OBJECT_ORDER: readonly NameFieldKey[] = [\n\t'country',\n\t'state',\n\t'locality',\n\t'street',\n\t'organization',\n\t'organizationalUnit',\n\t'commonName',\n\t'givenName',\n\t'surname',\n\t'title',\n\t'serialNumber',\n\t'emailAddress',\n];\n\n/**\n * Display keyword for a DN attribute type, keyed by OID.\n *\n * RFC 4514 [§3](https://datatracker.ietf.org/doc/html/rfc4514#section-3) defines\n * `CN`, `L`, `ST`, `O`, `OU`, `C`, `STREET`, `DC`, and `UID`; the rest are the short\n * names `openssl` prints for attribute types the RFC leaves to the dotted OID.\n */\nexport const DN_ATTRIBUTE_KEYWORDS: Readonly<Record<string, string>> = {\n\t[OIDS.commonName]: 'CN',\n\t[OIDS.surname]: 'SN',\n\t[OIDS.serialNumber]: 'serialNumber',\n\t[OIDS.countryName]: 'C',\n\t[OIDS.localityName]: 'L',\n\t[OIDS.stateOrProvinceName]: 'ST',\n\t[OIDS.streetAddress]: 'STREET',\n\t[OIDS.organizationName]: 'O',\n\t[OIDS.organizationalUnitName]: 'OU',\n\t[OIDS.title]: 'title',\n\t[OIDS.givenName]: 'GN',\n\t[OIDS.emailAddress]: 'emailAddress',\n\t[OIDS.userId]: 'UID',\n\t[OIDS.domainComponent]: 'DC',\n};\n\n/** Reverse lookup table: OID string → friendly {@linkcode NameFieldKey}. */\nconst NAME_FIELD_KEYS_BY_OID = new Map<string, NameFieldKey>();\nfor (const key of NAME_OBJECT_ORDER) {\n\tNAME_FIELD_KEYS_BY_OID.set(NAME_FIELD_DEFINITIONS[key].oid, key);\n}\n\n/** Resolves a dotted-decimal OID to its {@linkcode NameFieldKey}, or `undefined` if unknown. */\nexport function nameFieldKeyFromOid(oid: string): NameFieldKey | undefined {\n\treturn NAME_FIELD_KEYS_BY_OID.get(oid);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAa,IAAoE;CAChF,YAAY;EAAE,KAAK,EAAK;EAAY,QAAQ;CAAW;CACvD,SAAS;EAAE,KAAK,EAAK;EAAS,QAAQ;CAAW;CACjD,cAAc;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAgB;CAChE,SAAS;EAAE,KAAK,EAAK;EAAa,QAAQ;CAAgB;CAC1D,UAAU;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAW;CACvD,OAAO;EAAE,KAAK,EAAK;EAAqB,QAAQ;CAAW;CAC3D,QAAQ;EAAE,KAAK,EAAK;EAAe,QAAQ;CAAW;CACtD,cAAc;EAAE,KAAK,EAAK;EAAkB,QAAQ;CAAW;CAC/D,oBAAoB;EAAE,KAAK,EAAK;EAAwB,QAAQ;CAAW;CAC3E,OAAO;EAAE,KAAK,EAAK;EAAO,QAAQ;CAAW;CAC7C,WAAW;EAAE,KAAK,EAAK;EAAW,QAAQ;CAAW;CACrD,cAAc;EAAE,KAAK,EAAK;EAAc,QAAQ;CAAU;AAC3D,GAOa,IAA6C;CACzD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,GASa,IAA0D;EACrE,EAAK,aAAa;EAClB,EAAK,UAAU;EACf,EAAK,eAAe;EACpB,EAAK,cAAc;EACnB,EAAK,eAAe;EACpB,EAAK,sBAAsB;EAC3B,EAAK,gBAAgB;EACrB,EAAK,mBAAmB;EACxB,EAAK,yBAAyB;EAC9B,EAAK,QAAQ;EACb,EAAK,YAAY;EACjB,EAAK,eAAe;EACpB,EAAK,SAAS;EACd,EAAK,kBAAkB;AACzB,GAGM,oBAAyB,IAAI,IAA0B;AAC7D,KAAK,IAAM,KAAO,GACjB,EAAuB,IAAI,EAAuB,EAAI,CAAC,KAAK,CAAG;;AAIhE,SAAgB,oBAAoB,GAAuC;CAC1E,OAAO,EAAuB,IAAI,CAAG;AACtC"}
@@ -465,7 +465,7 @@ function sameDistributionPointName(e, t) {
465
465
  /** Set-equality comparison for GeneralName arrays (order-independent). */
466
466
  function sameGeneralNameSet(e, t) {
467
467
  if (e.length !== t.length) return !1;
468
- let n = Array(t.length).fill(!1);
468
+ let n = Array.from({ length: t.length }, () => !1);
469
469
  for (let r of e) {
470
470
  let e = !1;
471
471
  for (let i = 0; i < t.length; i += 1) {
@@ -505,7 +505,7 @@ function bytesEqual(e, t) {
505
505
  /** Set-equality comparison for RDN attribute sets (order-independent, RFC 4518 string prep). */
506
506
  function compareRelativeDistinguishedNames(e, t) {
507
507
  if (e.attributes.length !== t.attributes.length) return !1;
508
- let n = Array(t.attributes.length).fill(!1);
508
+ let n = Array.from({ length: t.attributes.length }, () => !1);
509
509
  for (let r of e.attributes) {
510
510
  let e = !1;
511
511
  for (let i = 0; i < t.attributes.length; i += 1) {