micro509 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +8 -8
  2. package/dist/index.d.ts +6 -6
  3. package/dist/index.js +1 -1
  4. package/dist/internal/asn1/oids.js +1 -1
  5. package/dist/internal/asn1/oids.js.map +1 -1
  6. package/dist/internal/crypto/pbes2.js +1 -1
  7. package/dist/internal/crypto/pbes2.js.map +1 -1
  8. package/dist/internal/crypto/sig-verify.js +1 -1
  9. package/dist/internal/crypto/sig-verify.js.map +1 -1
  10. package/dist/keys/keys.d.ts +72 -100
  11. package/dist/keys/keys.js +3 -3
  12. package/dist/keys/keys.js.map +1 -1
  13. package/dist/keys.d.ts +2 -2
  14. package/dist/pkcs/pfx.d.ts +31 -5
  15. package/dist/pkcs/pfx.js +1 -1
  16. package/dist/pkcs/pfx.js.map +1 -1
  17. package/dist/pkcs/pkcs7.d.ts +111 -5
  18. package/dist/pkcs/pkcs7.js +1 -1
  19. package/dist/pkcs/pkcs7.js.map +1 -1
  20. package/dist/pkcs.d.ts +3 -3
  21. package/dist/pkcs.js +1 -1
  22. package/dist/result/result.d.ts +54 -1
  23. package/dist/result/result.js +1 -1
  24. package/dist/result/result.js.map +1 -1
  25. package/dist/result.d.ts +2 -2
  26. package/dist/result.js +1 -1
  27. package/dist/revocation/crl.js +1 -1
  28. package/dist/revocation/crl.js.map +1 -1
  29. package/dist/revocation/ocsp.js +1 -1
  30. package/dist/revocation/ocsp.js.map +1 -1
  31. package/dist/revocation/revocation.js +1 -1
  32. package/dist/revocation/revocation.js.map +1 -1
  33. package/dist/verify/identity.js +1 -1
  34. package/dist/verify/identity.js.map +1 -1
  35. package/dist/verify/verify.js +1 -1
  36. package/dist/verify/verify.js.map +1 -1
  37. package/dist/x509/parse.d.ts +35 -21
  38. package/dist/x509/parse.js +1 -1
  39. package/dist/x509/parse.js.map +1 -1
  40. package/dist/x509.d.ts +2 -2
  41. package/package.json +37 -22
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <picture>
2
- <source media="(prefers-color-scheme: dark)" srcset="https://github.com/kjanat/ts-x509/raw/c5720af044fd9cc8f3c33e3bb91f79e6d5567454/site/assets/icon-light.svg">
3
- <source media="(prefers-color-scheme: light)" srcset="https://github.com/kjanat/ts-x509/raw/c5720af044fd9cc8f3c33e3bb91f79e6d5567454/site/assets/icon.svg">
4
- <img alt="" src="https://github.com/kjanat/ts-x509/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/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">
5
5
  </picture>
6
6
 
7
7
  # micro509
@@ -43,7 +43,7 @@ And when verification fails, you get typed results your code
43
43
  can act on: [21 error codes], the failing certificate index,
44
44
  and structured failure details instead of `false`.
45
45
 
46
- [21 error codes]: https://micro509.kjanat.com/guide/verification#error-codes
46
+ [21 error codes]: https://micro509.kjanat.dev/guide/verification#error-codes
47
47
 
48
48
  ```ts
49
49
  if (!result.ok) {
@@ -58,7 +58,7 @@ in a single zero-dependency JS package:
58
58
 
59
59
  - **OCSP** — build requests, parse and validate responses, verify responder authorization
60
60
  - **PFX / PKCS#12** — create and parse password-protected key+cert bundles
61
- - **PKCS#7 / CMS** — parse SignedData, verify signer signatures, extract cert bags
61
+ - **PKCS#7 / CMS** — sign content, parse and verify SignedData, extract cert bags
62
62
  - **CRLs** — create, parse, verify, and check revocation status
63
63
  - **Encrypted keys** — PBES2 PKCS#8, legacy OpenSSL encrypted PEM, PKCS#1, SEC1
64
64
  - **Key import/export** — PKCS#8, SPKI, JWK, PKCS#1, SEC1 with generation for RSA, ECDSA, Ed25519
@@ -182,7 +182,7 @@ It intentionally excludes niche, blockchain-specific, or key-agreement-only prim
182
182
  | RFC 9618 policy validation | partial |
183
183
 
184
184
  See [`docs/PKIX-SCOPE.md`](./docs/PKIX-SCOPE.md) for the detailed scope boundary
185
- and the [API reference](https://micro509.kjanat.com/api/) for the public module surface.
185
+ and the [API reference](https://micro509.kjanat.dev/api/) for the public module surface.
186
186
 
187
187
  ## Imports
188
188
 
@@ -205,11 +205,11 @@ import { pemDecode, pemEncode } from 'micro509/pem';
205
205
  import type { Micro509Error } from 'micro509/result';
206
206
  ```
207
207
 
208
- The full stable subpath list lives in the [API reference](https://micro509.kjanat.com/api/).
208
+ The full stable subpath list lives in the [API reference](https://micro509.kjanat.dev/api/).
209
209
 
210
210
  ## More docs
211
211
 
212
- - API reference: [micro509.kjanat.com/api](https://micro509.kjanat.com/api/)
212
+ - API reference: [micro509.kjanat.dev/api](https://micro509.kjanat.dev/api/)
213
213
  - Standards scope: [`docs/PKIX-SCOPE.md`](./docs/PKIX-SCOPE.md)
214
214
  - PKITS harness: [`test/pkits.test.ts`](./test/pkits.test.ts)
215
215
  - Differential harness: [`test/differential.test.ts`](./test/differential.test.ts)
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Pbes2EncryptionOptions, Pbes2EncryptionScheme, Pbes2Prf } from "./internal/crypto/pbes2.js";
2
- import { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcPublicKeyInput, ImportEd25519PublicKeyInput, ImportRsaPublicKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem } from "./keys/keys.js";
2
+ import { ErrorResult, IndexedErrorResult, IndexedMicro509Error, Micro509Error, Result, ResultError, isResultError, unwrap, unwrapOr } from "./result/result.js";
3
+ import { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcPublicKeyInput, ImportEd25519PublicKeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaPublicKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem } from "./keys/keys.js";
3
4
  import { CategorizedPemBlocks, PemBlock, categorizePemBlocks, pemDecode, pemEncode, splitPemBlocks } from "./pem/pem.js";
4
- import { ErrorResult, IndexedErrorResult, IndexedMicro509Error, Micro509Error, Result } from "./result/result.js";
5
5
  import { NameAttribute, NameFieldKey, NameInput, NameObject, RelativeDistinguishedNameInput } from "./x509/name.js";
6
6
  import { AuthorityInformationAccess, BasicConstraints, CertificateExtensionsInput, CertificatePolicies, DistributionPoint, DistributionPointName, ExtendedKeyUsage, GeneralName, GeneralSubtree, InhibitAnyPolicy, IssuingDistributionPoint, KeyUsage, NameConstraintForm, NameConstraints, ParsedNameConstraintForm, PolicyConstraints, PolicyInformation, PolicyMapping, PolicyMappings, PolicyQualifierInfo, SubjectAltName } from "./x509/extensions.js";
7
7
  import { ParsedBitFlags } from "./internal/x509/extension-bits.js";
8
- import { DecodedExtensionMap, DecodedExtensionValue, ExtensionDecoder, ExtensionDecoderMap, ParseOptions, ParsedCertificate, ParsedCertificateSigningRequest, ParsedDistributionPoint, ParsedDistributionPointName, ParsedExtension, ParsedIssuingDistributionPoint, ParsedName, ParsedNameAttribute, ParsedRelativeDistinguishedName, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem } from "./x509/parse.js";
9
- import { CreatePfxInput, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, createPfx, parsePfxDer, parsePfxPem } from "./pkcs/pfx.js";
10
- import { ParsePkcs7CertBagResult, ParsePkcs7ErrorCode, ParsePkcs7Failure, ParsePkcs7SignedDataResult, ParsedPkcs7SignedData, ParsedPkcs7SignerInfo, Pkcs7CertBag, Pkcs7CertificateSource, VerifyPkcs7SignedDataFailure, VerifyPkcs7SignedDataResult, createPkcs7CertBagDer, createPkcs7CertBagPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, verifyPkcs7SignedData } from "./pkcs/pkcs7.js";
8
+ import { DecodedExtensionMap, DecodedExtensionValue, ExtensionDecoder, ExtensionDecoderMap, ParseCertificateErrorCode, ParseCertificateFailure, ParseCertificateResult, ParseCertificateSigningRequestErrorCode, ParseCertificateSigningRequestFailure, ParseCertificateSigningRequestResult, ParseOptions, ParsedCertificate, ParsedCertificateSigningRequest, ParsedDistributionPoint, ParsedDistributionPointName, ParsedExtension, ParsedIssuingDistributionPoint, ParsedName, ParsedNameAttribute, ParsedRelativeDistinguishedName, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, findExtension, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem } from "./x509/parse.js";
9
+ import { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, createPfx, parsePfxDer, parsePfxPem } from "./pkcs/pfx.js";
10
+ import { CreatePkcs7CertBagDerResult, CreatePkcs7CertBagErrorCode, CreatePkcs7CertBagFailure, CreatePkcs7CertBagResult, CreatePkcs7SignedDataDerResult, CreatePkcs7SignedDataErrorCode, CreatePkcs7SignedDataFailure, CreatePkcs7SignedDataInput, CreatePkcs7SignedDataResult, ParsePkcs7CertBagResult, ParsePkcs7ErrorCode, ParsePkcs7Failure, ParsePkcs7SignedDataResult, ParsedPkcs7SignedData, ParsedPkcs7SignerInfo, Pkcs7CertBag, Pkcs7CertificateSource, Pkcs7SignedDataMaterial, Pkcs7Signer, VerifyPkcs7SignedDataFailure, VerifyPkcs7SignedDataResult, createPkcs7CertBagDer, createPkcs7CertBagPem, createPkcs7SignedDataDer, createPkcs7SignedDataPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, verifyPkcs7SignedData } from "./pkcs/pkcs7.js";
11
11
  import { CertificateRevocationListMaterial, CheckCertificateRevocationAgainstCrlInput, CheckCertificateRevocationAgainstCrlResult, CreateCertificateRevocationListInput, CrlCertificateSource, CrlSource, ParsedCertificateRevocationList, ParsedRevokedCertificate, RevocationReason, RevokedCertificateInput, ValidateCertificateRevocationListFailure, ValidateCertificateRevocationListInput, ValidateCertificateRevocationListResult, VerifyCertificateRevocationListFailure, VerifyCertificateRevocationListResult, checkCertificateRevocationAgainstCrl, createCertificateRevocationList, isCertificateRevoked, parseCertificateRevocationListDer, parseCertificateRevocationListPem, validateCertificateRevocationList, verifyCertificateRevocationList } from "./revocation/crl.js";
12
12
  import { CreateOcspRequestInput, CreateOcspRequestItemInput, CreateOcspResponseInput, CreateOcspSingleResponseInput, OcspCertStatus, OcspCertificateSource, OcspRequestMaterial, OcspRequestSource, OcspResponseMaterial, ParsedOcspCertId, ParsedOcspRequest, ParsedOcspResponderId, ParsedOcspResponse, ParsedOcspSingleResponse, ValidateOcspResponseFailure, ValidateOcspResponseInput, ValidateOcspResponseResult, VerifyOcspResponseFailure, VerifyOcspResponseResult, createOcspRequest, createOcspResponse, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, validateOcspResponse, verifyOcspResponse } from "./revocation/ocsp.js";
13
13
  import { CheckCertificateRevocationInput, CheckCertificateRevocationResult, ConfiguredOcspResponder, OcspResponderCandidate, OcspResponderSource, ResolveOcspResponderCandidatesInput, RevocationCertificateSource, RevocationCrlEvidenceInput, RevocationEvidenceInput, RevocationEvidenceKind, RevocationOcspEvidenceInput, RevocationStatus, checkCertificateRevocation, getCertificateOcspResponderUris, resolveOcspResponderCandidates } from "./revocation/revocation.js";
@@ -18,4 +18,4 @@ import { PolicyValidationInput } from "./verify/policy.js";
18
18
  import { BuildCandidatePathInput, BuildCandidatePathResult, CandidatePath, CertificateSource, ChainRevocationInput, CsrSource, EkuCheckFailure, EkuCheckPurpose, EkuCheckResult, TrustAnchor, 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 { CertificateMaterial, CreateCertificateInput, CreateSelfSignedCertificateInput, SelfSignedCertificateResult, ValidityInput, createCertificate, createSelfSignedCertificate } from "./x509/certificate.js";
20
20
  import { CreateCsrInput, CsrMaterial, createCertificateSigningRequest } from "./x509/csr.js";
21
- export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxInput, type CreateSelfSignedCertificateInput, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcPublicKeyInput, type ImportEd25519PublicKeyInput, type ImportRsaPublicKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, 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 OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderSource, type OcspResponseMaterial, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, 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 ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Prf, type PemBlock, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs7CertBag, type Pkcs7CertificateSource, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PrivateKeyImportInput, type PublicKeyImportInput, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type RevocationCertificateSource, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateReason, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SrvServiceIdentityInput, type SubjectAltName, type TrustAnchor, type UriServiceIdentityInput, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListFailure, type VerifyCertificateRevocationListResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseFailure, type VerifyOcspResponseResult, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, type VerifyServiceIdentityInput, buildCandidatePath, categorizePemBlocks, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBagDer, createPkcs7CertBagPem, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem, isCertificateRevoked, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateRevocationListDer, parseCertificateRevocationListPem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemEncode, resolveOcspResponderCandidates, splitPemBlocks, trustAnchorFromCertificate, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationList, verifyCertificateSigningRequest, verifyOcspResponse, verifyPkcs7SignedData };
21
+ export { type AuthorityInformationAccess, type BasicConstraints, type BuildCandidatePathInput, type BuildCandidatePathResult, type CandidatePath, type CategorizedPemBlocks, type CertificateExtensionsInput, type CertificateMaterial, type CertificatePolicies, type CertificateRevocationListMaterial, type CertificateRevocationStatus, type CertificateSource, type ChainRevocationInput, type CheckCertificateRevocationAgainstCrlInput, type CheckCertificateRevocationAgainstCrlResult, type CheckCertificateRevocationInput, type CheckCertificateRevocationResult, type CheckChainRevocationInput, type CheckChainRevocationResult, type CheckChainRevocationValue, type ConfiguredOcspResponder, type CreateCertificateInput, type CreateCertificateRevocationListInput, type CreateCsrInput, type CreateOcspRequestInput, type CreateOcspRequestItemInput, type CreateOcspResponseInput, type CreateOcspSingleResponseInput, type CreatePfxErrorCode, type CreatePfxFailure, type CreatePfxInput, type CreatePfxResult, type CreatePkcs7CertBagDerResult, type CreatePkcs7CertBagErrorCode, type CreatePkcs7CertBagFailure, type CreatePkcs7CertBagResult, type CreatePkcs7SignedDataDerResult, type CreatePkcs7SignedDataErrorCode, type CreatePkcs7SignedDataFailure, type CreatePkcs7SignedDataInput, type CreatePkcs7SignedDataResult, type CreateSelfSignedCertificateInput, type CrlCertificateSource, type CrlSource, type CsrMaterial, type CsrSource, type DecodedExtensionMap, type DecodedExtensionValue, type DistributionPoint, type DistributionPointName, type DnsServiceIdentityInput, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EkuCheckFailure, type EkuCheckPurpose, type EkuCheckResult, type EncryptedPkcs8Options, type ErrorResult, type ExtendedKeyUsage, type ExtensionDecoder, type ExtensionDecoderMap, type GeneralName, type GeneralSubtree, type ImportEcPublicKeyInput, type ImportEd25519PublicKeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaPublicKeyInput, type IndexedErrorResult, type IndexedMicro509Error, type InhibitAnyPolicy, type InitialNameConstraintsInput, type IpServiceIdentityInput, type IssuingDistributionPoint, type KeyAlgorithmInput, type KeyPairMaterial, type KeyUsage, type LegacyPemEncryptionOptions, type MatchServiceIdentityErrorCode, type MatchServiceIdentityFailure, 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 OcspRequestMaterial, type OcspRequestSource, type OcspResponderCandidate, type OcspResponderSource, type OcspResponseMaterial, type ParseCertificateErrorCode, type ParseCertificateFailure, type ParseCertificateResult, type ParseCertificateSigningRequestErrorCode, type ParseCertificateSigningRequestFailure, type ParseCertificateSigningRequestResult, type ParseOptions, type ParsePfxErrorCode, type ParsePfxFailure, type ParsePfxOptions, type ParsePfxResult, 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 ParsedPkcs7SignedData, type ParsedPkcs7SignerInfo, type ParsedRelativeDistinguishedName, type ParsedRevokedCertificate, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Prf, type PemBlock, type PfxBagAttributesInput, type PfxCertificateBagInput, type PfxCertificateSource, type PfxEncryptionOptions, type PfxMaterial, type PfxPrivateKeyBagInput, type PfxPrivateKeySource, type Pkcs7CertBag, type Pkcs7CertificateSource, type Pkcs7SignedDataMaterial, type Pkcs7Signer, type PolicyConstraints, type PolicyInformation, type PolicyMapping, type PolicyMappings, type PolicyQualifierInfo, type PolicyValidationInput, type PrivateKeyImportInput, type PublicKeyImportInput, type RelativeDistinguishedNameInput, type ResolveOcspResponderCandidatesInput, type Result, type ResultError, type RevocationCertificateSource, type RevocationCrlEvidenceInput, type RevocationEvidenceInput, type RevocationEvidenceKind, type RevocationExecutionError, type RevocationIndeterminateReason, type RevocationOcspEvidenceInput, type RevocationPolicy, type RevocationReason, type RevocationSource, type RevocationStatus, type RevokedCertificateInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaScheme, type SelfSignedCertificateResult, type ServiceIdentityInput, type ServiceIdentityType, type SrvServiceIdentityInput, type SubjectAltName, type TrustAnchor, type UriServiceIdentityInput, type ValidateCandidatePathInput, type ValidateCandidatePathResult, type ValidateCandidatePathSuccess, type ValidateCertificateRevocationListFailure, type ValidateCertificateRevocationListInput, type ValidateCertificateRevocationListResult, type ValidateForCaInput, type ValidateForCodeSigningInput, type ValidateForTlsClientInput, type ValidateForTlsServerInput, type ValidateOcspResponseFailure, type ValidateOcspResponseInput, type ValidateOcspResponseResult, type ValidityInput, type VerifiedCertificateChain, type VerifyCertificateChainInput, type VerifyCertificateRevocationListFailure, type VerifyCertificateRevocationListResult, type VerifyChainFailure, type VerifyChainResult, type VerifyErrorCode, type VerifyFailureDetails, type VerifyOcspResponseFailure, type VerifyOcspResponseResult, type VerifyPkcs7SignedDataFailure, type VerifyPkcs7SignedDataResult, type VerifyPurpose, type VerifyRequestFailure, type VerifyRequestResult, type VerifyServiceIdentityInput, buildCandidatePath, categorizePemBlocks, checkCertificateRevocation, checkCertificateRevocationAgainstCrl, checkChainRevocation, checkExtendedKeyUsage, createCertificate, createCertificateRevocationList, createCertificateSigningRequest, createOcspRequest, createOcspResponse, createPfx, createPkcs7CertBagDer, createPkcs7CertBagPem, createPkcs7SignedDataDer, createPkcs7SignedDataPem, createSelfSignedCertificate, decodeExtension, decodeExtensionMap, decodeExtensions, defineExtensionDecoder, defineExtensionDecoderMap, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, findExtension, generateKeyPair, getCertificateOcspResponderUris, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem, isCertificateRevoked, isResultError, matchCertificateServiceIdentity, matchServiceIdentity, parseCertificateChainPem, parseCertificateDer, parseCertificatePem, parseCertificateRevocationListDer, parseCertificateRevocationListPem, parseCertificateSigningRequestDer, parseCertificateSigningRequestPem, parseOcspRequestDer, parseOcspRequestPem, parseOcspResponseDer, parseOcspResponsePem, parsePfxDer, parsePfxPem, parsePkcs7CertBagDer, parsePkcs7CertBagPem, parsePkcs7SignedDataDer, parsePkcs7SignedDataPem, pemDecode, pemEncode, resolveOcspResponderCandidates, splitPemBlocks, trustAnchorFromCertificate, unwrap, unwrapOr, validateCandidatePath, validateCertificateRevocationList, validateForCa, validateForCodeSigning, validateForTlsClient, validateForTlsServer, validateOcspResponse, verifyCertificateChain, verifyCertificateRevocationList, verifyCertificateSigningRequest, verifyOcspResponse, verifyPkcs7SignedData };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{categorizePemBlocks as e,pemDecode as t,pemEncode as n,splitPemBlocks as r}from"./pem/pem.js";import{exportBinaryBase64 as i,exportEncryptedPkcs1Pem as a,exportEncryptedPkcs8Der as o,exportEncryptedPkcs8Pem as s,exportEncryptedSec1Pem as c,exportPkcs1Der as l,exportPkcs1Pem as u,exportPkcs8Der as d,exportPkcs8Pem as f,exportPrivateJwk as p,exportPublicJwk as m,exportSec1Der as h,exportSec1Pem as g,exportSpkiDer as _,exportSpkiPem as v,generateKeyPair as y,importEncryptedPkcs1Pem as b,importEncryptedPkcs8Der as x,importEncryptedPkcs8Pem as S,importEncryptedSec1Pem as C,importPkcs1Der as w,importPkcs1Pem as T,importPkcs8Base64 as E,importPkcs8Der as D,importPkcs8Pem as O,importPrivateJwk as k,importPublicJwk as A,importSec1Der as j,importSec1Pem as M,importSpkiBase64 as N,importSpkiDer as P,importSpkiPem as F}from"./keys/keys.js";import{decodeExtension as I,decodeExtensionMap as L,decodeExtensions as R,defineExtensionDecoder as z,defineExtensionDecoderMap as B,findExtension as V,parseCertificateChainPem as H,parseCertificateDer as U,parseCertificatePem as W,parseCertificateSigningRequestDer as G,parseCertificateSigningRequestPem as K}from"./x509/parse.js";import{createPfx as q,parsePfxDer as J,parsePfxPem as Y}from"./pkcs/pfx.js";import{createPkcs7CertBagDer as X,createPkcs7CertBagPem as Z,parsePkcs7CertBagDer as Q,parsePkcs7CertBagPem as $,parsePkcs7SignedDataDer as ee,parsePkcs7SignedDataPem as te,verifyPkcs7SignedData as ne}from"./pkcs/pkcs7.js";import{checkCertificateRevocationAgainstCrl as re,createCertificateRevocationList as ie,isCertificateRevoked as ae,parseCertificateRevocationListDer as oe,parseCertificateRevocationListPem as se,validateCertificateRevocationList as ce,verifyCertificateRevocationList as le}from"./revocation/crl.js";import{checkChainRevocation as ue}from"./revocation/chain.js";import{matchCertificateServiceIdentity as de,matchServiceIdentity as fe}from"./verify/identity.js";import{buildCandidatePath as pe,checkExtendedKeyUsage as me,trustAnchorFromCertificate as he,validateCandidatePath as ge,validateForCa as _e,validateForCodeSigning as ve,validateForTlsClient as ye,validateForTlsServer as be,verifyCertificateChain as xe,verifyCertificateSigningRequest as Se}from"./verify/verify.js";import{createOcspRequest as Ce,createOcspResponse as we,parseOcspRequestDer as Te,parseOcspRequestPem as Ee,parseOcspResponseDer as De,parseOcspResponsePem as Oe,validateOcspResponse as ke,verifyOcspResponse as Ae}from"./revocation/ocsp.js";import{checkCertificateRevocation as je,getCertificateOcspResponderUris as Me,resolveOcspResponderCandidates as Ne}from"./revocation/revocation.js";import{createCertificate as Pe,createSelfSignedCertificate as Fe}from"./x509/certificate.js";import{createCertificateSigningRequest as Ie}from"./x509/csr.js";export{pe as buildCandidatePath,e as categorizePemBlocks,je as checkCertificateRevocation,re as checkCertificateRevocationAgainstCrl,ue as checkChainRevocation,me as checkExtendedKeyUsage,Pe as createCertificate,ie as createCertificateRevocationList,Ie as createCertificateSigningRequest,Ce as createOcspRequest,we as createOcspResponse,q as createPfx,X as createPkcs7CertBagDer,Z as createPkcs7CertBagPem,Fe as createSelfSignedCertificate,I as decodeExtension,L as decodeExtensionMap,R as decodeExtensions,z as defineExtensionDecoder,B as defineExtensionDecoderMap,i as exportBinaryBase64,a as exportEncryptedPkcs1Pem,o as exportEncryptedPkcs8Der,s as exportEncryptedPkcs8Pem,c as exportEncryptedSec1Pem,l as exportPkcs1Der,u as exportPkcs1Pem,d as exportPkcs8Der,f as exportPkcs8Pem,p as exportPrivateJwk,m as exportPublicJwk,h as exportSec1Der,g as exportSec1Pem,_ as exportSpkiDer,v as exportSpkiPem,V as findExtension,y as generateKeyPair,Me as getCertificateOcspResponderUris,b as importEncryptedPkcs1Pem,x as importEncryptedPkcs8Der,S as importEncryptedPkcs8Pem,C as importEncryptedSec1Pem,w as importPkcs1Der,T as importPkcs1Pem,E as importPkcs8Base64,D as importPkcs8Der,O as importPkcs8Pem,k as importPrivateJwk,A as importPublicJwk,j as importSec1Der,M as importSec1Pem,N as importSpkiBase64,P as importSpkiDer,F as importSpkiPem,ae as isCertificateRevoked,de as matchCertificateServiceIdentity,fe as matchServiceIdentity,H as parseCertificateChainPem,U as parseCertificateDer,W as parseCertificatePem,oe as parseCertificateRevocationListDer,se as parseCertificateRevocationListPem,G as parseCertificateSigningRequestDer,K as parseCertificateSigningRequestPem,Te as parseOcspRequestDer,Ee as parseOcspRequestPem,De as parseOcspResponseDer,Oe as parseOcspResponsePem,J as parsePfxDer,Y as parsePfxPem,Q as parsePkcs7CertBagDer,$ as parsePkcs7CertBagPem,ee as parsePkcs7SignedDataDer,te as parsePkcs7SignedDataPem,t as pemDecode,n as pemEncode,Ne as resolveOcspResponderCandidates,r as splitPemBlocks,he as trustAnchorFromCertificate,ge as validateCandidatePath,ce as validateCertificateRevocationList,_e as validateForCa,ve as validateForCodeSigning,ye as validateForTlsClient,be as validateForTlsServer,ke as validateOcspResponse,xe as verifyCertificateChain,le as verifyCertificateRevocationList,Se as verifyCertificateSigningRequest,Ae as verifyOcspResponse,ne as verifyPkcs7SignedData};
1
+ import{categorizePemBlocks as e,pemDecode as t,pemEncode as n,splitPemBlocks as r}from"./pem/pem.js";import{isResultError as i,unwrap as a,unwrapOr as o}from"./result/result.js";import{exportBinaryBase64 as s,exportEncryptedPkcs1Pem as c,exportEncryptedPkcs8Der as l,exportEncryptedPkcs8Pem as u,exportEncryptedSec1Pem as d,exportPkcs1Der as f,exportPkcs1Pem as p,exportPkcs8Der as m,exportPkcs8Pem as h,exportPrivateJwk as g,exportPublicJwk as _,exportSec1Der as v,exportSec1Pem as y,exportSpkiDer as b,exportSpkiPem as x,generateKeyPair as S,importEncryptedPkcs1Pem as C,importEncryptedPkcs8Der as w,importEncryptedPkcs8Pem as T,importEncryptedSec1Pem as E,importPkcs1Der as D,importPkcs1Pem as O,importPkcs8Base64 as k,importPkcs8Der as A,importPkcs8Pem as j,importPrivateJwk as M,importPublicJwk as N,importSec1Der as P,importSec1Pem as F,importSpkiBase64 as I,importSpkiDer as L,importSpkiPem as R}from"./keys/keys.js";import{decodeExtension as z,decodeExtensionMap as B,decodeExtensions as V,defineExtensionDecoder as H,defineExtensionDecoderMap as U,findExtension as W,parseCertificateChainPem as G,parseCertificateDer as K,parseCertificatePem as q,parseCertificateSigningRequestDer as J,parseCertificateSigningRequestPem as Y}from"./x509/parse.js";import{createPfx as X,parsePfxDer as Z,parsePfxPem as Q}from"./pkcs/pfx.js";import{createPkcs7CertBagDer as $,createPkcs7CertBagPem as ee,createPkcs7SignedDataDer as te,createPkcs7SignedDataPem as ne,parsePkcs7CertBagDer as re,parsePkcs7CertBagPem as ie,parsePkcs7SignedDataDer as ae,parsePkcs7SignedDataPem as oe,verifyPkcs7SignedData as se}from"./pkcs/pkcs7.js";import{checkCertificateRevocationAgainstCrl as ce,createCertificateRevocationList as le,isCertificateRevoked as ue,parseCertificateRevocationListDer as de,parseCertificateRevocationListPem as fe,validateCertificateRevocationList as pe,verifyCertificateRevocationList as me}from"./revocation/crl.js";import{checkChainRevocation as he}from"./revocation/chain.js";import{matchCertificateServiceIdentity as ge,matchServiceIdentity as _e}from"./verify/identity.js";import{buildCandidatePath as ve,checkExtendedKeyUsage as ye,trustAnchorFromCertificate as be,validateCandidatePath as xe,validateForCa as Se,validateForCodeSigning as Ce,validateForTlsClient as we,validateForTlsServer as Te,verifyCertificateChain as Ee,verifyCertificateSigningRequest as De}from"./verify/verify.js";import{createOcspRequest as Oe,createOcspResponse as ke,parseOcspRequestDer as Ae,parseOcspRequestPem as je,parseOcspResponseDer as Me,parseOcspResponsePem as Ne,validateOcspResponse as Pe,verifyOcspResponse as Fe}from"./revocation/ocsp.js";import{checkCertificateRevocation as Ie,getCertificateOcspResponderUris as Le,resolveOcspResponderCandidates as Re}from"./revocation/revocation.js";import{createCertificate as ze,createSelfSignedCertificate as Be}from"./x509/certificate.js";import{createCertificateSigningRequest as Ve}from"./x509/csr.js";export{ve as buildCandidatePath,e as categorizePemBlocks,Ie as checkCertificateRevocation,ce as checkCertificateRevocationAgainstCrl,he as checkChainRevocation,ye as checkExtendedKeyUsage,ze as createCertificate,le as createCertificateRevocationList,Ve as createCertificateSigningRequest,Oe as createOcspRequest,ke as createOcspResponse,X as createPfx,$ as createPkcs7CertBagDer,ee as createPkcs7CertBagPem,te as createPkcs7SignedDataDer,ne as createPkcs7SignedDataPem,Be as createSelfSignedCertificate,z as decodeExtension,B as decodeExtensionMap,V as decodeExtensions,H as defineExtensionDecoder,U as defineExtensionDecoderMap,s as exportBinaryBase64,c as exportEncryptedPkcs1Pem,l as exportEncryptedPkcs8Der,u as exportEncryptedPkcs8Pem,d as exportEncryptedSec1Pem,f as exportPkcs1Der,p as exportPkcs1Pem,m as exportPkcs8Der,h as exportPkcs8Pem,g as exportPrivateJwk,_ as exportPublicJwk,v as exportSec1Der,y as exportSec1Pem,b as exportSpkiDer,x as exportSpkiPem,W as findExtension,S as generateKeyPair,Le as getCertificateOcspResponderUris,C as importEncryptedPkcs1Pem,w as importEncryptedPkcs8Der,T as importEncryptedPkcs8Pem,E as importEncryptedSec1Pem,D as importPkcs1Der,O as importPkcs1Pem,k as importPkcs8Base64,A as importPkcs8Der,j as importPkcs8Pem,M as importPrivateJwk,N as importPublicJwk,P as importSec1Der,F as importSec1Pem,I as importSpkiBase64,L as importSpkiDer,R as importSpkiPem,ue as isCertificateRevoked,i as isResultError,ge as matchCertificateServiceIdentity,_e as matchServiceIdentity,G as parseCertificateChainPem,K as parseCertificateDer,q as parseCertificatePem,de as parseCertificateRevocationListDer,fe as parseCertificateRevocationListPem,J as parseCertificateSigningRequestDer,Y as parseCertificateSigningRequestPem,Ae as parseOcspRequestDer,je as parseOcspRequestPem,Me as parseOcspResponseDer,Ne as parseOcspResponsePem,Z as parsePfxDer,Q as parsePfxPem,re as parsePkcs7CertBagDer,ie as parsePkcs7CertBagPem,ae as parsePkcs7SignedDataDer,oe as parsePkcs7SignedDataPem,t as pemDecode,n as pemEncode,Re as resolveOcspResponderCandidates,r as splitPemBlocks,be as trustAnchorFromCertificate,a as unwrap,o as unwrapOr,xe as validateCandidatePath,pe as validateCertificateRevocationList,Se as validateForCa,Ce as validateForCodeSigning,we as validateForTlsClient,Te as validateForTlsServer,Pe as validateOcspResponse,Ee as verifyCertificateChain,me as verifyCertificateRevocationList,De as verifyCertificateSigningRequest,Fe as verifyOcspResponse,se as verifyPkcs7SignedData};
@@ -1,2 +1,2 @@
1
- const e={commonName:`2.5.4.3`,surname:`2.5.4.4`,serialNumber:`2.5.4.5`,countryName:`2.5.4.6`,localityName:`2.5.4.7`,stateOrProvinceName:`2.5.4.8`,streetAddress:`2.5.4.9`,organizationName:`2.5.4.10`,organizationalUnitName:`2.5.4.11`,title:`2.5.4.12`,givenName:`2.5.4.42`,emailAddress:`1.2.840.113549.1.9.1`,cmsContentType:`1.2.840.113549.1.9.3`,cmsMessageDigest:`1.2.840.113549.1.9.4`,extensionRequest:`1.2.840.113549.1.9.14`,pkcs7Data:`1.2.840.113549.1.7.1`,pkcs7SignedData:`1.2.840.113549.1.7.2`,pkcs7EncryptedData:`1.2.840.113549.1.7.6`,pkcs12KeyBag:`1.2.840.113549.1.12.10.1.1`,pkcs12CertBag:`1.2.840.113549.1.12.10.1.3`,x509CertificateBagType:`1.2.840.113549.1.9.22.1`,friendlyName:`1.2.840.113549.1.9.20`,localKeyId:`1.2.840.113549.1.9.21`,pbes2:`1.2.840.113549.1.5.13`,pbkdf2:`1.2.840.113549.1.5.12`,mgf1:`1.2.840.113549.1.1.8`,hmacWithSHA1:`1.2.840.113549.2.7`,hmacWithSHA256:`1.2.840.113549.2.9`,aes128Cbc:`2.16.840.1.101.3.4.1.2`,aes192Cbc:`2.16.840.1.101.3.4.1.22`,aes256Cbc:`2.16.840.1.101.3.4.1.42`,rsaEncryption:`1.2.840.113549.1.1.1`,sha1WithRSAEncryption:`1.2.840.113549.1.1.5`,rsassaPss:`1.2.840.113549.1.1.10`,sha256WithRSAEncryption:`1.2.840.113549.1.1.11`,sha384WithRSAEncryption:`1.2.840.113549.1.1.12`,sha512WithRSAEncryption:`1.2.840.113549.1.1.13`,ecPublicKey:`1.2.840.10045.2.1`,ecdsaWithSHA1:`1.2.840.10045.4.1`,ecdsaWithSHA224:`1.2.840.10045.4.3.1`,ecdsaWithSHA256:`1.2.840.10045.4.3.2`,ecdsaWithSHA384:`1.2.840.10045.4.3.3`,ecdsaWithSHA512:`1.2.840.10045.4.3.4`,prime256v1:`1.2.840.10045.3.1.7`,secp384r1:`1.3.132.0.34`,secp521r1:`1.3.132.0.35`,ed25519:`1.3.101.112`,subjectKeyIdentifier:`2.5.29.14`,keyUsage:`2.5.29.15`,subjectAltName:`2.5.29.17`,nameConstraints:`2.5.29.30`,certificatePolicies:`2.5.29.32`,policyMappings:`2.5.29.33`,cRLNumber:`2.5.29.20`,cRLReason:`2.5.29.21`,invalidityDate:`2.5.29.24`,certificateIssuer:`2.5.29.29`,issuingDistributionPoint:`2.5.29.28`,deltaCRLIndicator:`2.5.29.27`,basicConstraints:`2.5.29.19`,policyConstraints:`2.5.29.36`,cRLDistributionPoints:`2.5.29.31`,freshestCRL:`2.5.29.46`,inhibitAnyPolicy:`2.5.29.54`,extendedKeyUsage:`2.5.29.37`,authorityKeyIdentifier:`2.5.29.35`,anyPolicy:`2.5.29.32.0`,authorityInfoAccess:`1.3.6.1.5.5.7.1.1`,idOnDnsSrv:`1.3.6.1.5.5.7.8.7`,cpsPolicyQualifier:`1.3.6.1.5.5.7.2.1`,userNoticePolicyQualifier:`1.3.6.1.5.5.7.2.2`,ocspAccessMethod:`1.3.6.1.5.5.7.48.1`,caIssuersAccessMethod:`1.3.6.1.5.5.7.48.2`,ocspBasicResponse:`1.3.6.1.5.5.7.48.1.1`,ocspNonce:`1.3.6.1.5.5.7.48.1.2`,sha1:`1.3.14.3.2.26`,sha256:`2.16.840.1.101.3.4.2.1`,sha384:`2.16.840.1.101.3.4.2.2`,sha512:`2.16.840.1.101.3.4.2.3`,serverAuth:`1.3.6.1.5.5.7.3.1`,clientAuth:`1.3.6.1.5.5.7.3.2`,codeSigning:`1.3.6.1.5.5.7.3.3`,emailProtection:`1.3.6.1.5.5.7.3.4`,timeStamping:`1.3.6.1.5.5.7.3.8`,ocspSigning:`1.3.6.1.5.5.7.3.9`};export{e as OIDS,e as default};
1
+ const e={commonName:`2.5.4.3`,surname:`2.5.4.4`,serialNumber:`2.5.4.5`,countryName:`2.5.4.6`,localityName:`2.5.4.7`,stateOrProvinceName:`2.5.4.8`,streetAddress:`2.5.4.9`,organizationName:`2.5.4.10`,organizationalUnitName:`2.5.4.11`,title:`2.5.4.12`,givenName:`2.5.4.42`,emailAddress:`1.2.840.113549.1.9.1`,cmsContentType:`1.2.840.113549.1.9.3`,cmsMessageDigest:`1.2.840.113549.1.9.4`,extensionRequest:`1.2.840.113549.1.9.14`,pkcs7Data:`1.2.840.113549.1.7.1`,pkcs7SignedData:`1.2.840.113549.1.7.2`,pkcs7EncryptedData:`1.2.840.113549.1.7.6`,pkcs12KeyBag:`1.2.840.113549.1.12.10.1.1`,pkcs12CertBag:`1.2.840.113549.1.12.10.1.3`,x509CertificateBagType:`1.2.840.113549.1.9.22.1`,friendlyName:`1.2.840.113549.1.9.20`,localKeyId:`1.2.840.113549.1.9.21`,pbes2:`1.2.840.113549.1.5.13`,pbkdf2:`1.2.840.113549.1.5.12`,mgf1:`1.2.840.113549.1.1.8`,hmacWithSHA1:`1.2.840.113549.2.7`,hmacWithSHA256:`1.2.840.113549.2.9`,aes128Cbc:`2.16.840.1.101.3.4.1.2`,aes192Cbc:`2.16.840.1.101.3.4.1.22`,aes256Cbc:`2.16.840.1.101.3.4.1.42`,rsaEncryption:`1.2.840.113549.1.1.1`,sha1WithRSAEncryption:`1.2.840.113549.1.1.5`,rsassaPss:`1.2.840.113549.1.1.10`,sha256WithRSAEncryption:`1.2.840.113549.1.1.11`,sha384WithRSAEncryption:`1.2.840.113549.1.1.12`,sha512WithRSAEncryption:`1.2.840.113549.1.1.13`,ecPublicKey:`1.2.840.10045.2.1`,ecdsaWithSHA1:`1.2.840.10045.4.1`,ecdsaWithSHA224:`1.2.840.10045.4.3.1`,ecdsaWithSHA256:`1.2.840.10045.4.3.2`,ecdsaWithSHA384:`1.2.840.10045.4.3.3`,ecdsaWithSHA512:`1.2.840.10045.4.3.4`,prime256v1:`1.2.840.10045.3.1.7`,secp384r1:`1.3.132.0.34`,secp521r1:`1.3.132.0.35`,ed25519:`1.3.101.112`,subjectKeyIdentifier:`2.5.29.14`,keyUsage:`2.5.29.15`,subjectAltName:`2.5.29.17`,nameConstraints:`2.5.29.30`,certificatePolicies:`2.5.29.32`,policyMappings:`2.5.29.33`,cRLNumber:`2.5.29.20`,cRLReason:`2.5.29.21`,invalidityDate:`2.5.29.24`,certificateIssuer:`2.5.29.29`,issuingDistributionPoint:`2.5.29.28`,deltaCRLIndicator:`2.5.29.27`,basicConstraints:`2.5.29.19`,policyConstraints:`2.5.29.36`,cRLDistributionPoints:`2.5.29.31`,freshestCRL:`2.5.29.46`,inhibitAnyPolicy:`2.5.29.54`,extendedKeyUsage:`2.5.29.37`,authorityKeyIdentifier:`2.5.29.35`,anyPolicy:`2.5.29.32.0`,authorityInfoAccess:`1.3.6.1.5.5.7.1.1`,idOnDnsSrv:`1.3.6.1.5.5.7.8.7`,cpsPolicyQualifier:`1.3.6.1.5.5.7.2.1`,userNoticePolicyQualifier:`1.3.6.1.5.5.7.2.2`,ocspAccessMethod:`1.3.6.1.5.5.7.48.1`,caIssuersAccessMethod:`1.3.6.1.5.5.7.48.2`,ocspBasicResponse:`1.3.6.1.5.5.7.48.1.1`,ocspNonce:`1.3.6.1.5.5.7.48.1.2`,sha1:`1.3.14.3.2.26`,sha256:`2.16.840.1.101.3.4.2.1`,sha384:`2.16.840.1.101.3.4.2.2`,sha512:`2.16.840.1.101.3.4.2.3`,serverAuth:`1.3.6.1.5.5.7.3.1`,clientAuth:`1.3.6.1.5.5.7.3.2`,codeSigning:`1.3.6.1.5.5.7.3.3`,emailProtection:`1.3.6.1.5.5.7.3.4`,timeStamping:`1.3.6.1.5.5.7.3.8`,ocspSigning:`1.3.6.1.5.5.7.3.9`};export{e as OIDS};
2
2
  //# sourceMappingURL=oids.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oids.js","names":[],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\n/**\n * Dotted-decimal OID constants for X.500 attributes, PKCS algorithms,\n * X.509v3 extensions, EKU purposes, hash algorithms, and PKIX access methods.\n */\nconst OIDS = {\n\tcommonName: '2.5.4.3',\n\tsurname: '2.5.4.4',\n\tserialNumber: '2.5.4.5',\n\tcountryName: '2.5.4.6',\n\tlocalityName: '2.5.4.7',\n\tstateOrProvinceName: '2.5.4.8',\n\tstreetAddress: '2.5.4.9',\n\torganizationName: '2.5.4.10',\n\torganizationalUnitName: '2.5.4.11',\n\ttitle: '2.5.4.12',\n\tgivenName: '2.5.4.42',\n\temailAddress: '1.2.840.113549.1.9.1',\n\tcmsContentType: '1.2.840.113549.1.9.3',\n\tcmsMessageDigest: '1.2.840.113549.1.9.4',\n\textensionRequest: '1.2.840.113549.1.9.14',\n\tpkcs7Data: '1.2.840.113549.1.7.1',\n\tpkcs7SignedData: '1.2.840.113549.1.7.2',\n\tpkcs7EncryptedData: '1.2.840.113549.1.7.6',\n\tpkcs12KeyBag: '1.2.840.113549.1.12.10.1.1',\n\tpkcs12CertBag: '1.2.840.113549.1.12.10.1.3',\n\tx509CertificateBagType: '1.2.840.113549.1.9.22.1',\n\tfriendlyName: '1.2.840.113549.1.9.20',\n\tlocalKeyId: '1.2.840.113549.1.9.21',\n\tpbes2: '1.2.840.113549.1.5.13',\n\tpbkdf2: '1.2.840.113549.1.5.12',\n\tmgf1: '1.2.840.113549.1.1.8',\n\thmacWithSHA1: '1.2.840.113549.2.7',\n\thmacWithSHA256: '1.2.840.113549.2.9',\n\taes128Cbc: '2.16.840.1.101.3.4.1.2',\n\taes192Cbc: '2.16.840.1.101.3.4.1.22',\n\taes256Cbc: '2.16.840.1.101.3.4.1.42',\n\trsaEncryption: '1.2.840.113549.1.1.1',\n\tsha1WithRSAEncryption: '1.2.840.113549.1.1.5',\n\trsassaPss: '1.2.840.113549.1.1.10',\n\tsha256WithRSAEncryption: '1.2.840.113549.1.1.11',\n\tsha384WithRSAEncryption: '1.2.840.113549.1.1.12',\n\tsha512WithRSAEncryption: '1.2.840.113549.1.1.13',\n\tecPublicKey: '1.2.840.10045.2.1',\n\tecdsaWithSHA1: '1.2.840.10045.4.1',\n\tecdsaWithSHA224: '1.2.840.10045.4.3.1',\n\tecdsaWithSHA256: '1.2.840.10045.4.3.2',\n\tecdsaWithSHA384: '1.2.840.10045.4.3.3',\n\tecdsaWithSHA512: '1.2.840.10045.4.3.4',\n\tprime256v1: '1.2.840.10045.3.1.7',\n\tsecp384r1: '1.3.132.0.34',\n\tsecp521r1: '1.3.132.0.35',\n\ted25519: '1.3.101.112',\n\tsubjectKeyIdentifier: '2.5.29.14',\n\tkeyUsage: '2.5.29.15',\n\tsubjectAltName: '2.5.29.17',\n\tnameConstraints: '2.5.29.30',\n\tcertificatePolicies: '2.5.29.32',\n\tpolicyMappings: '2.5.29.33',\n\tcRLNumber: '2.5.29.20',\n\tcRLReason: '2.5.29.21',\n\tinvalidityDate: '2.5.29.24',\n\tcertificateIssuer: '2.5.29.29',\n\tissuingDistributionPoint: '2.5.29.28',\n\tdeltaCRLIndicator: '2.5.29.27',\n\tbasicConstraints: '2.5.29.19',\n\tpolicyConstraints: '2.5.29.36',\n\tcRLDistributionPoints: '2.5.29.31',\n\tfreshestCRL: '2.5.29.46',\n\tinhibitAnyPolicy: '2.5.29.54',\n\textendedKeyUsage: '2.5.29.37',\n\tauthorityKeyIdentifier: '2.5.29.35',\n\tanyPolicy: '2.5.29.32.0',\n\tauthorityInfoAccess: '1.3.6.1.5.5.7.1.1',\n\tidOnDnsSrv: '1.3.6.1.5.5.7.8.7',\n\tcpsPolicyQualifier: '1.3.6.1.5.5.7.2.1',\n\tuserNoticePolicyQualifier: '1.3.6.1.5.5.7.2.2',\n\tocspAccessMethod: '1.3.6.1.5.5.7.48.1',\n\tcaIssuersAccessMethod: '1.3.6.1.5.5.7.48.2',\n\tocspBasicResponse: '1.3.6.1.5.5.7.48.1.1',\n\tocspNonce: '1.3.6.1.5.5.7.48.1.2',\n\tsha1: '1.3.14.3.2.26',\n\tsha256: '2.16.840.1.101.3.4.2.1',\n\tsha384: '2.16.840.1.101.3.4.2.2',\n\tsha512: '2.16.840.1.101.3.4.2.3',\n\tserverAuth: '1.3.6.1.5.5.7.3.1',\n\tclientAuth: '1.3.6.1.5.5.7.3.2',\n\tcodeSigning: '1.3.6.1.5.5.7.3.3',\n\temailProtection: '1.3.6.1.5.5.7.3.4',\n\ttimeStamping: '1.3.6.1.5.5.7.3.8',\n\tocspSigning: '1.3.6.1.5.5.7.3.9',\n} as const;\n\nexport { OIDS };\nexport default OIDS;\n"],"mappings":"AAaA,MAAM,EAAO,CACZ,WAAY,UACZ,QAAS,UACT,aAAc,UACd,YAAa,UACb,aAAc,UACd,oBAAqB,UACrB,cAAe,UACf,iBAAkB,WAClB,uBAAwB,WACxB,MAAO,WACP,UAAW,WACX,aAAc,uBACd,eAAgB,uBAChB,iBAAkB,uBAClB,iBAAkB,wBAClB,UAAW,uBACX,gBAAiB,uBACjB,mBAAoB,uBACpB,aAAc,6BACd,cAAe,6BACf,uBAAwB,0BACxB,aAAc,wBACd,WAAY,wBACZ,MAAO,wBACP,OAAQ,wBACR,KAAM,uBACN,aAAc,qBACd,eAAgB,qBAChB,UAAW,yBACX,UAAW,0BACX,UAAW,0BACX,cAAe,uBACf,sBAAuB,uBACvB,UAAW,wBACX,wBAAyB,wBACzB,wBAAyB,wBACzB,wBAAyB,wBACzB,YAAa,oBACb,cAAe,oBACf,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,WAAY,sBACZ,UAAW,eACX,UAAW,eACX,QAAS,cACT,qBAAsB,YACtB,SAAU,YACV,eAAgB,YAChB,gBAAiB,YACjB,oBAAqB,YACrB,eAAgB,YAChB,UAAW,YACX,UAAW,YACX,eAAgB,YAChB,kBAAmB,YACnB,yBAA0B,YAC1B,kBAAmB,YACnB,iBAAkB,YAClB,kBAAmB,YACnB,sBAAuB,YACvB,YAAa,YACb,iBAAkB,YAClB,iBAAkB,YAClB,uBAAwB,YACxB,UAAW,cACX,oBAAqB,oBACrB,WAAY,oBACZ,mBAAoB,oBACpB,0BAA2B,oBAC3B,iBAAkB,qBAClB,sBAAuB,qBACvB,kBAAmB,uBACnB,UAAW,uBACX,KAAM,gBACN,OAAQ,yBACR,OAAQ,yBACR,OAAQ,yBACR,WAAY,oBACZ,WAAY,oBACZ,YAAa,oBACb,gBAAiB,oBACjB,aAAc,oBACd,YAAa,mBACd"}
1
+ {"version":3,"file":"oids.js","names":[],"sources":["../../../src/internal/asn1/oids.ts"],"sourcesContent":["/**\n * Centralized ASN.1 object identifier registry referenced by create, parse,\n * verify, and container modules.\n *\n * All OIDs are dotted-decimal string constants keyed by their common short name.\n *\n * @module\n */\n\n/**\n * Dotted-decimal OID constants for X.500 attributes, PKCS algorithms,\n * X.509v3 extensions, EKU purposes, hash algorithms, and PKIX access methods.\n */\nconst OIDS = {\n\tcommonName: '2.5.4.3',\n\tsurname: '2.5.4.4',\n\tserialNumber: '2.5.4.5',\n\tcountryName: '2.5.4.6',\n\tlocalityName: '2.5.4.7',\n\tstateOrProvinceName: '2.5.4.8',\n\tstreetAddress: '2.5.4.9',\n\torganizationName: '2.5.4.10',\n\torganizationalUnitName: '2.5.4.11',\n\ttitle: '2.5.4.12',\n\tgivenName: '2.5.4.42',\n\temailAddress: '1.2.840.113549.1.9.1',\n\tcmsContentType: '1.2.840.113549.1.9.3',\n\tcmsMessageDigest: '1.2.840.113549.1.9.4',\n\textensionRequest: '1.2.840.113549.1.9.14',\n\tpkcs7Data: '1.2.840.113549.1.7.1',\n\tpkcs7SignedData: '1.2.840.113549.1.7.2',\n\tpkcs7EncryptedData: '1.2.840.113549.1.7.6',\n\tpkcs12KeyBag: '1.2.840.113549.1.12.10.1.1',\n\tpkcs12CertBag: '1.2.840.113549.1.12.10.1.3',\n\tx509CertificateBagType: '1.2.840.113549.1.9.22.1',\n\tfriendlyName: '1.2.840.113549.1.9.20',\n\tlocalKeyId: '1.2.840.113549.1.9.21',\n\tpbes2: '1.2.840.113549.1.5.13',\n\tpbkdf2: '1.2.840.113549.1.5.12',\n\tmgf1: '1.2.840.113549.1.1.8',\n\thmacWithSHA1: '1.2.840.113549.2.7',\n\thmacWithSHA256: '1.2.840.113549.2.9',\n\taes128Cbc: '2.16.840.1.101.3.4.1.2',\n\taes192Cbc: '2.16.840.1.101.3.4.1.22',\n\taes256Cbc: '2.16.840.1.101.3.4.1.42',\n\trsaEncryption: '1.2.840.113549.1.1.1',\n\tsha1WithRSAEncryption: '1.2.840.113549.1.1.5',\n\trsassaPss: '1.2.840.113549.1.1.10',\n\tsha256WithRSAEncryption: '1.2.840.113549.1.1.11',\n\tsha384WithRSAEncryption: '1.2.840.113549.1.1.12',\n\tsha512WithRSAEncryption: '1.2.840.113549.1.1.13',\n\tecPublicKey: '1.2.840.10045.2.1',\n\tecdsaWithSHA1: '1.2.840.10045.4.1',\n\tecdsaWithSHA224: '1.2.840.10045.4.3.1',\n\tecdsaWithSHA256: '1.2.840.10045.4.3.2',\n\tecdsaWithSHA384: '1.2.840.10045.4.3.3',\n\tecdsaWithSHA512: '1.2.840.10045.4.3.4',\n\tprime256v1: '1.2.840.10045.3.1.7',\n\tsecp384r1: '1.3.132.0.34',\n\tsecp521r1: '1.3.132.0.35',\n\ted25519: '1.3.101.112',\n\tsubjectKeyIdentifier: '2.5.29.14',\n\tkeyUsage: '2.5.29.15',\n\tsubjectAltName: '2.5.29.17',\n\tnameConstraints: '2.5.29.30',\n\tcertificatePolicies: '2.5.29.32',\n\tpolicyMappings: '2.5.29.33',\n\tcRLNumber: '2.5.29.20',\n\tcRLReason: '2.5.29.21',\n\tinvalidityDate: '2.5.29.24',\n\tcertificateIssuer: '2.5.29.29',\n\tissuingDistributionPoint: '2.5.29.28',\n\tdeltaCRLIndicator: '2.5.29.27',\n\tbasicConstraints: '2.5.29.19',\n\tpolicyConstraints: '2.5.29.36',\n\tcRLDistributionPoints: '2.5.29.31',\n\tfreshestCRL: '2.5.29.46',\n\tinhibitAnyPolicy: '2.5.29.54',\n\textendedKeyUsage: '2.5.29.37',\n\tauthorityKeyIdentifier: '2.5.29.35',\n\tanyPolicy: '2.5.29.32.0',\n\tauthorityInfoAccess: '1.3.6.1.5.5.7.1.1',\n\tidOnDnsSrv: '1.3.6.1.5.5.7.8.7',\n\tcpsPolicyQualifier: '1.3.6.1.5.5.7.2.1',\n\tuserNoticePolicyQualifier: '1.3.6.1.5.5.7.2.2',\n\tocspAccessMethod: '1.3.6.1.5.5.7.48.1',\n\tcaIssuersAccessMethod: '1.3.6.1.5.5.7.48.2',\n\tocspBasicResponse: '1.3.6.1.5.5.7.48.1.1',\n\tocspNonce: '1.3.6.1.5.5.7.48.1.2',\n\tsha1: '1.3.14.3.2.26',\n\tsha256: '2.16.840.1.101.3.4.2.1',\n\tsha384: '2.16.840.1.101.3.4.2.2',\n\tsha512: '2.16.840.1.101.3.4.2.3',\n\tserverAuth: '1.3.6.1.5.5.7.3.1',\n\tclientAuth: '1.3.6.1.5.5.7.3.2',\n\tcodeSigning: '1.3.6.1.5.5.7.3.3',\n\temailProtection: '1.3.6.1.5.5.7.3.4',\n\ttimeStamping: '1.3.6.1.5.5.7.3.8',\n\tocspSigning: '1.3.6.1.5.5.7.3.9',\n} as const;\n\nexport { OIDS };\n"],"mappings":"AAaA,MAAM,EAAO,CACZ,WAAY,UACZ,QAAS,UACT,aAAc,UACd,YAAa,UACb,aAAc,UACd,oBAAqB,UACrB,cAAe,UACf,iBAAkB,WAClB,uBAAwB,WACxB,MAAO,WACP,UAAW,WACX,aAAc,uBACd,eAAgB,uBAChB,iBAAkB,uBAClB,iBAAkB,wBAClB,UAAW,uBACX,gBAAiB,uBACjB,mBAAoB,uBACpB,aAAc,6BACd,cAAe,6BACf,uBAAwB,0BACxB,aAAc,wBACd,WAAY,wBACZ,MAAO,wBACP,OAAQ,wBACR,KAAM,uBACN,aAAc,qBACd,eAAgB,qBAChB,UAAW,yBACX,UAAW,0BACX,UAAW,0BACX,cAAe,uBACf,sBAAuB,uBACvB,UAAW,wBACX,wBAAyB,wBACzB,wBAAyB,wBACzB,wBAAyB,wBACzB,YAAa,oBACb,cAAe,oBACf,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,gBAAiB,sBACjB,WAAY,sBACZ,UAAW,eACX,UAAW,eACX,QAAS,cACT,qBAAsB,YACtB,SAAU,YACV,eAAgB,YAChB,gBAAiB,YACjB,oBAAqB,YACrB,eAAgB,YAChB,UAAW,YACX,UAAW,YACX,eAAgB,YAChB,kBAAmB,YACnB,yBAA0B,YAC1B,kBAAmB,YACnB,iBAAkB,YAClB,kBAAmB,YACnB,sBAAuB,YACvB,YAAa,YACb,iBAAkB,YAClB,iBAAkB,YAClB,uBAAwB,YACxB,UAAW,cACX,oBAAqB,oBACrB,WAAY,oBACZ,mBAAoB,oBACpB,0BAA2B,oBAC3B,iBAAkB,qBAClB,sBAAuB,qBACvB,kBAAmB,uBACnB,UAAW,uBACX,KAAM,gBACN,OAAQ,yBACR,OAAQ,yBACR,OAAQ,yBACR,WAAY,oBACZ,WAAY,oBACZ,YAAa,oBACb,gBAAiB,oBACjB,aAAc,oBACd,YAAa,mBACd"}
@@ -1,2 +1,2 @@
1
- import{integerFromNumber as e,nullValue as t,objectIdentifier as n,octetString as r,readSequenceChildren as i,sequence as a}from"../asn1/der.js";import{decodeIntegerNumber as o,decodeObjectIdentifier as s,toArrayBuffer as c}from"../asn1/asn1.js";import{OIDS as l}from"../asn1/oids.js";import{getCrypto as u}from"./webcrypto.js";async function d(e,t){let n=t.iterations??1e5,r=t.salt??u().getRandomValues(new Uint8Array(16)),i=t.iv??u().getRandomValues(new Uint8Array(16)),a=t.encryption??`aes256-cbc`,o=t.prf??`hmac-sha256`;if(!Number.isInteger(n)||n<1)throw RangeError(`Invalid iterations: must be an integer >= 1, got ${n}`);if(!(r instanceof Uint8Array)||r.length<8)throw TypeError(`Invalid salt: must be Uint8Array with length >= 8, got length ${r.length}`);if(!(i instanceof Uint8Array)||i.length!==16)throw TypeError(`Invalid IV: must be Uint8Array of exactly 16 bytes, got length ${i.length}`);let s=await h(t.password,r,n,a,o,[`encrypt`]),l=new Uint8Array(await u().subtle.encrypt({name:`AES-CBC`,iv:c(i)},s,c(e)));return{algorithmIdentifierDer:p({iterations:n,salt:r,iv:i,encryption:a,prf:o}),encryptedData:l,parameters:{iterations:n,salt:r,iv:i,encryption:a,prf:o}}}async function f(e,t,n){let r=m(e),i=await h(n,r.salt,r.iterations,r.encryption,r.prf,[`decrypt`]);try{return new Uint8Array(await u().subtle.decrypt({name:`AES-CBC`,iv:c(r.iv)},i,c(t)))}catch{throw Error(`Invalid password or encrypted content`)}}function p(i){let o=y(i.encryption),s=b(i.prf);return a([n(l.pbes2),a([a([n(l.pbkdf2),a([r(i.salt),e(i.iterations),e(o.keyLengthBytes),a([n(s.oid),t()])])]),a([n(o.oid),r(i.iv)])])])}function m(e){let t=i(e),n=t[0],r=t[1];if(n===void 0||r===void 0)throw Error(`Malformed PBES2 algorithm identifier`);if(s(n.value)!==l.pbes2)throw Error(`Unsupported encryption algorithm`);let a=e.slice(r.start-r.headerLength,r.end),c=i(a),u=c[0],d=c[1];if(u===void 0||d===void 0)throw Error(`Malformed PBES2 params`);let f=a.slice(u.start-u.headerLength,u.end),p=i(f),m=p[0],h=p[1];if(m===void 0||h===void 0)throw Error(`Malformed KDF params`);if(s(m.value)!==l.pbkdf2)throw Error(`Unsupported KDF`);let v=f.slice(h.start-h.headerLength,h.end),y=i(v),b=y[0],x=y[1];if(b===void 0||x===void 0||b.tag!==4)throw Error(`Malformed PBKDF2 params`);let S=y[2],C=S?.tag===2,w=C?y[3]:S,T=i(a.slice(d.start-d.headerLength,d.end)),E=T[0],D=T[1];if(E===void 0||D===void 0||D.tag!==4)throw Error(`Malformed encryption scheme`);let O=_(s(E.value));if(O===void 0)throw Error(`Unsupported content encryption scheme`);if(S!==void 0&&!C&&S.tag!==48)throw Error(`Malformed PBKDF2 params`);if(C&&o(S.value)!==O.keyLengthBytes)throw Error(`Unsupported PBKDF2 key length`);let k=g(v,w),A=o(x.value),j=new Uint8Array(b.value),M=new Uint8Array(D.value);if(A<1)throw RangeError(`Invalid PBES2 iterations: must be >= 1, got ${A}`);if(j.length<8)throw RangeError(`Invalid PBES2 salt: must be >= 8 bytes, got ${j.length}`);if(M.length!==16)throw RangeError(`Invalid PBES2 IV: must be exactly 16 bytes, got ${M.length}`);return{salt:j,iterations:A,iv:M,encryption:O.name,prf:k}}async function h(e,t,n,r,i,a){let o=y(r),s=b(i),l=await u().subtle.importKey(`raw`,new TextEncoder().encode(e),`PBKDF2`,!1,[`deriveKey`]);return u().subtle.deriveKey({name:`PBKDF2`,salt:c(t),iterations:n,hash:s.hash},l,{name:`AES-CBC`,length:o.keyLengthBits},!1,a)}function g(e,t){if(t===void 0)return`hmac-sha1`;if(t.tag!==48)throw Error(`Malformed PBKDF2 PRF`);let n=i(e.slice(t.start-t.headerLength,t.end))[0];if(n===void 0)throw Error(`Malformed PBKDF2 PRF`);let r=v(s(n.value));if(r===void 0)throw Error(`Unsupported PBKDF2 PRF`);return r}function _(e){switch(e){case l.aes128Cbc:return{name:`aes128-cbc`,oid:e,keyLengthBits:128,keyLengthBytes:16};case l.aes192Cbc:return{name:`aes192-cbc`,oid:e,keyLengthBits:192,keyLengthBytes:24};case l.aes256Cbc:return{name:`aes256-cbc`,oid:e,keyLengthBits:256,keyLengthBytes:32}}}function v(e){switch(e){case l.hmacWithSHA1:return`hmac-sha1`;case l.hmacWithSHA256:return`hmac-sha256`}}function y(e){let t=_(e===`aes128-cbc`?l.aes128Cbc:e===`aes192-cbc`?l.aes192Cbc:l.aes256Cbc);if(t===void 0)throw Error(`Unsupported content encryption scheme`);return t}function b(e){switch(e){case`hmac-sha1`:return{oid:l.hmacWithSHA1,hash:`SHA-1`};case`hmac-sha256`:return{oid:l.hmacWithSHA256,hash:`SHA-256`}}}export{f as decryptPbes2,p as encodePbes2AlgorithmIdentifier,d as encryptPbes2,m as parsePbes2AlgorithmIdentifier};
1
+ import{integerFromNumber as e,nullValue as t,objectIdentifier as n,octetString as r,readSequenceChildren as i,sequence as a}from"../asn1/der.js";import{decodeIntegerNumber as o,decodeObjectIdentifier as s,toArrayBuffer as c}from"../asn1/asn1.js";import{OIDS as l}from"../asn1/oids.js";import{getCrypto as u}from"./webcrypto.js";const d=Symbol(`micro509.WrongPasswordError`);function f(e){return Object.assign(Error(e),{name:`WrongPasswordError`,[d]:!0})}function p(e){return e instanceof Error&&d in e}async function m(e,t){let n=t.iterations??1e5,r=t.salt??u().getRandomValues(new Uint8Array(16)),i=t.iv??u().getRandomValues(new Uint8Array(16)),a=t.encryption??`aes256-cbc`,o=t.prf??`hmac-sha256`;if(!Number.isInteger(n)||n<1)throw RangeError(`Invalid iterations: must be an integer >= 1, got ${n}`);if(!(r instanceof Uint8Array)||r.length<8)throw TypeError(`Invalid salt: must be Uint8Array with length >= 8, got length ${r.length}`);if(!(i instanceof Uint8Array)||i.length!==16)throw TypeError(`Invalid IV: must be Uint8Array of exactly 16 bytes, got length ${i.length}`);let s=await v(t.password,r,n,a,o,[`encrypt`]),l=new Uint8Array(await u().subtle.encrypt({name:`AES-CBC`,iv:c(i)},s,c(e)));return{algorithmIdentifierDer:g({iterations:n,salt:r,iv:i,encryption:a,prf:o}),encryptedData:l,parameters:{iterations:n,salt:r,iv:i,encryption:a,prf:o}}}async function h(e,t,n){let r=_(e),i=await v(n,r.salt,r.iterations,r.encryption,r.prf,[`decrypt`]);try{return new Uint8Array(await u().subtle.decrypt({name:`AES-CBC`,iv:c(r.iv)},i,c(t)))}catch{throw f(`Invalid password or encrypted content`)}}function g(i){let o=S(i.encryption),s=C(i.prf);return a([n(l.pbes2),a([a([n(l.pbkdf2),a([r(i.salt),e(i.iterations),e(o.keyLengthBytes),a([n(s.oid),t()])])]),a([n(o.oid),r(i.iv)])])])}function _(e){let t=i(e),n=t[0],r=t[1];if(n===void 0||r===void 0)throw Error(`Malformed PBES2 algorithm identifier`);if(s(n.value)!==l.pbes2)throw Error(`Unsupported encryption algorithm`);let a=e.slice(r.start-r.headerLength,r.end),c=i(a),u=c[0],d=c[1];if(u===void 0||d===void 0)throw Error(`Malformed PBES2 params`);let f=a.slice(u.start-u.headerLength,u.end),p=i(f),m=p[0],h=p[1];if(m===void 0||h===void 0)throw Error(`Malformed KDF params`);if(s(m.value)!==l.pbkdf2)throw Error(`Unsupported KDF`);let g=f.slice(h.start-h.headerLength,h.end),_=i(g),v=_[0],x=_[1];if(v===void 0||x===void 0||v.tag!==4)throw Error(`Malformed PBKDF2 params`);let S=_[2],C=S?.tag===2,w=C?_[3]:S,T=i(a.slice(d.start-d.headerLength,d.end)),E=T[0],D=T[1];if(E===void 0||D===void 0||D.tag!==4)throw Error(`Malformed encryption scheme`);let O=b(s(E.value));if(O===void 0)throw Error(`Unsupported content encryption scheme`);if(S!==void 0&&!C&&S.tag!==48)throw Error(`Malformed PBKDF2 params`);if(C&&o(S.value)!==O.keyLengthBytes)throw Error(`Unsupported PBKDF2 key length`);let k=y(g,w),A=o(x.value),j=new Uint8Array(v.value),M=new Uint8Array(D.value);if(A<1)throw RangeError(`Invalid PBES2 iterations: must be >= 1, got ${A}`);if(j.length<8)throw RangeError(`Invalid PBES2 salt: must be >= 8 bytes, got ${j.length}`);if(M.length!==16)throw RangeError(`Invalid PBES2 IV: must be exactly 16 bytes, got ${M.length}`);return{salt:j,iterations:A,iv:M,encryption:O.name,prf:k}}async function v(e,t,n,r,i,a){let o=S(r),s=C(i),l=await u().subtle.importKey(`raw`,new TextEncoder().encode(e),`PBKDF2`,!1,[`deriveKey`]);return u().subtle.deriveKey({name:`PBKDF2`,salt:c(t),iterations:n,hash:s.hash},l,{name:`AES-CBC`,length:o.keyLengthBits},!1,a)}function y(e,t){if(t===void 0)return`hmac-sha1`;if(t.tag!==48)throw Error(`Malformed PBKDF2 PRF`);let n=i(e.slice(t.start-t.headerLength,t.end))[0];if(n===void 0)throw Error(`Malformed PBKDF2 PRF`);let r=x(s(n.value));if(r===void 0)throw Error(`Unsupported PBKDF2 PRF`);return r}function b(e){switch(e){case l.aes128Cbc:return{name:`aes128-cbc`,oid:e,keyLengthBits:128,keyLengthBytes:16};case l.aes192Cbc:return{name:`aes192-cbc`,oid:e,keyLengthBits:192,keyLengthBytes:24};case l.aes256Cbc:return{name:`aes256-cbc`,oid:e,keyLengthBits:256,keyLengthBytes:32}}}function x(e){switch(e){case l.hmacWithSHA1:return`hmac-sha1`;case l.hmacWithSHA256:return`hmac-sha256`}}function S(e){let t=b(e===`aes128-cbc`?l.aes128Cbc:e===`aes192-cbc`?l.aes192Cbc:l.aes256Cbc);if(t===void 0)throw Error(`Unsupported content encryption scheme`);return t}function C(e){switch(e){case`hmac-sha1`:return{oid:l.hmacWithSHA1,hash:`SHA-1`};case`hmac-sha256`:return{oid:l.hmacWithSHA256,hash:`SHA-256`}}}export{h as decryptPbes2,g as encodePbes2AlgorithmIdentifier,m as encryptPbes2,p as isWrongPasswordError,_ as parsePbes2AlgorithmIdentifier,f as wrongPasswordError};
2
2
  //# sourceMappingURL=pbes2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbes2.js","names":[],"sources":["../../../src/internal/crypto/pbes2.ts"],"sourcesContent":["/**\n * PBES2 password-based encryption and decryption (RFC 8018).\n *\n * Supports AES-CBC-128/192/256 with PBKDF2 using HMAC-SHA-1 or HMAC-SHA-256.\n * Used internally by encrypted PKCS#8 and PFX flows.\n *\n * @module\n */\n\nimport {\n\tdecodeIntegerNumber,\n\tdecodeObjectIdentifier,\n\ttoArrayBuffer,\n} from '#micro509/internal/asn1/asn1.ts';\nimport {\n\tintegerFromNumber,\n\tnullValue,\n\tobjectIdentifier,\n\toctetString,\n\treadSequenceChildren,\n\tsequence,\n} from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport { getCrypto } from './webcrypto.ts';\n\n/** AES-CBC key sizes supported by this PBES2 implementation. */\nexport type Pbes2EncryptionScheme = 'aes128-cbc' | 'aes192-cbc' | 'aes256-cbc';\n\n/** PBKDF2 pseudo-random function choices. `hmac-sha1` is the RFC default; `hmac-sha256` is preferred. */\nexport type Pbes2Prf = 'hmac-sha1' | 'hmac-sha256';\n\n/** Input for `encryptPbes2`. */\nexport interface Pbes2EncryptionOptions {\n\t/** Password fed to PBKDF2 for key derivation. */\n\treadonly password: string;\n\t/** PBKDF2 iteration count. Default: `100_000`. */\n\treadonly iterations?: number;\n\t/** PBKDF2 salt. Default: 16 cryptographically random bytes. */\n\treadonly salt?: Uint8Array;\n\t/** AES-CBC initialization vector. Default: 16 cryptographically random bytes. */\n\treadonly iv?: Uint8Array;\n\t/** AES key size. Default: `'aes256-cbc'`. */\n\treadonly encryption?: Pbes2EncryptionScheme;\n\t/** PBKDF2 PRF. Default: `'hmac-sha256'`. */\n\treadonly prf?: Pbes2Prf;\n}\n\n/** Resolved PBES2 algorithm parameters, either parsed from DER or built by `encryptPbes2`. */\nexport interface Pbes2Parameters {\n\t/** PBKDF2 iteration count. */\n\treadonly iterations: number;\n\t/** PBKDF2 salt bytes. */\n\treadonly salt: Uint8Array;\n\t/** AES-CBC initialization vector. */\n\treadonly iv: Uint8Array;\n\t/** AES-CBC key-size variant. */\n\treadonly encryption: Pbes2EncryptionScheme;\n\t/** PBKDF2 pseudo-random function. */\n\treadonly prf: Pbes2Prf;\n}\n\n/** Output of `encryptPbes2`: ciphertext plus the DER-encoded AlgorithmIdentifier. */\nexport interface Pbes2EncryptionResult {\n\t/** DER-encoded PBES2 AlgorithmIdentifier SEQUENCE (embeds KDF + cipher params). */\n\treadonly algorithmIdentifierDer: Uint8Array;\n\t/** AES-CBC ciphertext (includes PKCS#7 padding). */\n\treadonly encryptedData: Uint8Array;\n\t/** Resolved algorithm parameters used during encryption. */\n\treadonly parameters: Pbes2Parameters;\n}\n\n/** Encrypts `data` using PBES2 (PBKDF2 + AES-CBC) and returns ciphertext with algorithm params. */\nexport async function encryptPbes2(\n\tdata: Uint8Array,\n\toptions: Pbes2EncryptionOptions,\n): Promise<Pbes2EncryptionResult> {\n\tconst iterations = options.iterations ?? 100_000;\n\tconst salt = options.salt ?? getCrypto().getRandomValues(new Uint8Array(16));\n\tconst iv = options.iv ?? getCrypto().getRandomValues(new Uint8Array(16));\n\tconst encryption = options.encryption ?? 'aes256-cbc';\n\tconst prf = options.prf ?? 'hmac-sha256';\n\n\t// Validate inputs before any WebCrypto calls\n\tif (!Number.isInteger(iterations) || iterations < 1) {\n\t\tthrow new RangeError(`Invalid iterations: must be an integer >= 1, got ${iterations}`);\n\t}\n\tif (!(salt instanceof Uint8Array) || salt.length < 8) {\n\t\tthrow new TypeError(\n\t\t\t`Invalid salt: must be Uint8Array with length >= 8, got length ${salt.length}`,\n\t\t);\n\t}\n\tif (!(iv instanceof Uint8Array) || iv.length !== 16) {\n\t\tthrow new TypeError(\n\t\t\t`Invalid IV: must be Uint8Array of exactly 16 bytes, got length ${iv.length}`,\n\t\t);\n\t}\n\n\tconst key = await deriveAesKey(options.password, salt, iterations, encryption, prf, ['encrypt']);\n\tconst encryptedData = new Uint8Array(\n\t\tawait getCrypto().subtle.encrypt(\n\t\t\t{ name: 'AES-CBC', iv: toArrayBuffer(iv) },\n\t\t\tkey,\n\t\t\ttoArrayBuffer(data),\n\t\t),\n\t);\n\treturn {\n\t\talgorithmIdentifierDer: encodePbes2AlgorithmIdentifier({\n\t\t\titerations,\n\t\t\tsalt,\n\t\t\tiv,\n\t\t\tencryption,\n\t\t\tprf,\n\t\t}),\n\t\tencryptedData,\n\t\tparameters: { iterations, salt, iv, encryption, prf },\n\t};\n}\n\n/** Decrypts PBES2 ciphertext given the DER AlgorithmIdentifier and password. Throws on wrong password. */\nexport async function decryptPbes2(\n\talgorithmIdentifierDer: Uint8Array,\n\tencryptedData: Uint8Array,\n\tpassword: string,\n): Promise<Uint8Array> {\n\tconst parameters = parsePbes2AlgorithmIdentifier(algorithmIdentifierDer);\n\tconst key = await deriveAesKey(\n\t\tpassword,\n\t\tparameters.salt,\n\t\tparameters.iterations,\n\t\tparameters.encryption,\n\t\tparameters.prf,\n\t\t['decrypt'],\n\t);\n\ttry {\n\t\treturn new Uint8Array(\n\t\t\tawait getCrypto().subtle.decrypt(\n\t\t\t\t{ name: 'AES-CBC', iv: toArrayBuffer(parameters.iv) },\n\t\t\t\tkey,\n\t\t\t\ttoArrayBuffer(encryptedData),\n\t\t\t),\n\t\t);\n\t} catch {\n\t\tthrow new Error('Invalid password or encrypted content');\n\t}\n}\n\n/** DER-encodes a PBES2 AlgorithmIdentifier SEQUENCE from resolved parameters. */\nexport function encodePbes2AlgorithmIdentifier(parameters: Pbes2Parameters): Uint8Array {\n\tconst encryption = resolveEncryptionProfile(parameters.encryption);\n\tconst prf = resolvePrfProfile(parameters.prf);\n\treturn sequence([\n\t\tobjectIdentifier(OIDS.pbes2),\n\t\tsequence([\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(OIDS.pbkdf2),\n\t\t\t\tsequence([\n\t\t\t\t\toctetString(parameters.salt),\n\t\t\t\t\tintegerFromNumber(parameters.iterations),\n\t\t\t\t\tintegerFromNumber(encryption.keyLengthBytes),\n\t\t\t\t\tsequence([objectIdentifier(prf.oid), nullValue()]),\n\t\t\t\t]),\n\t\t\t]),\n\t\t\tsequence([objectIdentifier(encryption.oid), octetString(parameters.iv)]),\n\t\t]),\n\t]);\n}\n\n/** Decodes a DER-encoded PBES2 AlgorithmIdentifier into structured {@linkcode Pbes2Parameters}. */\nexport function parsePbes2AlgorithmIdentifier(algorithmIdentifierDer: Uint8Array): Pbes2Parameters {\n\tconst topLevel = readSequenceChildren(algorithmIdentifierDer);\n\tconst oid = topLevel[0];\n\tconst params = topLevel[1];\n\tif (oid === undefined || params === undefined) {\n\t\tthrow new Error('Malformed PBES2 algorithm identifier');\n\t}\n\tif (decodeObjectIdentifier(oid.value) !== OIDS.pbes2) {\n\t\tthrow new Error('Unsupported encryption algorithm');\n\t}\n\tconst paramsDer = algorithmIdentifierDer.slice(params.start - params.headerLength, params.end);\n\tconst pbes2Params = readSequenceChildren(paramsDer);\n\tconst kdf = pbes2Params[0];\n\tconst scheme = pbes2Params[1];\n\tif (kdf === undefined || scheme === undefined) {\n\t\tthrow new Error('Malformed PBES2 params');\n\t}\n\tconst kdfDer = paramsDer.slice(kdf.start - kdf.headerLength, kdf.end);\n\tconst kdfChildren = readSequenceChildren(kdfDer);\n\tconst kdfOid = kdfChildren[0];\n\tconst kdfParams = kdfChildren[1];\n\tif (kdfOid === undefined || kdfParams === undefined) {\n\t\tthrow new Error('Malformed KDF params');\n\t}\n\tif (decodeObjectIdentifier(kdfOid.value) !== OIDS.pbkdf2) {\n\t\tthrow new Error('Unsupported KDF');\n\t}\n\t// PBKDF2 params: SEQUENCE { salt OCTET STRING, iterationCount INTEGER, [keyLength INTEGER], [prf AlgorithmIdentifier] }\n\tconst pbkdf2Der = kdfDer.slice(kdfParams.start - kdfParams.headerLength, kdfParams.end);\n\tconst pbkdf2Params = readSequenceChildren(pbkdf2Der);\n\tconst salt = pbkdf2Params[0];\n\tconst iterations = pbkdf2Params[1];\n\tif (salt === undefined || iterations === undefined || salt.tag !== 0x04) {\n\t\tthrow new Error('Malformed PBKDF2 params');\n\t}\n\tconst keyLengthElement = pbkdf2Params[2];\n\tconst hasExplicitKeyLength = keyLengthElement?.tag === 0x02;\n\tconst prfElement = hasExplicitKeyLength ? pbkdf2Params[3] : keyLengthElement;\n\tconst schemeDer = paramsDer.slice(scheme.start - scheme.headerLength, scheme.end);\n\tconst schemeChildren = readSequenceChildren(schemeDer);\n\tconst schemeOid = schemeChildren[0];\n\tconst iv = schemeChildren[1];\n\tif (schemeOid === undefined || iv === undefined || iv.tag !== 0x04) {\n\t\tthrow new Error('Malformed encryption scheme');\n\t}\n\tconst encryption = encryptionSchemeFromOid(decodeObjectIdentifier(schemeOid.value));\n\tif (encryption === undefined) {\n\t\tthrow new Error('Unsupported content encryption scheme');\n\t}\n\tif (keyLengthElement !== undefined && !hasExplicitKeyLength && keyLengthElement.tag !== 0x30) {\n\t\tthrow new Error('Malformed PBKDF2 params');\n\t}\n\tif (\n\t\thasExplicitKeyLength &&\n\t\tdecodeIntegerNumber(keyLengthElement.value) !== encryption.keyLengthBytes\n\t) {\n\t\tthrow new Error('Unsupported PBKDF2 key length');\n\t}\n\tconst prf = parsePbkdf2Prf(pbkdf2Der, prfElement);\n\n\t// Validate parsed parameters before returning\n\tconst iterationsValue = decodeIntegerNumber(iterations.value);\n\tconst saltValue = new Uint8Array(salt.value);\n\tconst ivValue = new Uint8Array(iv.value);\n\n\tif (iterationsValue < 1) {\n\t\tthrow new RangeError(`Invalid PBES2 iterations: must be >= 1, got ${iterationsValue}`);\n\t}\n\tif (saltValue.length < 8) {\n\t\tthrow new RangeError(`Invalid PBES2 salt: must be >= 8 bytes, got ${saltValue.length}`);\n\t}\n\tif (ivValue.length !== 16) {\n\t\tthrow new RangeError(`Invalid PBES2 IV: must be exactly 16 bytes, got ${ivValue.length}`);\n\t}\n\n\treturn {\n\t\tsalt: saltValue,\n\t\titerations: iterationsValue,\n\t\tiv: ivValue,\n\t\tencryption: encryption.name,\n\t\tprf,\n\t};\n}\n\n/** Derives an AES-CBC `CryptoKey` from a password via PBKDF2. */\nasync function deriveAesKey(\n\tpassword: string,\n\tsalt: Uint8Array,\n\titerations: number,\n\tencryptionName: Pbes2EncryptionScheme,\n\tprfName: Pbes2Prf,\n\tusages: KeyUsage[],\n): Promise<CryptoKey> {\n\tconst encryption = resolveEncryptionProfile(encryptionName);\n\tconst prf = resolvePrfProfile(prfName);\n\tconst passwordKey = await getCrypto().subtle.importKey(\n\t\t'raw',\n\t\tnew TextEncoder().encode(password),\n\t\t'PBKDF2',\n\t\tfalse,\n\t\t['deriveKey'],\n\t);\n\treturn getCrypto().subtle.deriveKey(\n\t\t{\n\t\t\tname: 'PBKDF2',\n\t\t\tsalt: toArrayBuffer(salt),\n\t\t\titerations,\n\t\t\thash: prf.hash,\n\t\t},\n\t\tpasswordKey,\n\t\t{ name: 'AES-CBC', length: encryption.keyLengthBits },\n\t\tfalse,\n\t\tusages,\n\t);\n}\n\n/** Parses the optional PRF AlgorithmIdentifier from PBKDF2 params. Absent means HMAC-SHA-1. */\nfunction parsePbkdf2Prf(\n\tpbkdf2Der: Uint8Array,\n\telement: ReturnType<typeof readSequenceChildren>[number] | undefined,\n): Pbes2Prf {\n\tif (element === undefined) {\n\t\treturn 'hmac-sha1';\n\t}\n\tif (element.tag !== 0x30) {\n\t\tthrow new Error('Malformed PBKDF2 PRF');\n\t}\n\tconst prfDer = readSequenceChildren(\n\t\tpbkdf2Der.slice(element.start - element.headerLength, element.end),\n\t);\n\tconst oid = prfDer[0];\n\tif (oid === undefined) {\n\t\tthrow new Error('Malformed PBKDF2 PRF');\n\t}\n\tconst prf = prfFromOid(decodeObjectIdentifier(oid.value));\n\tif (prf === undefined) {\n\t\tthrow new Error('Unsupported PBKDF2 PRF');\n\t}\n\treturn prf;\n}\n\n/** Maps an AES-CBC OID to the encryption profile, or `undefined` if unsupported. */\nfunction encryptionSchemeFromOid(oid: string):\n\t| {\n\t\t\treadonly name: Pbes2EncryptionScheme;\n\t\t\treadonly oid: string;\n\t\t\treadonly keyLengthBits: 128 | 192 | 256;\n\t\t\treadonly keyLengthBytes: 16 | 24 | 32;\n\t }\n\t| undefined {\n\tswitch (oid) {\n\t\tcase OIDS.aes128Cbc:\n\t\t\treturn { name: 'aes128-cbc', oid, keyLengthBits: 128, keyLengthBytes: 16 };\n\t\tcase OIDS.aes192Cbc:\n\t\t\treturn { name: 'aes192-cbc', oid, keyLengthBits: 192, keyLengthBytes: 24 };\n\t\tcase OIDS.aes256Cbc:\n\t\t\treturn { name: 'aes256-cbc', oid, keyLengthBits: 256, keyLengthBytes: 32 };\n\t}\n\treturn undefined;\n}\n\n/** Maps an HMAC OID to the PRF name, or `undefined` if unsupported. */\nfunction prfFromOid(oid: string): Pbes2Prf | undefined {\n\tswitch (oid) {\n\t\tcase OIDS.hmacWithSHA1:\n\t\t\treturn 'hmac-sha1';\n\t\tcase OIDS.hmacWithSHA256:\n\t\t\treturn 'hmac-sha256';\n\t}\n\treturn undefined;\n}\n\n/** Looks up the full encryption profile for a scheme name. Throws if unsupported. */\nfunction resolveEncryptionProfile(name: Pbes2EncryptionScheme): {\n\treadonly name: Pbes2EncryptionScheme;\n\treadonly oid: string;\n\treadonly keyLengthBits: 128 | 192 | 256;\n\treadonly keyLengthBytes: 16 | 24 | 32;\n} {\n\tconst profile = encryptionSchemeFromOid(\n\t\tname === 'aes128-cbc'\n\t\t\t? OIDS.aes128Cbc\n\t\t\t: name === 'aes192-cbc'\n\t\t\t\t? OIDS.aes192Cbc\n\t\t\t\t: OIDS.aes256Cbc,\n\t);\n\tif (profile === undefined) {\n\t\tthrow new Error('Unsupported content encryption scheme');\n\t}\n\treturn profile;\n}\n\n/** Looks up OID and WebCrypto hash name for a PRF. */\nfunction resolvePrfProfile(name: Pbes2Prf): {\n\treadonly oid: string;\n\treadonly hash: 'SHA-1' | 'SHA-256';\n} {\n\tswitch (name) {\n\t\tcase 'hmac-sha1':\n\t\t\treturn { oid: OIDS.hmacWithSHA1, hash: 'SHA-1' };\n\t\tcase 'hmac-sha256':\n\t\t\treturn { oid: OIDS.hmacWithSHA256, hash: 'SHA-256' };\n\t}\n}\n"],"mappings":"wUAwEA,eAAsB,EACrB,EACA,EACiC,CACjC,IAAM,EAAa,EAAQ,YAAc,IACnC,EAAO,EAAQ,MAAQ,EAAU,CAAC,CAAC,gBAAgB,IAAI,WAAW,EAAE,CAAC,EACrE,EAAK,EAAQ,IAAM,EAAU,CAAC,CAAC,gBAAgB,IAAI,WAAW,EAAE,CAAC,EACjE,EAAa,EAAQ,YAAc,aACnC,EAAM,EAAQ,KAAO,cAG3B,GAAI,CAAC,OAAO,UAAU,CAAU,GAAK,EAAa,EACjD,MAAU,WAAW,oDAAoD,GAAY,EAEtF,GAAI,EAAE,aAAgB,aAAe,EAAK,OAAS,EAClD,MAAU,UACT,iEAAiE,EAAK,QACvE,EAED,GAAI,EAAE,aAAc,aAAe,EAAG,SAAW,GAChD,MAAU,UACT,kEAA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AAI,IAAQ,IAAA,GACX,MAAU,MAAM,sBAAsB,EAEvC,IAAM,EAAM,EAAW,EAAuB,EAAI,KAAK,CAAC,EACxD,GAAI,IAAQ,IAAA,GACX,MAAU,MAAM,wBAAwB,EAEzC,OAAO,CACR,CAGA,SAAS,EAAwB,EAOpB,CACZ,OAAQ,EAAR,CACC,KAAK,EAAK,UACT,MAAO,CAAE,KAAM,aAAc,MAAK,cAAe,IAAK,eAAgB,EAAG,EAC1E,KAAK,EAAK,UACT,MAAO,CAAE,KAAM,aAAc,MAAK,cAAe,IAAK,eAAgB,EAAG,EAC1E,KAAK,EAAK,UACT,MAAO,CAAE,KAAM,aAAc,MAAK,cAAe,IAAK,eAAgB,EAAG,CAC3E,CAED,CAGA,SAAS,EAAW,EAAmC,CACtD,OAAQ,EAAR,CACC,KAAK,EAAK,aACT,MAAO,YACR,KAAK,EAAK,eACT,MAAO,aACT,CAED,CAGA,SAAS,EAAyB,EAKhC,CACD,IAAM,EAAU,EACf,IAAS,aACN,EAAK,UACL,IAAS,aACR,EAAK,UACL,EAAK,SACV,EACA,GAAI,IAAY,IAAA,GACf,MAAU,MAAM,uCAAuC,EAExD,OAAO,CACR,CAGA,SAAS,EAAkB,EAGzB,CACD,OAAQ,EAAR,CACC,IAAK,YACJ,MAAO,CAAE,IAAK,EAAK,aAAc,KAAM,OAAQ,EAChD,IAAK,cACJ,MAAO,CAAE,IAAK,EAAK,eAAgB,KAAM,SAAU,CACrD,CACD"}
1
+ {"version":3,"file":"pbes2.js","names":[],"sources":["../../../src/internal/crypto/pbes2.ts"],"sourcesContent":["/**\n * PBES2 password-based encryption and decryption (RFC 8018).\n *\n * Supports AES-CBC-128/192/256 with PBKDF2 using HMAC-SHA-1 or HMAC-SHA-256.\n * Used internally by encrypted PKCS#8 and PFX flows.\n *\n * @module\n */\n\nimport {\n\tdecodeIntegerNumber,\n\tdecodeObjectIdentifier,\n\ttoArrayBuffer,\n} from '#micro509/internal/asn1/asn1.ts';\nimport {\n\tintegerFromNumber,\n\tnullValue,\n\tobjectIdentifier,\n\toctetString,\n\treadSequenceChildren,\n\tsequence,\n} from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport { getCrypto } from './webcrypto.ts';\n\n/**\n * Thrown when PBES2 / AES-CBC decryption fails its integrity check, which in\n * practice means the supplied password was wrong (or the ciphertext was\n * corrupted). Lets callers distinguish a bad password from malformed input.\n */\n/** Module-private brand so {@link isWrongPasswordError} cannot be fooled by look-alike errors. */\nconst wrongPasswordBrand = Symbol('micro509.WrongPasswordError');\n\n/** Builds the branded `Error` (no class) thrown when decryption fails — a wrong password or corrupt content. */\nexport function wrongPasswordError(message: string): Error {\n\treturn Object.assign(new Error(message), {\n\t\tname: 'WrongPasswordError',\n\t\t[wrongPasswordBrand]: true,\n\t});\n}\n\n/** Type guard: was decryption rejected for a wrong password / corrupt content? */\nexport function isWrongPasswordError(value: unknown): value is Error {\n\treturn value instanceof Error && wrongPasswordBrand in value;\n}\n\n/** AES-CBC key sizes supported by this PBES2 implementation. */\nexport type Pbes2EncryptionScheme = 'aes128-cbc' | 'aes192-cbc' | 'aes256-cbc';\n\n/** PBKDF2 pseudo-random function choices. `hmac-sha1` is the RFC default; `hmac-sha256` is preferred. */\nexport type Pbes2Prf = 'hmac-sha1' | 'hmac-sha256';\n\n/** Input for `encryptPbes2`. */\nexport interface Pbes2EncryptionOptions {\n\t/** Password fed to PBKDF2 for key derivation. */\n\treadonly password: string;\n\t/** PBKDF2 iteration count. Default: `100_000`. */\n\treadonly iterations?: number;\n\t/** PBKDF2 salt. Default: 16 cryptographically random bytes. */\n\treadonly salt?: Uint8Array;\n\t/** AES-CBC initialization vector. Default: 16 cryptographically random bytes. */\n\treadonly iv?: Uint8Array;\n\t/** AES key size. Default: `'aes256-cbc'`. */\n\treadonly encryption?: Pbes2EncryptionScheme;\n\t/** PBKDF2 PRF. Default: `'hmac-sha256'`. */\n\treadonly prf?: Pbes2Prf;\n}\n\n/** Resolved PBES2 algorithm parameters, either parsed from DER or built by `encryptPbes2`. */\nexport interface Pbes2Parameters {\n\t/** PBKDF2 iteration count. */\n\treadonly iterations: number;\n\t/** PBKDF2 salt bytes. */\n\treadonly salt: Uint8Array;\n\t/** AES-CBC initialization vector. */\n\treadonly iv: Uint8Array;\n\t/** AES-CBC key-size variant. */\n\treadonly encryption: Pbes2EncryptionScheme;\n\t/** PBKDF2 pseudo-random function. */\n\treadonly prf: Pbes2Prf;\n}\n\n/** Output of `encryptPbes2`: ciphertext plus the DER-encoded AlgorithmIdentifier. */\nexport interface Pbes2EncryptionResult {\n\t/** DER-encoded PBES2 AlgorithmIdentifier SEQUENCE (embeds KDF + cipher params). */\n\treadonly algorithmIdentifierDer: Uint8Array;\n\t/** AES-CBC ciphertext (includes PKCS#7 padding). */\n\treadonly encryptedData: Uint8Array;\n\t/** Resolved algorithm parameters used during encryption. */\n\treadonly parameters: Pbes2Parameters;\n}\n\n/** Encrypts `data` using PBES2 (PBKDF2 + AES-CBC) and returns ciphertext with algorithm params. */\nexport async function encryptPbes2(\n\tdata: Uint8Array,\n\toptions: Pbes2EncryptionOptions,\n): Promise<Pbes2EncryptionResult> {\n\tconst iterations = options.iterations ?? 100_000;\n\tconst salt = options.salt ?? getCrypto().getRandomValues(new Uint8Array(16));\n\tconst iv = options.iv ?? getCrypto().getRandomValues(new Uint8Array(16));\n\tconst encryption = options.encryption ?? 'aes256-cbc';\n\tconst prf = options.prf ?? 'hmac-sha256';\n\n\t// Validate inputs before any WebCrypto calls\n\tif (!Number.isInteger(iterations) || iterations < 1) {\n\t\tthrow new RangeError(`Invalid iterations: must be an integer >= 1, got ${iterations}`);\n\t}\n\tif (!(salt instanceof Uint8Array) || salt.length < 8) {\n\t\tthrow new TypeError(\n\t\t\t`Invalid salt: must be Uint8Array with length >= 8, got length ${salt.length}`,\n\t\t);\n\t}\n\tif (!(iv instanceof Uint8Array) || iv.length !== 16) {\n\t\tthrow new TypeError(\n\t\t\t`Invalid IV: must be Uint8Array of exactly 16 bytes, got length ${iv.length}`,\n\t\t);\n\t}\n\n\tconst key = await deriveAesKey(options.password, salt, iterations, encryption, prf, ['encrypt']);\n\tconst encryptedData = new Uint8Array(\n\t\tawait getCrypto().subtle.encrypt(\n\t\t\t{ name: 'AES-CBC', iv: toArrayBuffer(iv) },\n\t\t\tkey,\n\t\t\ttoArrayBuffer(data),\n\t\t),\n\t);\n\treturn {\n\t\talgorithmIdentifierDer: encodePbes2AlgorithmIdentifier({\n\t\t\titerations,\n\t\t\tsalt,\n\t\t\tiv,\n\t\t\tencryption,\n\t\t\tprf,\n\t\t}),\n\t\tencryptedData,\n\t\tparameters: { iterations, salt, iv, encryption, prf },\n\t};\n}\n\n/** Decrypts PBES2 ciphertext given the DER AlgorithmIdentifier and password. Throws on wrong password. */\nexport async function decryptPbes2(\n\talgorithmIdentifierDer: Uint8Array,\n\tencryptedData: Uint8Array,\n\tpassword: string,\n): Promise<Uint8Array> {\n\tconst parameters = parsePbes2AlgorithmIdentifier(algorithmIdentifierDer);\n\tconst key = await deriveAesKey(\n\t\tpassword,\n\t\tparameters.salt,\n\t\tparameters.iterations,\n\t\tparameters.encryption,\n\t\tparameters.prf,\n\t\t['decrypt'],\n\t);\n\ttry {\n\t\treturn new Uint8Array(\n\t\t\tawait getCrypto().subtle.decrypt(\n\t\t\t\t{ name: 'AES-CBC', iv: toArrayBuffer(parameters.iv) },\n\t\t\t\tkey,\n\t\t\t\ttoArrayBuffer(encryptedData),\n\t\t\t),\n\t\t);\n\t} catch {\n\t\tthrow wrongPasswordError('Invalid password or encrypted content');\n\t}\n}\n\n/** DER-encodes a PBES2 AlgorithmIdentifier SEQUENCE from resolved parameters. */\nexport function encodePbes2AlgorithmIdentifier(parameters: Pbes2Parameters): Uint8Array {\n\tconst encryption = resolveEncryptionProfile(parameters.encryption);\n\tconst prf = resolvePrfProfile(parameters.prf);\n\treturn sequence([\n\t\tobjectIdentifier(OIDS.pbes2),\n\t\tsequence([\n\t\t\tsequence([\n\t\t\t\tobjectIdentifier(OIDS.pbkdf2),\n\t\t\t\tsequence([\n\t\t\t\t\toctetString(parameters.salt),\n\t\t\t\t\tintegerFromNumber(parameters.iterations),\n\t\t\t\t\tintegerFromNumber(encryption.keyLengthBytes),\n\t\t\t\t\tsequence([objectIdentifier(prf.oid), nullValue()]),\n\t\t\t\t]),\n\t\t\t]),\n\t\t\tsequence([objectIdentifier(encryption.oid), octetString(parameters.iv)]),\n\t\t]),\n\t]);\n}\n\n/** Decodes a DER-encoded PBES2 AlgorithmIdentifier into structured {@linkcode Pbes2Parameters}. */\nexport function parsePbes2AlgorithmIdentifier(algorithmIdentifierDer: Uint8Array): Pbes2Parameters {\n\tconst topLevel = readSequenceChildren(algorithmIdentifierDer);\n\tconst oid = topLevel[0];\n\tconst params = topLevel[1];\n\tif (oid === undefined || params === undefined) {\n\t\tthrow new Error('Malformed PBES2 algorithm identifier');\n\t}\n\tif (decodeObjectIdentifier(oid.value) !== OIDS.pbes2) {\n\t\tthrow new Error('Unsupported encryption algorithm');\n\t}\n\tconst paramsDer = algorithmIdentifierDer.slice(params.start - params.headerLength, params.end);\n\tconst pbes2Params = readSequenceChildren(paramsDer);\n\tconst kdf = pbes2Params[0];\n\tconst scheme = pbes2Params[1];\n\tif (kdf === undefined || scheme === undefined) {\n\t\tthrow new Error('Malformed PBES2 params');\n\t}\n\tconst kdfDer = paramsDer.slice(kdf.start - kdf.headerLength, kdf.end);\n\tconst kdfChildren = readSequenceChildren(kdfDer);\n\tconst kdfOid = kdfChildren[0];\n\tconst kdfParams = kdfChildren[1];\n\tif (kdfOid === undefined || kdfParams === undefined) {\n\t\tthrow new Error('Malformed KDF params');\n\t}\n\tif (decodeObjectIdentifier(kdfOid.value) !== OIDS.pbkdf2) {\n\t\tthrow new Error('Unsupported KDF');\n\t}\n\t// PBKDF2 params: SEQUENCE { salt OCTET STRING, iterationCount INTEGER, [keyLength INTEGER], [prf AlgorithmIdentifier] }\n\tconst pbkdf2Der = kdfDer.slice(kdfParams.start - kdfParams.headerLength, kdfParams.end);\n\tconst pbkdf2Params = readSequenceChildren(pbkdf2Der);\n\tconst salt = pbkdf2Params[0];\n\tconst iterations = pbkdf2Params[1];\n\tif (salt === undefined || iterations === undefined || salt.tag !== 0x04) {\n\t\tthrow new Error('Malformed PBKDF2 params');\n\t}\n\tconst keyLengthElement = pbkdf2Params[2];\n\tconst hasExplicitKeyLength = keyLengthElement?.tag === 0x02;\n\tconst prfElement = hasExplicitKeyLength ? pbkdf2Params[3] : keyLengthElement;\n\tconst schemeDer = paramsDer.slice(scheme.start - scheme.headerLength, scheme.end);\n\tconst schemeChildren = readSequenceChildren(schemeDer);\n\tconst schemeOid = schemeChildren[0];\n\tconst iv = schemeChildren[1];\n\tif (schemeOid === undefined || iv === undefined || iv.tag !== 0x04) {\n\t\tthrow new Error('Malformed encryption scheme');\n\t}\n\tconst encryption = encryptionSchemeFromOid(decodeObjectIdentifier(schemeOid.value));\n\tif (encryption === undefined) {\n\t\tthrow new Error('Unsupported content encryption scheme');\n\t}\n\tif (keyLengthElement !== undefined && !hasExplicitKeyLength && keyLengthElement.tag !== 0x30) {\n\t\tthrow new Error('Malformed PBKDF2 params');\n\t}\n\tif (\n\t\thasExplicitKeyLength &&\n\t\tdecodeIntegerNumber(keyLengthElement.value) !== encryption.keyLengthBytes\n\t) {\n\t\tthrow new Error('Unsupported PBKDF2 key length');\n\t}\n\tconst prf = parsePbkdf2Prf(pbkdf2Der, prfElement);\n\n\t// Validate parsed parameters before returning\n\tconst iterationsValue = decodeIntegerNumber(iterations.value);\n\tconst saltValue = new Uint8Array(salt.value);\n\tconst ivValue = new Uint8Array(iv.value);\n\n\tif (iterationsValue < 1) {\n\t\tthrow new RangeError(`Invalid PBES2 iterations: must be >= 1, got ${iterationsValue}`);\n\t}\n\tif (saltValue.length < 8) {\n\t\tthrow new RangeError(`Invalid PBES2 salt: must be >= 8 bytes, got ${saltValue.length}`);\n\t}\n\tif (ivValue.length !== 16) {\n\t\tthrow new RangeError(`Invalid PBES2 IV: must be exactly 16 bytes, got ${ivValue.length}`);\n\t}\n\n\treturn {\n\t\tsalt: saltValue,\n\t\titerations: iterationsValue,\n\t\tiv: ivValue,\n\t\tencryption: encryption.name,\n\t\tprf,\n\t};\n}\n\n/** Derives an AES-CBC `CryptoKey` from a password via PBKDF2. */\nasync function deriveAesKey(\n\tpassword: string,\n\tsalt: Uint8Array,\n\titerations: number,\n\tencryptionName: Pbes2EncryptionScheme,\n\tprfName: Pbes2Prf,\n\tusages: KeyUsage[],\n): Promise<CryptoKey> {\n\tconst encryption = resolveEncryptionProfile(encryptionName);\n\tconst prf = resolvePrfProfile(prfName);\n\tconst passwordKey = await getCrypto().subtle.importKey(\n\t\t'raw',\n\t\tnew TextEncoder().encode(password),\n\t\t'PBKDF2',\n\t\tfalse,\n\t\t['deriveKey'],\n\t);\n\treturn getCrypto().subtle.deriveKey(\n\t\t{\n\t\t\tname: 'PBKDF2',\n\t\t\tsalt: toArrayBuffer(salt),\n\t\t\titerations,\n\t\t\thash: prf.hash,\n\t\t},\n\t\tpasswordKey,\n\t\t{ name: 'AES-CBC', length: encryption.keyLengthBits },\n\t\tfalse,\n\t\tusages,\n\t);\n}\n\n/** Parses the optional PRF AlgorithmIdentifier from PBKDF2 params. Absent means HMAC-SHA-1. */\nfunction parsePbkdf2Prf(\n\tpbkdf2Der: Uint8Array,\n\telement: ReturnType<typeof readSequenceChildren>[number] | undefined,\n): Pbes2Prf {\n\tif (element === undefined) {\n\t\treturn 'hmac-sha1';\n\t}\n\tif (element.tag !== 0x30) {\n\t\tthrow new Error('Malformed PBKDF2 PRF');\n\t}\n\tconst prfDer = readSequenceChildren(\n\t\tpbkdf2Der.slice(element.start - element.headerLength, element.end),\n\t);\n\tconst oid = prfDer[0];\n\tif (oid === undefined) {\n\t\tthrow new Error('Malformed PBKDF2 PRF');\n\t}\n\tconst prf = prfFromOid(decodeObjectIdentifier(oid.value));\n\tif (prf === undefined) {\n\t\tthrow new Error('Unsupported PBKDF2 PRF');\n\t}\n\treturn prf;\n}\n\n/** Maps an AES-CBC OID to the encryption profile, or `undefined` if unsupported. */\nfunction encryptionSchemeFromOid(oid: string):\n\t| {\n\t\t\treadonly name: Pbes2EncryptionScheme;\n\t\t\treadonly oid: string;\n\t\t\treadonly keyLengthBits: 128 | 192 | 256;\n\t\t\treadonly keyLengthBytes: 16 | 24 | 32;\n\t }\n\t| undefined {\n\tswitch (oid) {\n\t\tcase OIDS.aes128Cbc:\n\t\t\treturn { name: 'aes128-cbc', oid, keyLengthBits: 128, keyLengthBytes: 16 };\n\t\tcase OIDS.aes192Cbc:\n\t\t\treturn { name: 'aes192-cbc', oid, keyLengthBits: 192, keyLengthBytes: 24 };\n\t\tcase OIDS.aes256Cbc:\n\t\t\treturn { name: 'aes256-cbc', oid, keyLengthBits: 256, keyLengthBytes: 32 };\n\t}\n\treturn undefined;\n}\n\n/** Maps an HMAC OID to the PRF name, or `undefined` if unsupported. */\nfunction prfFromOid(oid: string): Pbes2Prf | undefined {\n\tswitch (oid) {\n\t\tcase OIDS.hmacWithSHA1:\n\t\t\treturn 'hmac-sha1';\n\t\tcase OIDS.hmacWithSHA256:\n\t\t\treturn 'hmac-sha256';\n\t}\n\treturn undefined;\n}\n\n/** Looks up the full encryption profile for a scheme name. Throws if unsupported. */\nfunction resolveEncryptionProfile(name: Pbes2EncryptionScheme): {\n\treadonly name: Pbes2EncryptionScheme;\n\treadonly oid: string;\n\treadonly keyLengthBits: 128 | 192 | 256;\n\treadonly keyLengthBytes: 16 | 24 | 32;\n} {\n\tconst profile = encryptionSchemeFromOid(\n\t\tname === 'aes128-cbc'\n\t\t\t? OIDS.aes128Cbc\n\t\t\t: name === 'aes192-cbc'\n\t\t\t\t? OIDS.aes192Cbc\n\t\t\t\t: OIDS.aes256Cbc,\n\t);\n\tif (profile === undefined) {\n\t\tthrow new Error('Unsupported content encryption scheme');\n\t}\n\treturn profile;\n}\n\n/** Looks up OID and WebCrypto hash name for a PRF. */\nfunction resolvePrfProfile(name: Pbes2Prf): {\n\treadonly oid: string;\n\treadonly hash: 'SHA-1' | 'SHA-256';\n} {\n\tswitch (name) {\n\t\tcase 'hmac-sha1':\n\t\t\treturn { oid: OIDS.hmacWithSHA1, hash: 'SHA-1' };\n\t\tcase 'hmac-sha256':\n\t\t\treturn { oid: OIDS.hmacWithSHA256, hash: 'SHA-256' };\n\t}\n}\n"],"mappings":"wUA+BA,MAAM,EAAqB,OAAO,6BAA6B,EAG/D,SAAgB,EAAmB,EAAwB,CAC1D,OAAO,OAAO,OAAW,MAAM,CAAO,EAAG,CACxC,KAAM,sBACL,GAAqB,EACvB,CAAC,CACF,CAGA,SAAgB,EAAqB,EAAgC,CACpE,OAAO,aAAiB,OAAS,KAAsB,CACxD,CAiDA,eAAsB,EACrB,EACA,EACiC,CACjC,IAAM,EAAa,EAAQ,YAAc,IACnC,EAAO,EAAQ,MAAQ,EAAU,CAAC,CAAC,gBAAgB,IAAI,WAAW,EAAE,CAAC,EACrE,EAAK,EAAQ,IAAM,EAAU,CAAC,CAAC,gBAAgB,IAAI,WAAW,EAAE,CAAC,EACjE,EAAa,EAAQ,YAAc,aACnC,EAAM,EAAQ,KAAO,cAG3B,GAAI,CAAC,OAAO,UAAU,CAAU,GAAK,EAAa,EACjD,MAAU,WAAW,oDAAoD,GAAY,EAEtF,GAAI,EAAE,aAAgB,aAAe,EAAK,OAAS,EAClD,MAAU,UACT,iEAAiE,EAAK,QACvE,EAED,GAAI,EAAE,aAAc,aAAe,EAAG,SAAW,GAChD,MAAU,UACT,kEAAkE,EAAG,QACtE,EAGD,IAAM,EAAM,MAAM,EAAa,EAAQ,SAAU,EAAM,EAAY,EAAY,EAAK,CAAC,SAAS,CAAC,EACzF,EAAgB,IAAI,WACzB,MAAM,EAAU,CAAC,CAAC,OAAO,QACxB,CAAE,KAAM,UAAW,GAAI,EAAc,CAAE,CAAE,EACzC,EACA,EAAc,CAAI,CACnB,CACD,EACA,MAAO,CACN,uBAA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K,cAAe,IAAK,eAAgB,EAAG,EAC1E,KAAK,EAAK,UACT,MAAO,CAAE,KAAM,aAAc,MAAK,cAAe,IAAK,eAAgB,EAAG,EAC1E,KAAK,EAAK,UACT,MAAO,CAAE,KAAM,aAAc,MAAK,cAAe,IAAK,eAAgB,EAAG,CAC3E,CAED,CAGA,SAAS,EAAW,EAAmC,CACtD,OAAQ,EAAR,CACC,KAAK,EAAK,aACT,MAAO,YACR,KAAK,EAAK,eACT,MAAO,aACT,CAED,CAGA,SAAS,EAAyB,EAKhC,CACD,IAAM,EAAU,EACf,IAAS,aACN,EAAK,UACL,IAAS,aACR,EAAK,UACL,EAAK,SACV,EACA,GAAI,IAAY,IAAA,GACf,MAAU,MAAM,uCAAuC,EAExD,OAAO,CACR,CAGA,SAAS,EAAkB,EAGzB,CACD,OAAQ,EAAR,CACC,IAAK,YACJ,MAAO,CAAE,IAAK,EAAK,aAAc,KAAM,OAAQ,EAChD,IAAK,cACJ,MAAO,CAAE,IAAK,EAAK,eAAgB,KAAM,SAAU,CACrD,CACD"}
@@ -1,2 +1,2 @@
1
- import{readElement as e}from"../asn1/der.js";import{toArrayBuffer as t}from"../asn1/asn1.js";import{OIDS as n}from"../asn1/oids.js";import{getCrypto as r}from"./webcrypto.js";import{importSpkiDer as i}from"../../keys/keys.js";import{parseRsaPssParameters as a}from"./rsa-pss.js";import{alternateEcdsaSignatureEncoding as o}from"./ecdsa.js";function s(e,t,r,i,a=`issuer`){switch(e){case n.sha256WithRSAEncryption:{let e=f(t,`SHA-256 with RSA`);return e===void 0?c(r,`SHA-256`,`pkcs1-v1_5`,a):e}case n.sha384WithRSAEncryption:{let e=f(t,`SHA-384 with RSA`);return e===void 0?c(r,`SHA-384`,`pkcs1-v1_5`,a):e}case n.sha512WithRSAEncryption:{let e=f(t,`SHA-512 with RSA`);return e===void 0?c(r,`SHA-512`,`pkcs1-v1_5`,a):e}case n.rsassaPss:return d(t,r,a);case n.ecdsaWithSHA256:{let e=p(t,`ECDSA with SHA-256`);return e===void 0?l(r,i,`SHA-256`,a):e}case n.ecdsaWithSHA384:{let e=p(t,`ECDSA with SHA-384`);return e===void 0?l(r,i,`SHA-384`,a):e}case n.ecdsaWithSHA512:{let e=p(t,`ECDSA with SHA-512`);return e===void 0?l(r,i,`SHA-512`,a):e}case n.ed25519:{let e=p(t,`Ed25519`);return e===void 0?r===n.ed25519?m({importAlgorithm:{kind:`ed25519`},verifyParams:{name:`Ed25519`}}):h(`Ed25519`,`requires Ed25519 ${a} public key`):e}default:return h(e,`unrecognized signature algorithm OID`)}}function c(e,t,r=`pkcs1-v1_5`,i=`issuer`,a){return e===n.rsaEncryption?m({importAlgorithm:{kind:`rsa`,hash:t,scheme:r},verifyParams:r===`pss`?{name:`RSA-PSS`,saltLength:a??0}:{name:`RSASSA-PKCS1-v1_5`}}):h(`RSA`,`requires RSA ${i} public key`)}function l(e,t,r,i=`issuer`){if(e!==n.ecPublicKey)return h(`ECDSA`,`requires EC ${i} public key`);switch(t){case n.prime256v1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-256`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:64});case n.secp384r1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-384`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:96});case n.secp521r1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-521`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:132});default:return h(`ECDSA`,`unsupported EC curve OID: ${t??`missing`}`)}}async function u(e,n,a,c,l,u,d){let f=s(e,n,a,c);if(!f.ok)return f;try{let e=await i(l,f.value.importAlgorithm),n=r().subtle,a=t(u),s=t(d);if(await n.verify(f.value.verifyParams,e,a,s))return{ok:!0,valid:!0};if(f.value.ecdsaRawSignatureBytes!==void 0){let r=o(u,f.value.ecdsaRawSignatureBytes/2);if(r!==void 0)return{ok:!0,valid:await n.verify(f.value.verifyParams,e,t(r),s)}}return{ok:!0,valid:!1}}catch(e){return g(e instanceof Error?e.message:`signature verification failed`)}}function d(e,t,n){let r=a(e);return r.ok?c(t,r.value.hash,`pss`,n,r.value.saltLength):h(`RSA-PSS`,r.reason)}function f(t,n){if(t===void 0)return h(n,`signature AlgorithmIdentifier parameters must be DER NULL`);try{let r=e(t);return r.tag!==5||r.length!==0||r.end!==t.length?h(n,`signature AlgorithmIdentifier parameters must be DER NULL`):void 0}catch{return h(n,`signature AlgorithmIdentifier parameters must be DER NULL`)}}function p(e,t){if(e!==void 0)return h(t,`signature AlgorithmIdentifier parameters must be absent`)}function m(e){return{ok:!0,value:e}}function h(e,t){return{ok:!1,code:`unsupported_signature_algorithm_parameters`,reason:`${e} parameters unsupported: ${t}`}}function g(e){return{ok:!1,code:`verification_error`,reason:e}}export{s as getVerifySignatureConfigResult,l as requireEcPublicKey,c as requireRsaPublicKey,u as verifySignedDataDetailed};
1
+ import{readElement as e}from"../asn1/der.js";import{toArrayBuffer as t}from"../asn1/asn1.js";import{OIDS as n}from"../asn1/oids.js";import{getCrypto as r}from"./webcrypto.js";import{importSpkiDerOrThrow as i}from"../../keys/keys.js";import{parseRsaPssParameters as a}from"./rsa-pss.js";import{alternateEcdsaSignatureEncoding as o}from"./ecdsa.js";function s(e,t,r,i,a=`issuer`){switch(e){case n.sha256WithRSAEncryption:{let e=f(t,`SHA-256 with RSA`);return e===void 0?c(r,`SHA-256`,`pkcs1-v1_5`,a):e}case n.sha384WithRSAEncryption:{let e=f(t,`SHA-384 with RSA`);return e===void 0?c(r,`SHA-384`,`pkcs1-v1_5`,a):e}case n.sha512WithRSAEncryption:{let e=f(t,`SHA-512 with RSA`);return e===void 0?c(r,`SHA-512`,`pkcs1-v1_5`,a):e}case n.rsassaPss:return d(t,r,a);case n.ecdsaWithSHA256:{let e=p(t,`ECDSA with SHA-256`);return e===void 0?l(r,i,`SHA-256`,a):e}case n.ecdsaWithSHA384:{let e=p(t,`ECDSA with SHA-384`);return e===void 0?l(r,i,`SHA-384`,a):e}case n.ecdsaWithSHA512:{let e=p(t,`ECDSA with SHA-512`);return e===void 0?l(r,i,`SHA-512`,a):e}case n.ed25519:{let e=p(t,`Ed25519`);return e===void 0?r===n.ed25519?m({importAlgorithm:{kind:`ed25519`},verifyParams:{name:`Ed25519`}}):h(`Ed25519`,`requires Ed25519 ${a} public key`):e}default:return h(e,`unrecognized signature algorithm OID`)}}function c(e,t,r=`pkcs1-v1_5`,i=`issuer`,a){return e===n.rsaEncryption?m({importAlgorithm:{kind:`rsa`,hash:t,scheme:r},verifyParams:r===`pss`?{name:`RSA-PSS`,saltLength:a??0}:{name:`RSASSA-PKCS1-v1_5`}}):h(`RSA`,`requires RSA ${i} public key`)}function l(e,t,r,i=`issuer`){if(e!==n.ecPublicKey)return h(`ECDSA`,`requires EC ${i} public key`);switch(t){case n.prime256v1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-256`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:64});case n.secp384r1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-384`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:96});case n.secp521r1:return m({importAlgorithm:{kind:`ecdsa`,curve:`P-521`},verifyParams:{name:`ECDSA`,hash:r},ecdsaRawSignatureBytes:132});default:return h(`ECDSA`,`unsupported EC curve OID: ${t??`missing`}`)}}async function u(e,n,a,c,l,u,d){let f=s(e,n,a,c);if(!f.ok)return f;try{let e=await i(l,f.value.importAlgorithm),n=r().subtle,a=t(u),s=t(d);if(await n.verify(f.value.verifyParams,e,a,s))return{ok:!0,valid:!0};if(f.value.ecdsaRawSignatureBytes!==void 0){let r=o(u,f.value.ecdsaRawSignatureBytes/2);if(r!==void 0)return{ok:!0,valid:await n.verify(f.value.verifyParams,e,t(r),s)}}return{ok:!0,valid:!1}}catch(e){return g(e instanceof Error?e.message:`signature verification failed`)}}function d(e,t,n){let r=a(e);return r.ok?c(t,r.value.hash,`pss`,n,r.value.saltLength):h(`RSA-PSS`,r.reason)}function f(t,n){if(t===void 0)return h(n,`signature AlgorithmIdentifier parameters must be DER NULL`);try{let r=e(t);return r.tag!==5||r.length!==0||r.end!==t.length?h(n,`signature AlgorithmIdentifier parameters must be DER NULL`):void 0}catch{return h(n,`signature AlgorithmIdentifier parameters must be DER NULL`)}}function p(e,t){if(e!==void 0)return h(t,`signature AlgorithmIdentifier parameters must be absent`)}function m(e){return{ok:!0,value:e}}function h(e,t){return{ok:!1,code:`unsupported_signature_algorithm_parameters`,reason:`${e} parameters unsupported: ${t}`}}function g(e){return{ok:!1,code:`verification_error`,reason:e}}export{s as getVerifySignatureConfigResult,l as requireEcPublicKey,c as requireRsaPublicKey,u as verifySignedDataDetailed};
2
2
  //# sourceMappingURL=sig-verify.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sig-verify.js","names":[],"sources":["../../../src/internal/crypto/sig-verify.ts"],"sourcesContent":["/**\n * Signature-verification helpers that resolve parsed algorithm OIDs into WebCrypto\n * verification configuration for higher-level validators.\n *\n * @module\n */\n\nimport { toArrayBuffer } from '#micro509/internal/asn1/asn1.ts';\nimport { readElement } from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport type { PublicKeyImportInput, RsaHash, RsaScheme } from '#micro509/keys/keys.ts';\nimport { importSpkiDer } from '#micro509/keys/keys.ts';\nimport { alternateEcdsaSignatureEncoding } from './ecdsa.ts';\nimport { parseRsaPssParameters } from './rsa-pss.ts';\nimport { getCrypto } from './webcrypto.ts';\n\nexport {\n\talternateEcdsaSignatureEncoding,\n\tconcatFixedWidth,\n\tderEcdsaSignatureToRaw,\n\trawEcdsaSignatureToDer,\n} from './ecdsa.ts';\n\n/** Resolved WebCrypto parameters needed to verify a signature. */\nexport interface VerifySignatureConfig {\n\t/** Algorithm descriptor for importing the signer's public key via {@linkcode importSpkiDer}. */\n\treadonly importAlgorithm: PublicKeyImportInput;\n\t/** WebCrypto `verify()` algorithm parameter. */\n\treadonly verifyParams: Algorithm | EcdsaParams | RsaPssParams;\n\t/** When set, raw ECDSA signatures are this many bytes and may need DER/raw conversion. */\n\treadonly ecdsaRawSignatureBytes?: number;\n}\n\n/** Failure: the signature algorithm or its parameters are not supported. */\nexport interface VerifySignatureConfigFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'unsupported_signature_algorithm_parameters';\n\t/** Human-readable explanation of why the algorithm is unsupported. */\n\treadonly reason: string;\n}\n\n/** Failure: signature verification could not run to completion. */\nexport interface VerifySignedDataFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'verification_error';\n\t/** Human-readable explanation of the verification failure. */\n\treadonly reason: string;\n}\n\n/** Success branch of {@linkcode VerifySignatureConfigResult}. */\ninterface VerifySignatureConfigSuccess {\n\t/** Discriminant for the success branch. */\n\treadonly ok: true;\n\t/** The resolved verification configuration. */\n\treadonly value: VerifySignatureConfig;\n}\n\n/** Result of resolving signature algorithm OIDs into a {@linkcode VerifySignatureConfig}. */\nexport type VerifySignatureConfigResult =\n\t| VerifySignatureConfigSuccess\n\t| VerifySignatureConfigFailure;\n\n/** Success branch of {@linkcode VerifySignedDataResult}. */\ninterface VerifySignedDataSuccess {\n\t/** Discriminant for the success branch. */\n\treadonly ok: true;\n\t/** Whether the cryptographic signature is valid for the given data and key. */\n\treadonly valid: boolean;\n}\n\n/** Result of a full signature verification: validity, unsupported params, or a runtime verification failure. */\nexport type VerifySignedDataResult =\n\t| VerifySignedDataSuccess\n\t| VerifySignatureConfigFailure\n\t| VerifySignedDataFailure;\n\n/**\n * Resolve algorithm OIDs into a {@linkcode VerifySignatureConfig}.\n *\n * Throws on unsupported algorithms. Use {@linkcode getVerifySignatureConfigResult} for\n * a non-throwing variant.\n */\nexport function getVerifySignatureConfig(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tcontext = 'issuer',\n): VerifySignatureConfig {\n\tconst result = getVerifySignatureConfigResult(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t\tcontext,\n\t);\n\tif (!result.ok) {\n\t\tthrow new Error(result.reason);\n\t}\n\treturn result.value;\n}\n\n/** Non-throwing variant of {@linkcode getVerifySignatureConfig} — returns a typed result union. */\nexport function getVerifySignatureConfigResult(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tcontext = 'issuer',\n): VerifySignatureConfigResult {\n\tswitch (signatureAlgorithmOid) {\n\t\tcase OIDS.sha256WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-256 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-256', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.sha384WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-384 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-384', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.sha512WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-512 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-512', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.rsassaPss:\n\t\t\treturn requireRsaPssVerifyConfig(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\tpublicKeyAlgorithmOid,\n\t\t\t\tcontext,\n\t\t\t);\n\t\tcase OIDS.ecdsaWithSHA256: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-256',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-256', context);\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA384: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-384',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-384', context);\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA512: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-512',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-512', context);\n\t\t}\n\t\tcase OIDS.ed25519: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'Ed25519',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\tif (publicKeyAlgorithmOid !== OIDS.ed25519) {\n\t\t\t\treturn unsupported('Ed25519', `requires Ed25519 ${context} public key`);\n\t\t\t}\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ed25519' },\n\t\t\t\tverifyParams: { name: 'Ed25519' },\n\t\t\t});\n\t\t}\n\t\tdefault:\n\t\t\treturn unsupported(signatureAlgorithmOid, 'unrecognized signature algorithm OID');\n\t}\n}\n\n/** Validate that the public key OID is `rsaEncryption` and return an RSA verification config result. */\nexport function requireRsaPublicKey(\n\talgorithmOid: string,\n\thash: RsaHash,\n\tscheme: RsaScheme = 'pkcs1-v1_5',\n\tcontext = 'issuer',\n\tsaltLength?: number,\n): VerifySignatureConfigResult {\n\tif (algorithmOid !== OIDS.rsaEncryption) {\n\t\treturn unsupported('RSA', `requires RSA ${context} public key`);\n\t}\n\tconst verifyParams: Algorithm | RsaPssParams =\n\t\tscheme === 'pss'\n\t\t\t? { name: 'RSA-PSS', saltLength: saltLength ?? 0 }\n\t\t\t: { name: 'RSASSA-PKCS1-v1_5' };\n\treturn ok({ importAlgorithm: { kind: 'rsa', hash, scheme }, verifyParams });\n}\n\n/** Validate that the public key OID is `ecPublicKey`, resolve the curve, and return an ECDSA verification config result. */\nexport function requireEcPublicKey(\n\talgorithmOid: string,\n\tparametersOid: string | undefined,\n\thash: string,\n\tcontext = 'issuer',\n): VerifySignatureConfigResult {\n\tif (algorithmOid !== OIDS.ecPublicKey) {\n\t\treturn unsupported('ECDSA', `requires EC ${context} public key`);\n\t}\n\tswitch (parametersOid) {\n\t\tcase OIDS.prime256v1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-256' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 64,\n\t\t\t});\n\t\tcase OIDS.secp384r1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-384' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 96,\n\t\t\t});\n\t\tcase OIDS.secp521r1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-521' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 132,\n\t\t\t});\n\t\tdefault:\n\t\t\treturn unsupported('ECDSA', `unsupported EC curve OID: ${parametersOid ?? 'missing'}`);\n\t}\n}\n\n/** Return the raw ECDSA signature byte count (r + s) for a given curve OID, if supported. */\nexport function curveBytes(parametersOid: string | undefined): number | undefined {\n\tswitch (parametersOid) {\n\t\tcase OIDS.prime256v1:\n\t\t\treturn 64;\n\t\tcase OIDS.secp384r1:\n\t\t\treturn 96;\n\t\tcase OIDS.secp521r1:\n\t\t\treturn 132;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Verify a signature against the signer's SPKI and the signed TBS bytes.\n *\n * Throws on unsupported algorithms. Use {@linkcode verifySignedDataDetailed} for\n * a non-throwing variant.\n */\nexport async function verifySignedData(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tsubjectPublicKeyInfoDer: Uint8Array,\n\tsignature: Uint8Array,\n\tsignedData: Uint8Array,\n): Promise<boolean> {\n\tconst result = await verifySignedDataDetailed(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t\tsubjectPublicKeyInfoDer,\n\t\tsignature,\n\t\tsignedData,\n\t);\n\tif (!result.ok) {\n\t\tthrow new Error(result.reason);\n\t}\n\treturn result.valid;\n}\n\n/**\n * Non-throwing variant of {@linkcode verifySignedData} — returns a typed\n * {@linkcode VerifySignedDataResult} instead of throwing on unsupported algorithms\n * or runtime verification failures.\n *\n * Tries both DER and raw ECDSA encodings when the first attempt fails.\n */\nexport async function verifySignedDataDetailed(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tsubjectPublicKeyInfoDer: Uint8Array,\n\tsignature: Uint8Array,\n\tsignedData: Uint8Array,\n): Promise<VerifySignedDataResult> {\n\tconst config = getVerifySignatureConfigResult(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t);\n\tif (!config.ok) {\n\t\treturn config;\n\t}\n\ttry {\n\t\tconst key = await importSpkiDer(subjectPublicKeyInfoDer, config.value.importAlgorithm);\n\t\tconst subtle = getCrypto().subtle;\n\t\tconst signatureView = toArrayBuffer(signature);\n\t\tconst dataView = toArrayBuffer(signedData);\n\t\tif (await subtle.verify(config.value.verifyParams, key, signatureView, dataView)) {\n\t\t\treturn { ok: true, valid: true };\n\t\t}\n\t\tif (config.value.ecdsaRawSignatureBytes !== undefined) {\n\t\t\tconst alternate = alternateEcdsaSignatureEncoding(\n\t\t\t\tsignature,\n\t\t\t\tconfig.value.ecdsaRawSignatureBytes / 2,\n\t\t\t);\n\t\t\tif (alternate !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tok: true,\n\t\t\t\t\tvalid: await subtle.verify(\n\t\t\t\t\t\tconfig.value.verifyParams,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttoArrayBuffer(alternate),\n\t\t\t\t\t\tdataView,\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn { ok: true, valid: false };\n\t} catch (error) {\n\t\treturn verificationError(\n\t\t\terror instanceof Error ? error.message : 'signature verification failed',\n\t\t);\n\t}\n}\n\n/** Parse RSA-PSS algorithm parameters and build a verification config, or return failure. */\nfunction requireRsaPssVerifyConfig(\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tcontext: string,\n): VerifySignatureConfigResult {\n\tconst parameters = parseRsaPssParameters(signatureAlgorithmParametersDer);\n\tif (!parameters.ok) {\n\t\treturn unsupported('RSA-PSS', parameters.reason);\n\t}\n\treturn requireRsaPublicKey(\n\t\tpublicKeyAlgorithmOid,\n\t\tparameters.value.hash,\n\t\t'pss',\n\t\tcontext,\n\t\tparameters.value.saltLength,\n\t);\n}\n\nfunction requireDerNullSignatureAlgorithmParameters(\n\tparametersDer: Uint8Array | undefined,\n\talgorithm: string,\n): VerifySignatureConfigFailure | undefined {\n\tif (parametersDer === undefined) {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t}\n\ttry {\n\t\tconst element = readElement(parametersDer);\n\t\tif (element.tag !== 0x05 || element.length !== 0 || element.end !== parametersDer.length) {\n\t\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t}\n}\n\nfunction requireAbsentSignatureAlgorithmParameters(\n\tparametersDer: Uint8Array | undefined,\n\talgorithm: string,\n): VerifySignatureConfigFailure | undefined {\n\tif (parametersDer !== undefined) {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be absent');\n\t}\n\treturn undefined;\n}\n\n/** Wrap a config in a success result. */\nfunction ok(value: VerifySignatureConfig): VerifySignatureConfigSuccess {\n\treturn { ok: true, value };\n}\n\n/** Build an unsupported-algorithm failure result. */\nfunction unsupported(algorithm: string, reason: string): VerifySignatureConfigFailure {\n\treturn {\n\t\tok: false,\n\t\tcode: 'unsupported_signature_algorithm_parameters',\n\t\treason: `${algorithm} parameters unsupported: ${reason}`,\n\t};\n}\n\nfunction verificationError(reason: string): VerifySignedDataFailure {\n\treturn {\n\t\tok: false,\n\t\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B,EAAyC,CACnE,MAAO,CACN,GAAI,GACJ,KAAM,qBACN,QACD,CACD"}
1
+ {"version":3,"file":"sig-verify.js","names":[],"sources":["../../../src/internal/crypto/sig-verify.ts"],"sourcesContent":["/**\n * Signature-verification helpers that resolve parsed algorithm OIDs into WebCrypto\n * verification configuration for higher-level validators.\n *\n * @module\n */\n\nimport { toArrayBuffer } from '#micro509/internal/asn1/asn1.ts';\nimport { readElement } from '#micro509/internal/asn1/der.ts';\nimport { OIDS } from '#micro509/internal/asn1/oids.ts';\nimport type { PublicKeyImportInput, RsaHash, RsaScheme } from '#micro509/keys/keys.ts';\nimport { importSpkiDerOrThrow } from '#micro509/keys/keys.ts';\nimport { alternateEcdsaSignatureEncoding } from './ecdsa.ts';\nimport { parseRsaPssParameters } from './rsa-pss.ts';\nimport { getCrypto } from './webcrypto.ts';\n\nexport {\n\talternateEcdsaSignatureEncoding,\n\tconcatFixedWidth,\n\tderEcdsaSignatureToRaw,\n\trawEcdsaSignatureToDer,\n} from './ecdsa.ts';\n\n/** Resolved WebCrypto parameters needed to verify a signature. */\nexport interface VerifySignatureConfig {\n\t/** Algorithm descriptor for importing the signer's public key via {@linkcode importSpkiDer}. */\n\treadonly importAlgorithm: PublicKeyImportInput;\n\t/** WebCrypto `verify()` algorithm parameter. */\n\treadonly verifyParams: Algorithm | EcdsaParams | RsaPssParams;\n\t/** When set, raw ECDSA signatures are this many bytes and may need DER/raw conversion. */\n\treadonly ecdsaRawSignatureBytes?: number;\n}\n\n/** Failure: the signature algorithm or its parameters are not supported. */\nexport interface VerifySignatureConfigFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'unsupported_signature_algorithm_parameters';\n\t/** Human-readable explanation of why the algorithm is unsupported. */\n\treadonly reason: string;\n}\n\n/** Failure: signature verification could not run to completion. */\nexport interface VerifySignedDataFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'verification_error';\n\t/** Human-readable explanation of the verification failure. */\n\treadonly reason: string;\n}\n\n/** Success branch of {@linkcode VerifySignatureConfigResult}. */\ninterface VerifySignatureConfigSuccess {\n\t/** Discriminant for the success branch. */\n\treadonly ok: true;\n\t/** The resolved verification configuration. */\n\treadonly value: VerifySignatureConfig;\n}\n\n/** Result of resolving signature algorithm OIDs into a {@linkcode VerifySignatureConfig}. */\nexport type VerifySignatureConfigResult =\n\t| VerifySignatureConfigSuccess\n\t| VerifySignatureConfigFailure;\n\n/** Success branch of {@linkcode VerifySignedDataResult}. */\ninterface VerifySignedDataSuccess {\n\t/** Discriminant for the success branch. */\n\treadonly ok: true;\n\t/** Whether the cryptographic signature is valid for the given data and key. */\n\treadonly valid: boolean;\n}\n\n/** Result of a full signature verification: validity, unsupported params, or a runtime verification failure. */\nexport type VerifySignedDataResult =\n\t| VerifySignedDataSuccess\n\t| VerifySignatureConfigFailure\n\t| VerifySignedDataFailure;\n\n/**\n * Resolve algorithm OIDs into a {@linkcode VerifySignatureConfig}.\n *\n * Throws on unsupported algorithms. Use {@linkcode getVerifySignatureConfigResult} for\n * a non-throwing variant.\n */\nexport function getVerifySignatureConfig(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tcontext = 'issuer',\n): VerifySignatureConfig {\n\tconst result = getVerifySignatureConfigResult(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t\tcontext,\n\t);\n\tif (!result.ok) {\n\t\tthrow new Error(result.reason);\n\t}\n\treturn result.value;\n}\n\n/** Non-throwing variant of {@linkcode getVerifySignatureConfig} — returns a typed result union. */\nexport function getVerifySignatureConfigResult(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tcontext = 'issuer',\n): VerifySignatureConfigResult {\n\tswitch (signatureAlgorithmOid) {\n\t\tcase OIDS.sha256WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-256 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-256', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.sha384WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-384 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-384', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.sha512WithRSAEncryption: {\n\t\t\tconst parameters = requireDerNullSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'SHA-512 with RSA',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireRsaPublicKey(publicKeyAlgorithmOid, 'SHA-512', 'pkcs1-v1_5', context);\n\t\t}\n\t\tcase OIDS.rsassaPss:\n\t\t\treturn requireRsaPssVerifyConfig(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\tpublicKeyAlgorithmOid,\n\t\t\t\tcontext,\n\t\t\t);\n\t\tcase OIDS.ecdsaWithSHA256: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-256',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-256', context);\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA384: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-384',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-384', context);\n\t\t}\n\t\tcase OIDS.ecdsaWithSHA512: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'ECDSA with SHA-512',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\treturn requireEcPublicKey(publicKeyAlgorithmOid, publicKeyParametersOid, 'SHA-512', context);\n\t\t}\n\t\tcase OIDS.ed25519: {\n\t\t\tconst parameters = requireAbsentSignatureAlgorithmParameters(\n\t\t\t\tsignatureAlgorithmParametersDer,\n\t\t\t\t'Ed25519',\n\t\t\t);\n\t\t\tif (parameters !== undefined) {\n\t\t\t\treturn parameters;\n\t\t\t}\n\t\t\tif (publicKeyAlgorithmOid !== OIDS.ed25519) {\n\t\t\t\treturn unsupported('Ed25519', `requires Ed25519 ${context} public key`);\n\t\t\t}\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ed25519' },\n\t\t\t\tverifyParams: { name: 'Ed25519' },\n\t\t\t});\n\t\t}\n\t\tdefault:\n\t\t\treturn unsupported(signatureAlgorithmOid, 'unrecognized signature algorithm OID');\n\t}\n}\n\n/** Validate that the public key OID is `rsaEncryption` and return an RSA verification config result. */\nexport function requireRsaPublicKey(\n\talgorithmOid: string,\n\thash: RsaHash,\n\tscheme: RsaScheme = 'pkcs1-v1_5',\n\tcontext = 'issuer',\n\tsaltLength?: number,\n): VerifySignatureConfigResult {\n\tif (algorithmOid !== OIDS.rsaEncryption) {\n\t\treturn unsupported('RSA', `requires RSA ${context} public key`);\n\t}\n\tconst verifyParams: Algorithm | RsaPssParams =\n\t\tscheme === 'pss'\n\t\t\t? { name: 'RSA-PSS', saltLength: saltLength ?? 0 }\n\t\t\t: { name: 'RSASSA-PKCS1-v1_5' };\n\treturn ok({ importAlgorithm: { kind: 'rsa', hash, scheme }, verifyParams });\n}\n\n/** Validate that the public key OID is `ecPublicKey`, resolve the curve, and return an ECDSA verification config result. */\nexport function requireEcPublicKey(\n\talgorithmOid: string,\n\tparametersOid: string | undefined,\n\thash: string,\n\tcontext = 'issuer',\n): VerifySignatureConfigResult {\n\tif (algorithmOid !== OIDS.ecPublicKey) {\n\t\treturn unsupported('ECDSA', `requires EC ${context} public key`);\n\t}\n\tswitch (parametersOid) {\n\t\tcase OIDS.prime256v1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-256' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 64,\n\t\t\t});\n\t\tcase OIDS.secp384r1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-384' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 96,\n\t\t\t});\n\t\tcase OIDS.secp521r1:\n\t\t\treturn ok({\n\t\t\t\timportAlgorithm: { kind: 'ecdsa', curve: 'P-521' },\n\t\t\t\tverifyParams: { name: 'ECDSA', hash },\n\t\t\t\tecdsaRawSignatureBytes: 132,\n\t\t\t});\n\t\tdefault:\n\t\t\treturn unsupported('ECDSA', `unsupported EC curve OID: ${parametersOid ?? 'missing'}`);\n\t}\n}\n\n/** Return the raw ECDSA signature byte count (r + s) for a given curve OID, if supported. */\nexport function curveBytes(parametersOid: string | undefined): number | undefined {\n\tswitch (parametersOid) {\n\t\tcase OIDS.prime256v1:\n\t\t\treturn 64;\n\t\tcase OIDS.secp384r1:\n\t\t\treturn 96;\n\t\tcase OIDS.secp521r1:\n\t\t\treturn 132;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Verify a signature against the signer's SPKI and the signed TBS bytes.\n *\n * Throws on unsupported algorithms. Use {@linkcode verifySignedDataDetailed} for\n * a non-throwing variant.\n */\nexport async function verifySignedData(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tsubjectPublicKeyInfoDer: Uint8Array,\n\tsignature: Uint8Array,\n\tsignedData: Uint8Array,\n): Promise<boolean> {\n\tconst result = await verifySignedDataDetailed(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t\tsubjectPublicKeyInfoDer,\n\t\tsignature,\n\t\tsignedData,\n\t);\n\tif (!result.ok) {\n\t\tthrow new Error(result.reason);\n\t}\n\treturn result.valid;\n}\n\n/**\n * Non-throwing variant of {@linkcode verifySignedData} — returns a typed\n * {@linkcode VerifySignedDataResult} instead of throwing on unsupported algorithms\n * or runtime verification failures.\n *\n * Tries both DER and raw ECDSA encodings when the first attempt fails.\n */\nexport async function verifySignedDataDetailed(\n\tsignatureAlgorithmOid: string,\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tpublicKeyParametersOid: string | undefined,\n\tsubjectPublicKeyInfoDer: Uint8Array,\n\tsignature: Uint8Array,\n\tsignedData: Uint8Array,\n): Promise<VerifySignedDataResult> {\n\tconst config = getVerifySignatureConfigResult(\n\t\tsignatureAlgorithmOid,\n\t\tsignatureAlgorithmParametersDer,\n\t\tpublicKeyAlgorithmOid,\n\t\tpublicKeyParametersOid,\n\t);\n\tif (!config.ok) {\n\t\treturn config;\n\t}\n\ttry {\n\t\tconst key = await importSpkiDerOrThrow(subjectPublicKeyInfoDer, config.value.importAlgorithm);\n\t\tconst subtle = getCrypto().subtle;\n\t\tconst signatureView = toArrayBuffer(signature);\n\t\tconst dataView = toArrayBuffer(signedData);\n\t\tif (await subtle.verify(config.value.verifyParams, key, signatureView, dataView)) {\n\t\t\treturn { ok: true, valid: true };\n\t\t}\n\t\tif (config.value.ecdsaRawSignatureBytes !== undefined) {\n\t\t\tconst alternate = alternateEcdsaSignatureEncoding(\n\t\t\t\tsignature,\n\t\t\t\tconfig.value.ecdsaRawSignatureBytes / 2,\n\t\t\t);\n\t\t\tif (alternate !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tok: true,\n\t\t\t\t\tvalid: await subtle.verify(\n\t\t\t\t\t\tconfig.value.verifyParams,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\ttoArrayBuffer(alternate),\n\t\t\t\t\t\tdataView,\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn { ok: true, valid: false };\n\t} catch (error) {\n\t\treturn verificationError(\n\t\t\terror instanceof Error ? error.message : 'signature verification failed',\n\t\t);\n\t}\n}\n\n/** Parse RSA-PSS algorithm parameters and build a verification config, or return failure. */\nfunction requireRsaPssVerifyConfig(\n\tsignatureAlgorithmParametersDer: Uint8Array | undefined,\n\tpublicKeyAlgorithmOid: string,\n\tcontext: string,\n): VerifySignatureConfigResult {\n\tconst parameters = parseRsaPssParameters(signatureAlgorithmParametersDer);\n\tif (!parameters.ok) {\n\t\treturn unsupported('RSA-PSS', parameters.reason);\n\t}\n\treturn requireRsaPublicKey(\n\t\tpublicKeyAlgorithmOid,\n\t\tparameters.value.hash,\n\t\t'pss',\n\t\tcontext,\n\t\tparameters.value.saltLength,\n\t);\n}\n\nfunction requireDerNullSignatureAlgorithmParameters(\n\tparametersDer: Uint8Array | undefined,\n\talgorithm: string,\n): VerifySignatureConfigFailure | undefined {\n\tif (parametersDer === undefined) {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t}\n\ttry {\n\t\tconst element = readElement(parametersDer);\n\t\tif (element.tag !== 0x05 || element.length !== 0 || element.end !== parametersDer.length) {\n\t\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be DER NULL');\n\t}\n}\n\nfunction requireAbsentSignatureAlgorithmParameters(\n\tparametersDer: Uint8Array | undefined,\n\talgorithm: string,\n): VerifySignatureConfigFailure | undefined {\n\tif (parametersDer !== undefined) {\n\t\treturn unsupported(algorithm, 'signature AlgorithmIdentifier parameters must be absent');\n\t}\n\treturn undefined;\n}\n\n/** Wrap a config in a success result. */\nfunction ok(value: VerifySignatureConfig): VerifySignatureConfigSuccess {\n\treturn { ok: true, value };\n}\n\n/** Build an unsupported-algorithm failure result. */\nfunction unsupported(algorithm: string, reason: string): VerifySignatureConfigFailure {\n\treturn {\n\t\tok: false,\n\t\tcode: 'unsupported_signature_algorithm_parameters',\n\t\treason: `${algorithm} parameters unsupported: ${reason}`,\n\t};\n}\n\nfunction verificationError(reason: string): VerifySignedDataFailure {\n\treturn {\n\t\tok: false,\n\t\tcode: 'verification_error',\n\t\treason,\n\t};\n}\n"],"mappings":"2VA2GA,SAAgB,EACf,EACA,EACA,EACA,EACA,EAAU,SACoB,CAC9B,OAAQ,EAAR,CACC,KAAK,EAAK,wBAAyB,CAClC,IAAM,EAAa,EAClB,EACA,kBACD,EAIA,OAHI,IAAe,IAAA,GAGZ,EAAoB,EAAuB,UAAW,aAAc,CAAO,EAF1E,CAGT,CACA,KAAK,EAAK,wBAAyB,CAClC,IAAM,EAAa,EAClB,EACA,kBACD,EAIA,OAHI,IAAe,IAAA,GAGZ,EAAoB,EAAuB,UAAW,aAAc,CAAO,EAF1E,CAGT,CACA,KAAK,E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