micro509 0.17.1 → 0.19.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 (183) hide show
  1. package/CHANGELOG.md +165 -6
  2. package/dist/crypto/crypto.d.ts +12 -4
  3. package/dist/crypto/crypto.js +30 -17
  4. package/dist/crypto/crypto.js.map +1 -1
  5. package/dist/crypto.d.ts +8 -2
  6. package/dist/der/der.d.ts +14 -4
  7. package/dist/der/der.js +19 -19
  8. package/dist/der/der.js.map +1 -1
  9. package/dist/der.d.ts +26 -2
  10. package/dist/der.js +4 -4
  11. package/dist/index.d.ts +84 -16
  12. package/dist/index.js +19 -19
  13. package/dist/internal/asn1/asn1.d.ts +1 -2
  14. package/dist/internal/asn1/asn1.js +10 -2
  15. package/dist/internal/asn1/asn1.js.map +1 -1
  16. package/dist/internal/asn1/ber.js.map +1 -1
  17. package/dist/internal/asn1/decode-refusal.js.map +1 -1
  18. package/dist/internal/asn1/der.d.ts +1 -2
  19. package/dist/internal/asn1/der.js.map +1 -1
  20. package/dist/internal/asn1/oids.js +71 -353
  21. package/dist/internal/asn1/oids.js.map +1 -1
  22. package/dist/internal/asn1/oids.json.js +357 -0
  23. package/dist/internal/asn1/oids.json.js.map +1 -0
  24. package/dist/internal/crypto/algorithm-names.js +1 -1
  25. package/dist/internal/crypto/algorithm-names.js.map +1 -1
  26. package/dist/internal/crypto/ecdsa.js.map +1 -1
  27. package/dist/internal/crypto/hash.js.map +1 -1
  28. package/dist/internal/crypto/pbes2.d.ts +1 -2
  29. package/dist/internal/crypto/pbes2.js +70 -70
  30. package/dist/internal/crypto/pbes2.js.map +1 -1
  31. package/dist/internal/crypto/prime-ec.js +37 -0
  32. package/dist/internal/crypto/prime-ec.js.map +1 -0
  33. package/dist/internal/crypto/rsa-pss.js +50 -50
  34. package/dist/internal/crypto/rsa-pss.js.map +1 -1
  35. package/dist/internal/crypto/sig-verify.d.ts +41 -2
  36. package/dist/internal/crypto/sig-verify.js +125 -38
  37. package/dist/internal/crypto/sig-verify.js.map +1 -1
  38. package/dist/internal/crypto/signing.d.ts +1 -2
  39. package/dist/internal/crypto/signing.js +26 -26
  40. package/dist/internal/crypto/signing.js.map +1 -1
  41. package/dist/internal/jose/base64url.js.map +1 -1
  42. package/dist/internal/jose/json-data.js +108 -0
  43. package/dist/internal/jose/json-data.js.map +1 -0
  44. package/dist/internal/jose/strict-json.d.ts +1 -2
  45. package/dist/internal/jose/strict-json.js.map +1 -1
  46. package/dist/internal/shared/base64.js.map +1 -1
  47. package/dist/internal/shared/dn.d.ts +1 -2
  48. package/dist/internal/shared/dn.js +1 -1
  49. package/dist/internal/shared/dn.js.map +1 -1
  50. package/dist/internal/shared/idna.js.map +1 -1
  51. package/dist/internal/shared/ip.d.ts +1 -2
  52. package/dist/internal/shared/ip.js.map +1 -1
  53. package/dist/internal/shared/mailbox.js.map +1 -1
  54. package/dist/internal/shared/punycode.js.map +1 -1
  55. package/dist/internal/shared/uri-host.js.map +1 -1
  56. package/dist/internal/verify/name-constraints-engine.js +64 -64
  57. package/dist/internal/verify/name-constraints-engine.js.map +1 -1
  58. package/dist/internal/verify/policy-engine.js +1 -1
  59. package/dist/internal/verify/policy-engine.js.map +1 -1
  60. package/dist/internal/verify/spki-distrust.js.map +1 -1
  61. package/dist/internal/verify/verify-path.d.ts +1 -2
  62. package/dist/internal/verify/verify-path.js +234 -128
  63. package/dist/internal/verify/verify-path.js.map +1 -1
  64. package/dist/internal/x509/directory-name.js +10 -10
  65. package/dist/internal/x509/directory-name.js.map +1 -1
  66. package/dist/internal/x509/extension-bits.js.map +1 -1
  67. package/dist/internal/x509/extension-errors.d.ts +1 -2
  68. package/dist/internal/x509/extension-errors.js.map +1 -1
  69. package/dist/internal/x509/extension-registry.js +18 -18
  70. package/dist/internal/x509/extension-registry.js.map +1 -1
  71. package/dist/internal/x509/general-name-profile.js +9 -9
  72. package/dist/internal/x509/general-name-profile.js.map +1 -1
  73. package/dist/internal/x509/general-name.js +32 -32
  74. package/dist/internal/x509/general-name.js.map +1 -1
  75. package/dist/internal/x509/name-fields.js +1 -1
  76. package/dist/internal/x509/name-fields.js.map +1 -1
  77. package/dist/internal/x509/or-address.js.map +1 -1
  78. package/dist/jose/base64url.d.ts +4 -0
  79. package/dist/jose/base64url.js +14 -0
  80. package/dist/jose/base64url.js.map +1 -0
  81. package/dist/jose/errors.d.ts +9 -3
  82. package/dist/jose/errors.js.map +1 -1
  83. package/dist/jose/jwe.d.ts +64 -0
  84. package/dist/jose/jwe.js +188 -0
  85. package/dist/jose/jwe.js.map +1 -0
  86. package/dist/jose/jwks.d.ts +38 -10
  87. package/dist/jose/jwks.js +156 -96
  88. package/dist/jose/jwks.js.map +1 -1
  89. package/dist/jose/jws.d.ts +8 -6
  90. package/dist/jose/jws.js +216 -170
  91. package/dist/jose/jws.js.map +1 -1
  92. package/dist/jose/jwt.d.ts +8 -2
  93. package/dist/jose/jwt.js +98 -98
  94. package/dist/jose/jwt.js.map +1 -1
  95. package/dist/jose/remote-jwks.d.ts +1 -2
  96. package/dist/jose/remote-jwks.js +106 -108
  97. package/dist/jose/remote-jwks.js.map +1 -1
  98. package/dist/jose.d.ts +15 -4
  99. package/dist/jose.js +7 -5
  100. package/dist/kdf/argon2-arithmetic.js.map +1 -1
  101. package/dist/kdf/argon2-core.js.map +1 -1
  102. package/dist/kdf/argon2-memory.js.map +1 -1
  103. package/dist/kdf/argon2-portable.js.map +1 -1
  104. package/dist/kdf/argon2.d.ts +7 -2
  105. package/dist/kdf/argon2.js.map +1 -1
  106. package/dist/kdf.d.ts +6 -0
  107. package/dist/keys/keys.d.ts +31 -6
  108. package/dist/keys/keys.js +315 -233
  109. package/dist/keys/keys.js.map +1 -1
  110. package/dist/keys.d.ts +11 -2
  111. package/dist/keys.js +2 -2
  112. package/dist/pem/pem.d.ts +1 -2
  113. package/dist/pem/pem.js +40 -25
  114. package/dist/pem/pem.js.map +1 -1
  115. package/dist/pem.d.ts +6 -0
  116. package/dist/pkcs/pfx.d.ts +2 -3
  117. package/dist/pkcs/pfx.js +142 -142
  118. package/dist/pkcs/pfx.js.map +1 -1
  119. package/dist/pkcs/pkcs12-mac.d.ts +1 -2
  120. package/dist/pkcs/pkcs12-mac.js +122 -122
  121. package/dist/pkcs/pkcs12-mac.js.map +1 -1
  122. package/dist/pkcs/pkcs7.d.ts +24 -3
  123. package/dist/pkcs/pkcs7.js +294 -256
  124. package/dist/pkcs/pkcs7.js.map +1 -1
  125. package/dist/pkcs.d.ts +10 -1
  126. package/dist/pkcs.js +4 -4
  127. package/dist/result/result.d.ts +1 -2
  128. package/dist/result/result.js.map +1 -1
  129. package/dist/result.d.ts +6 -0
  130. package/dist/revocation/chain.d.ts +69 -16
  131. package/dist/revocation/chain.js +431 -303
  132. package/dist/revocation/chain.js.map +1 -1
  133. package/dist/revocation/crl.d.ts +67 -14
  134. package/dist/revocation/crl.js +656 -366
  135. package/dist/revocation/crl.js.map +1 -1
  136. package/dist/revocation/ocsp.d.ts +78 -24
  137. package/dist/revocation/ocsp.js +622 -436
  138. package/dist/revocation/ocsp.js.map +1 -1
  139. package/dist/revocation/revocation.d.ts +68 -14
  140. package/dist/revocation/revocation.js +195 -74
  141. package/dist/revocation/revocation.js.map +1 -1
  142. package/dist/revocation.d.ts +14 -5
  143. package/dist/revocation.js +4 -4
  144. package/dist/ssh/ssh.d.ts +2 -3
  145. package/dist/ssh/ssh.js +165 -170
  146. package/dist/ssh/ssh.js.map +1 -1
  147. package/dist/ssh/wire.d.ts +1 -2
  148. package/dist/ssh/wire.js +10 -10
  149. package/dist/ssh/wire.js.map +1 -1
  150. package/dist/ssh.d.ts +8 -0
  151. package/dist/verify/identity.d.ts +3 -4
  152. package/dist/verify/identity.js +33 -33
  153. package/dist/verify/identity.js.map +1 -1
  154. package/dist/verify/name-constraints.d.ts +9 -2
  155. package/dist/verify/policy.d.ts +9 -2
  156. package/dist/verify/verify.d.ts +85 -34
  157. package/dist/verify/verify.js +276 -226
  158. package/dist/verify/verify.js.map +1 -1
  159. package/dist/verify.d.ts +12 -2
  160. package/dist/x509/certificate.d.ts +4 -5
  161. package/dist/x509/certificate.js +40 -40
  162. package/dist/x509/certificate.js.map +1 -1
  163. package/dist/x509/csr.d.ts +3 -4
  164. package/dist/x509/csr.js +15 -15
  165. package/dist/x509/csr.js.map +1 -1
  166. package/dist/x509/extensions.d.ts +1 -2
  167. package/dist/x509/extensions.js +165 -165
  168. package/dist/x509/extensions.js.map +1 -1
  169. package/dist/x509/fingerprint.d.ts +1 -2
  170. package/dist/x509/fingerprint.js.map +1 -1
  171. package/dist/x509/name-text.d.ts +1 -2
  172. package/dist/x509/name-text.js.map +1 -1
  173. package/dist/x509/name.d.ts +1 -2
  174. package/dist/x509/name.js +15 -15
  175. package/dist/x509/name.js.map +1 -1
  176. package/dist/x509/parse.d.ts +9 -6
  177. package/dist/x509/parse.js +394 -394
  178. package/dist/x509/parse.js.map +1 -1
  179. package/dist/x509.d.ts +17 -4
  180. package/dist/x509.js +8 -8
  181. package/package.json +32 -33
  182. package/dist/internal/asn1/oids2.js +0 -75
  183. package/dist/internal/asn1/oids2.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,13 +2,12 @@
2
2
 
3
3
  <!--
4
4
  Release checklist — every box, every release:
5
- - [ ] Move [Unreleased] entries under a new `## [X.Y.Z] - YYYY-MM-DD` header + intro line
6
- - [ ] Bump version in package.json AND jsr.json
5
+ - [ ] Start the release with `beepboop release <bump>` or the Start release workflow; Beepboop opens the version PR that bumps package.json AND jsr.json
6
+ - [ ] On the version PR, move [Unreleased] entries under a new `## [X.Y.Z] - YYYY-MM-DD` header + intro line
7
7
  - [ ] Bump the version in examples/browser/index.html's import map. examples/vite/package.json uses `latest`
8
8
  - [ ] Run `bun install` after the example bump so bun.lock matches; CI installs with a frozen lockfile
9
9
  - [ ] Link definitions at the BOTTOM of this file: add [X.Y.Z] compare link, repoint [Unreleased]
10
- - [ ] Verify the signature on the merged release commit, then create its signed release tag
11
- - [ ] Push the tag to trigger the Publish workflow
10
+ - [ ] Merge the version PR; Beepboop pushes the signed vX.Y.Z tag, which starts the Publish workflow
12
11
  - [ ] Verify npm, JSR, the GitHub release and the documentation deployment
13
12
  -->
14
13
 
@@ -19,6 +18,163 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
18
 
20
19
  ## [Unreleased]
21
20
 
21
+ ## [0.19.0] - 2026-11-16
22
+
23
+ Verify signatures WebCrypto cannot run, such as DSA, with caller verifiers
24
+ across chains, CRLs, OCSP, CSRs and CMS. Revocation checking fails closed in
25
+ more places: delegated OCSP responders and CRL signers need revocation
26
+ evidence, delta CRLs are read newest first through one shared search, and a
27
+ delta CRL the attempt limits leave unread makes the status indeterminate.
28
+
29
+ ### Added
30
+
31
+ - **Caller signature verifiers.** `signatureVerifiers` maps a signature
32
+ algorithm OID to `(input) => Promise<boolean>`. Path building and
33
+ validation, `verifyCertificateChain`, CRL and OCSP verification, chain
34
+ revocation, `checkCertificateRevocation`, `verifyCertificateSigningRequest`,
35
+ `verifyPkcs7SignedData` and `verifySignature` accept it. A verifier runs only
36
+ for a signature native verification refuses, and only a resolved `true`
37
+ counts as valid. Naming a natively verified OID, a non-OID key, one OID
38
+ twice or a non-function throws `RangeError`. The input carries the RFC 5280
39
+ §6.1 working key parameters, so a DSA key without parameters inherits them
40
+ from its path ([RFC 5280 §6.1.4][rfc5280-section-6.1.4]).
41
+ [#14](https://github.com/kjanat/micro509/issues/14)
42
+ - Parsed certificates, CSRs, CRLs and OCSP responses keep a signature's unused
43
+ bit count as `signatureValueUnusedBits`. Native verification fails a
44
+ non-zero count as `signature_invalid`.
45
+ - `checkChainRevocation` takes `trustAnchor`, `distrustedSpkiSha256` and
46
+ `policy.crlSignerSelfEvidence` (`'delegated'` by default, or `'any'`).
47
+ - `unreadSupersededDeltaCrls` on `RevocationPolicy` and
48
+ `checkCertificateRevocation`, and
49
+ `responderRevocationUnreadSupersededDeltaCrls` on `validateOcspResponse`.
50
+ `'indeterminate'` is the default; `'ignore'` skips an unread delta CRL that
51
+ one already read supersedes.
52
+ - The verification guide explains peer authentication: only the transport's
53
+ proof of possession ties the leaf to a TLS peer. A recipe authenticates a
54
+ TLS client by the handshake certificate's SPKI.
55
+ [#236](https://github.com/kjanat/micro509/issues/236)
56
+
57
+ ### Changed
58
+
59
+ - `responderRevocationPolicy` defaults to `'nocheck-or-evidence'`. A delegated
60
+ OCSP responder without `id-pkix-ocsp-nocheck` or `noRevAvail` needs CRL
61
+ evidence and otherwise fails with `responder_revocation_unknown`
62
+ ([RFC 9608 §4][rfc9608-section-4]). `'honor-nocheck'` stays as an opt-in.
63
+ This changes verification defaults.
64
+ - A delegated CRL signer outside the chain needs CRLs covering every reason,
65
+ checked against the issuer its own validated path gives it, and every CA on
66
+ that path outside the chain must be good
67
+ ([RFC 5280 §6.3.3][rfc5280-section-6.3.3]).
68
+ - Chain revocation, CRL signers, delegated responders,
69
+ `checkCertificateRevocation` and `checkCertificateRevocationAgainstCrl` share
70
+ one delta CRL search. It reads applicable delta CRLs newest first, current
71
+ or not. A non-current CRL settles only a revocation other than
72
+ `certificateHold` of an unexpired certificate
73
+ ([RFC 5280 §5.3.1][rfc5280-section-5.3.1]). A delta CRL left unread by the
74
+ 4-per-base and 32-per-call limits yields `delta_crl_retry_limit_exceeded`
75
+ unless the base CRL holds a lasting revocation.
76
+ - `checkCertificateRevocation` checks each distinct complete CRL once with the
77
+ newest applicable delta CRL in its evidence, returns `skipped` with
78
+ `skipReason: 'no_rev_avail'` for a `noRevAvail` certificate, and records
79
+ `delta_crl_unusable`, `delta_crl_retry_limit_exceeded` and `malformed` in
80
+ `details.indeterminateEvidence`.
81
+ - Input that does not decode fails with `malformed` across path building,
82
+ validation, CSR, CRL, OCSP and service identity APIs, instead of a code that
83
+ names a different problem.
84
+ - A negative or non-finite `clockSkewMs` throws `RangeError`.
85
+ - Nested revocation checks share one evaluation instant when `at` is omitted.
86
+
87
+ ### Fixed
88
+
89
+ - A revoked CA directly under a bare trust anchor passed chain revocation.
90
+ - A CRL past its `nextUpdate`, over the age bound or without `nextUpdate`
91
+ reported `stale_crl` for a certificate it revoked, so soft-fail allowed it.
92
+ - Four older current clean delta CRLs could spend the attempt limit ahead of a
93
+ newer expired delta CRL revoking for keyCompromise.
94
+ - An undecodable `deltaCrl` hid a revocation in its complete CRL.
95
+ - A CRL signer outside the chain counted as good without a CRL covering it, or
96
+ under a revoked CA.
97
+ - `verifySignature` and `verifySignatureWithKey` refused a native algorithm
98
+ whose OID had a redundant leading zero.
99
+
100
+ ### Security
101
+
102
+ - Tests cover the three node-forge 1.4.1 advisories: a `pathLenConstraint`
103
+ without keyUsage, deeply nested BIT STRINGs, and non-canonical DigestInfo
104
+ with an e=3 forgery. micro509 needed no change and refuses each case.
105
+ [#256](https://github.com/kjanat/micro509/issues/256)
106
+
107
+ ## [0.18.0] - 2026-11-14
108
+
109
+ Sign and verify JWTs with RS384, RS512, ES256 and ES384, encrypt with compact
110
+ JWE, and migrate from jose with runnable guides and an independent test corpus.
111
+ One function imports any unencrypted private-key PEM, and JWK Sets that arrive
112
+ as parsed objects get the same validation as JSON text.
113
+
114
+ CMS verification now defaults to the application profile: `id-data` content
115
+ with signed attributes from every signer. Callers that accept bare `id-data`
116
+ signatures opt in.
117
+
118
+ ### Added
119
+
120
+ - **Sign and verify RS384, RS512, ES256 and ES384.** `micro509/jose` signs and
121
+ verifies compact JWS and JWT with these algorithms next to RS256, through
122
+ direct keys, local JWK Sets and remote resolvers. Callers accept only the
123
+ algorithms they list. RSA keys are checked for hash, modulus, exponent and
124
+ key usage. ECDSA keys are bound to their exact curve and hash, and signatures
125
+ use the fixed-width raw encoding. EC JWK entries are checked for coordinate
126
+ encoding, width, field range and curve membership. `importJwkEntry(entry)`
127
+ stays RS256, and other algorithms take an explicit argument.
128
+ [#227](https://github.com/kjanat/micro509/issues/227)
129
+ - **Encrypt with compact JWE.** `encryptCompactJwe` and `decryptCompactJwe`
130
+ support RSA-OAEP-512 with A256GCM under an explicit `alg` and `enc` policy.
131
+ Headers and segments are strict and bounded, and `zip` and critical
132
+ extensions are refused. A failed RSA unwrap, a wrong key, a wrong content-key
133
+ length and a failed GCM tag return one refusal, and a failed unwrap continues
134
+ with a random content key as [RFC 7516 §11.5][rfc7516-section-11.5]
135
+ recommends. Decryption returns the plaintext bytes and the authenticated
136
+ protected header members. [#231](https://github.com/kjanat/micro509/issues/231)
137
+ - **Encode and decode base64url.** `micro509/jose` exports `base64UrlEncode` and
138
+ the strict `base64UrlDecode`, which refuses padding, whitespace, noncanonical
139
+ trailing bits and invalid lengths.
140
+ [#232](https://github.com/kjanat/micro509/issues/232)
141
+ - **Validate parsed JWK Sets.** `validateJwks` checks a JWK Set that is already
142
+ a JavaScript object with the rules of `parseJwks`. It reads data without
143
+ calling getters or `toJSON`, rejects non-JSON values and cycles, bounds depth,
144
+ node count and data size, and keeps a detached copy.
145
+ [#229](https://github.com/kjanat/micro509/issues/229)
146
+ - **Import any private-key PEM.** `importPrivateKeyPem` and
147
+ `importPrivateKeyPemOrThrow` accept exactly one PKCS#8, PKCS#1 or SEC1 block
148
+ and pass it to the matching importer. Bundles and encrypted input return
149
+ typed refusals. [#222](https://github.com/kjanat/micro509/issues/222)
150
+ - Key import failures carry the stage, reason and container in their details,
151
+ and a bounded diagnostic replaces native backend messages.
152
+ [#223](https://github.com/kjanat/micro509/issues/223)
153
+ - **Migrate from jose.** The migration guide maps jose APIs to micro509 with
154
+ runnable examples. Recipes cover key generation and import, verified claims
155
+ flowing into application schemas, and an application-owned JWKS cache. 21
156
+ independently signed JWT cases with fixed-clock expectations are reusable in
157
+ consumer tests. [#220](https://github.com/kjanat/micro509/issues/220),
158
+ [#221](https://github.com/kjanat/micro509/issues/221),
159
+ [#224](https://github.com/kjanat/micro509/issues/224),
160
+ [#225](https://github.com/kjanat/micro509/issues/225),
161
+ [#226](https://github.com/kjanat/micro509/issues/226)
162
+
163
+ ### Changed
164
+
165
+ - CMS verification defaults to `id-data` content with signed attributes required
166
+ for every signer. Set `expectedContentTypeOid` for another application content
167
+ type. Legacy bare `id-data` signatures require explicit `signedAttributes:
168
+ 'allowed'` or `'forbidden'`; non-`id-data` always requires signed attributes
169
+ under RFC 5652 §5.3. New typed content-type and attribute-policy failures are
170
+ distinct from invalid signatures. This changes verification defaults.
171
+ [#216](https://github.com/kjanat/micro509/issues/216)
172
+ - Format with kprint through `bun fmt` (`@kjanat/fmt`). TOML formats through
173
+ the Tombi plugin.
174
+ - Releases start from `beepboop release`, the Start release workflow or the
175
+ Beepboop dashboard. Beepboop opens the version PR and, after the merge,
176
+ pushes the signed version tag that starts the Publish workflow.
177
+
22
178
  ## [0.17.1] - 2026-10-26
23
179
 
24
180
  Derive Argon2 keys across supported runtimes with the TypeScript implementation,
@@ -1136,7 +1292,7 @@ stricter typed-contract pass.
1136
1292
  octets ([RFC 5915 §3][rfc5915-section-3], "version SHALL be ... one"). Only the tag was checked, so
1137
1293
  version 0 or 2 was deferred to the WebCrypto backend as a misleading error.
1138
1294
  - PBES2 decryption no longer rejects a PBKDF2 salt shorter than eight bytes. [RFC
1139
- 8018 §4.1][rfc8018-section-4.1] makes the eight-octet minimum a "should" for salt _selection_ and
1295
+ 8018 §4.1][rfc8018-section-4.1] makes the eight-octet minimum a "should" for salt *selection* and
1140
1296
  says the salt need not be checked on receipt, so `openssl pkcs8 -saltlen 4`
1141
1297
  could not be decrypted. The encrypt path keeps the minimum.
1142
1298
  (https://github.com/kjanat/micro509/pull/85)
@@ -2072,7 +2228,9 @@ Initial prerelease. API may change before 1.0.
2072
2228
  - Zero runtime dependencies, WebCrypto-native, tree-shakeable subpath exports;
2073
2229
  runs on Node, Bun, Deno, browsers, and Cloudflare Workers.
2074
2230
 
2075
- [Unreleased]: https://github.com/kjanat/micro509/compare/v0.17.1...HEAD
2231
+ [Unreleased]: https://github.com/kjanat/micro509/compare/v0.19.0...HEAD
2232
+ [0.19.0]: https://github.com/kjanat/micro509/compare/v0.18.0...v0.19.0
2233
+ [0.18.0]: https://github.com/kjanat/micro509/compare/v0.17.1...v0.18.0
2076
2234
  [0.17.1]: https://github.com/kjanat/micro509/compare/v0.17.0...v0.17.1
2077
2235
  [0.17.0]: https://github.com/kjanat/micro509/compare/v0.16.0...v0.17.0
2078
2236
  [0.16.0]: https://github.com/kjanat/micro509/compare/v0.15.0...v0.16.0
@@ -2208,6 +2366,7 @@ Initial prerelease. API may change before 1.0.
2208
2366
  [rfc7468-section-8]: https://www.rfc-editor.org/rfc/rfc7468.html#section-8
2209
2367
  [rfc7468-section-9]: https://www.rfc-editor.org/rfc/rfc7468.html#section-9
2210
2368
  [rfc7468-section-14]: https://www.rfc-editor.org/rfc/rfc7468.html#section-14
2369
+ [rfc7516-section-11.5]: https://www.rfc-editor.org/rfc/rfc7516.html#section-11.5
2211
2370
  [rfc8018-appendix-A.2]: https://www.rfc-editor.org/rfc/rfc8018.html#appendix-A.2
2212
2371
  [rfc8018-section-4.1]: https://www.rfc-editor.org/rfc/rfc8018.html#section-4.1
2213
2372
  [rfc8410-section-5]: https://www.rfc-editor.org/rfc/rfc8410.html#section-5
@@ -1,6 +1,6 @@
1
- import { EcNamedCurve } from "../keys/keys.js";
2
- import { VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "../internal/crypto/sig-verify.js";
1
+ import { SignatureVerifier, SignatureVerifierInput, SignatureVerifiers, VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "../internal/crypto/sig-verify.js";
3
2
  import { SignatureProfileInput } from "../internal/crypto/signing.js";
3
+ import { EcNamedCurve } from "../keys/keys.js";
4
4
  /** Failure: the signature algorithm parameters exceed a micro509 decoding limit. */
5
5
  export interface VerifySignatureLimitFailure {
6
6
  /** Discriminant for the failure branch. */
@@ -34,6 +34,15 @@ export interface VerifySignatureInput {
34
34
  readonly signature: Uint8Array;
35
35
  /** The exact bytes the signature covers. */
36
36
  readonly data: Uint8Array;
37
+ /**
38
+ * Caller verifiers for signature algorithms micro509 does not verify through
39
+ * WebCrypto, keyed by dotted-decimal signature algorithm OID. One runs only
40
+ * where the result would otherwise be
41
+ * `unsupported_signature_algorithm_parameters`, with the parameters in
42
+ * `signerSpkiDer`. A key that micro509 verifies natively, a key that is no OID,
43
+ * or a value that is no function throws `RangeError`.
44
+ */
45
+ readonly signatureVerifiers?: SignatureVerifiers;
37
46
  }
38
47
  /** Input for {@linkcode verifySignatureWithKey}. */
39
48
  export interface VerifySignatureWithKeyInput {
@@ -100,5 +109,4 @@ export declare function ecdsaSignatureDerToRaw(signature: Uint8Array, curve: EcN
100
109
  * Throws when the input length does not match the curve.
101
110
  */
102
111
  export declare function ecdsaSignatureRawToDer(signature: Uint8Array, curve: EcNamedCurve): Uint8Array;
103
- export type { SignatureProfileInput, VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess };
104
- //# sourceMappingURL=crypto.d.ts.map
112
+ export type { SignatureProfileInput, SignatureVerifier, SignatureVerifierInput, SignatureVerifiers, VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess };
@@ -1,7 +1,8 @@
1
- import { DECODE_LIMIT_CODES as e, decodeRefusalOf as t } from "../internal/asn1/decode-refusal.js";
2
- import { derEcdsaSignatureToRaw as n, rawEcdsaSignatureToDer as r } from "../internal/crypto/ecdsa.js";
3
- import { verifySignedDataDetailed as i, verifySignedDataWithKeyDetailed as a } from "../internal/crypto/sig-verify.js";
4
- import { getSignatureAlgorithm as o, signBytes as s } from "../internal/crypto/signing.js";
1
+ import { canonicalizeOid as e } from "../internal/asn1/asn1.js";
2
+ import { DECODE_LIMIT_CODES as t, decodeRefusalOf as n, rethrowDecodeRefusal as r } from "../internal/asn1/decode-refusal.js";
3
+ import { derEcdsaSignatureToRaw as i, rawEcdsaSignatureToDer as a } from "../internal/crypto/ecdsa.js";
4
+ import { callerVerification as o, verifySignedDataDetailed as s, verifySignedDataWithKeyDetailed as c } from "../internal/crypto/sig-verify.js";
5
+ import { getSignatureAlgorithm as l, signBytes as u } from "../internal/crypto/signing.js";
5
6
  // src/crypto/crypto.ts
6
7
  /**
7
8
  * Detached-signature primitives: verify a signature against a signer's SPKI or CryptoKey,
@@ -18,12 +19,12 @@ import { getSignatureAlgorithm as o, signBytes as s } from "../internal/crypto/s
18
19
  * Returns the same validity, unsupported-parameter, operational-error and decoding-limit
19
20
  * branches as {@linkcode verifySignature}.
20
21
  */
21
- async function verifySignatureWithKey(n) {
22
+ async function verifySignatureWithKey(e) {
22
23
  try {
23
- return await a(n.publicKey, n.signatureAlgorithm.oid, n.signatureAlgorithm.parametersDer, n.signature, n.data, n.signatureEncoding);
24
- } catch (n) {
25
- let r = t(n, e);
26
- if (r === void 0) throw n;
24
+ return await c(e.publicKey, canonicalSignatureOid(e.signatureAlgorithm.oid), e.signatureAlgorithm.parametersDer, e.signature, e.data, e.signatureEncoding);
25
+ } catch (e) {
26
+ let r = n(e, t);
27
+ if (r === void 0) throw e;
27
28
  return {
28
29
  ok: !1,
29
30
  code: r.code,
@@ -32,6 +33,18 @@ async function verifySignatureWithKey(n) {
32
33
  }
33
34
  }
34
35
  /**
36
+ * `oid` in its canonical spelling, so dispatch and the caller verifier lookup
37
+ * compare OIDs canonically. A string that is no OID stays as given, and
38
+ * dispatch refuses it.
39
+ */
40
+ function canonicalSignatureOid(n) {
41
+ try {
42
+ return e(n);
43
+ } catch (e) {
44
+ return r(e, t), n;
45
+ }
46
+ }
47
+ /**
35
48
  * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.
36
49
  *
37
50
  * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,
@@ -42,12 +55,12 @@ async function verifySignatureWithKey(n) {
42
55
  * `unsupported_signature_algorithm_parameters`, `verification_error` or
43
56
  * `limit_exceeded` failures otherwise.
44
57
  */
45
- async function verifySignature(n) {
58
+ async function verifySignature(e) {
46
59
  try {
47
- return await i(n.signatureAlgorithm.oid, n.signatureAlgorithm.parametersDer, n.publicKeyAlgorithm.oid, n.publicKeyAlgorithm.parametersOid, n.signerSpkiDer, n.signature, n.data);
48
- } catch (n) {
49
- let r = t(n, e);
50
- if (r === void 0) throw n;
60
+ return await s(canonicalSignatureOid(e.signatureAlgorithm.oid), e.signatureAlgorithm.parametersDer, e.publicKeyAlgorithm.oid, e.publicKeyAlgorithm.parametersOid, e.signerSpkiDer, e.signature, 0, e.data, o(e.signatureVerifiers));
61
+ } catch (e) {
62
+ let r = n(e, t);
63
+ if (r === void 0) throw e;
51
64
  return {
52
65
  ok: !1,
53
66
  code: r.code,
@@ -65,7 +78,7 @@ async function verifySignature(n) {
65
78
  * signatures are returned DER-encoded. Throws on unsupported key algorithms.
66
79
  */
67
80
  async function signData(e, t, n) {
68
- let r = o(e, n), i = await s(e, r, t);
81
+ let r = l(e, n), i = await u(e, r, t);
69
82
  return r.parameters === void 0 ? {
70
83
  signature: i,
71
84
  algorithmOid: r.algorithmOid
@@ -81,7 +94,7 @@ async function signData(e, t, n) {
81
94
  * Throws on malformed DER or integers too large for the curve.
82
95
  */
83
96
  function ecdsaSignatureDerToRaw(e, t) {
84
- return n(e, ecdsaPartLength(t));
97
+ return i(e, ecdsaPartLength(t));
85
98
  }
86
99
  /**
87
100
  * Converts a fixed-width raw `r || s` ECDSA signature to the DER
@@ -89,7 +102,7 @@ function ecdsaSignatureDerToRaw(e, t) {
89
102
  * Throws when the input length does not match the curve.
90
103
  */
91
104
  function ecdsaSignatureRawToDer(e, t) {
92
- return r(e, ecdsaPartLength(t));
105
+ return a(e, ecdsaPartLength(t));
93
106
  }
94
107
  /** Byte width of one ECDSA signature integer for the given curve. */
95
108
  function ecdsaPartLength(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.js","names":["_exhaustive","verifySignedDataWithKeyDetailed","input","error","refusal","decodeRefusalOf","DECODE_LIMIT_CODES","verifySignedDataDetailed","algorithm","getSignatureAlgorithm","privateKey","profile","signature","signBytes","data","derEcdsaSignatureToRaw","curve","rawEcdsaSignatureToDer"],"sources":["../../src/crypto/crypto.ts"],"sourcesContent":["/**\n * Detached-signature primitives: verify a signature against a signer's SPKI or CryptoKey,\n * sign arbitrary bytes with a WebCrypto private key, and convert ECDSA\n * signatures between DER `ECDSA-Sig-Value` and fixed-width raw encodings.\n *\n * @module\n */\n\nimport { DECODE_LIMIT_CODES, decodeRefusalOf } from '#micro509/internal/asn1/decode-refusal';\nimport { derEcdsaSignatureToRaw, rawEcdsaSignatureToDer } from '#micro509/internal/crypto/ecdsa';\nimport type { VerifySignedDataResult } from '#micro509/internal/crypto/sig-verify';\nimport {\n\tverifySignedDataDetailed,\n\tverifySignedDataWithKeyDetailed,\n} from '#micro509/internal/crypto/sig-verify';\nimport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\nimport { getSignatureAlgorithm, signBytes } from '#micro509/internal/crypto/signing';\nimport type { EcNamedCurve } from '#micro509/keys/keys';\n\nexport type {\n\tVerifySignatureConfigFailure,\n\tVerifySignedDataFailure,\n\tVerifySignedDataResult,\n\tVerifySignedDataSuccess,\n} from '#micro509/internal/crypto/sig-verify';\nexport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\n\n/** Failure: the signature algorithm parameters exceed a micro509 decoding limit. */\nexport interface VerifySignatureLimitFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'limit_exceeded';\n\t/** Human-readable description of the limit. */\n\treadonly reason: string;\n}\n\n/** Result of {@linkcode verifySignature} and {@linkcode verifySignatureWithKey}. */\nexport type VerifySignatureResult = VerifySignedDataResult | VerifySignatureLimitFailure;\n\n/** Input for {@linkcode verifySignature}. */\nexport interface VerifySignatureInput {\n\t/** DER `SubjectPublicKeyInfo` of the signer (`subjectPublicKeyInfoDer` on a parsed certificate). */\n\treadonly signerSpkiDer: Uint8Array;\n\t/** The signature algorithm as carried beside the signature. */\n\treadonly signatureAlgorithm: {\n\t\t/** Dotted-decimal signature algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** DER algorithm parameters when the algorithm carries them (RSA-PSS). */\n\t\treadonly parametersDer?: Uint8Array;\n\t};\n\t/** The signer's public key algorithm as carried in its SPKI. */\n\treadonly publicKeyAlgorithm: {\n\t\t/** Dotted-decimal public key algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** Named-curve or scheme parameters OID, when present. */\n\t\treadonly parametersOid?: string;\n\t};\n\t/** The signature bytes. ECDSA accepts DER or raw encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n}\n\n/** Input for {@linkcode verifySignatureWithKey}. */\nexport interface VerifySignatureWithKeyInput {\n\t/** An existing public key with verify usage; extractability is not required. */\n\treadonly publicKey: CryptoKey;\n\t/** Explicit signature OID and parameters, including RSA-PSS salt length. */\n\treadonly signatureAlgorithm: VerifySignatureInput['signatureAlgorithm'];\n\t/** ECDSA accepts raw r || s or DER; RSA and Ed25519 require raw. No encoding retry occurs. */\n\treadonly signatureEncoding: 'raw' | 'der';\n\t/** The signature bytes in the declared encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n}\n\n/**\n * Verifies a detached signature using an existing WebCrypto public key without\n * exporting or importing it. Repeated calls may reuse non-extractable keys.\n * Signature algorithms and parameters follow {@linkcode verifySignature}; RSA\n * scheme and hash must match the key. ECDSA encoding is explicit and never retried.\n * Returns the same validity, unsupported-parameter, operational-error and decoding-limit\n * branches as {@linkcode verifySignature}.\n */\nexport async function verifySignatureWithKey(\n\tinput: VerifySignatureWithKeyInput,\n): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataWithKeyDetailed(\n\t\t\tinput.publicKey,\n\t\t\tinput.signatureAlgorithm.oid,\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.signature,\n\t\t\tinput.data,\n\t\t\tinput.signatureEncoding,\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) throw error;\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/** Result of {@linkcode signData}: the signature plus its on-wire algorithm identity. */\nexport interface SignDataResult {\n\t/** The signature bytes. ECDSA is DER `ECDSA-Sig-Value`, everything else raw. */\n\treadonly signature: Uint8Array;\n\t/** Dotted-decimal signature algorithm OID. */\n\treadonly algorithmOid: string;\n\t/** DER algorithm parameters when the algorithm carries them (NULL for PKCS#1 v1.5, RSA-PSS params). */\n\treadonly parametersDer?: Uint8Array;\n}\n\n/**\n * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.\n *\n * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,\n * ECDSA P-256/P-384/P-521, and Ed25519. When an ECDSA signature fails to\n * verify under one encoding, the alternate DER/raw encoding is retried.\n *\n * Returns a typed union: `{ ok: true, valid }` when verification ran,\n * `unsupported_signature_algorithm_parameters`, `verification_error` or\n * `limit_exceeded` failures otherwise.\n */\nexport async function verifySignature(input: VerifySignatureInput): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataDetailed(\n\t\t\tinput.signatureAlgorithm.oid,\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.publicKeyAlgorithm.oid,\n\t\t\tinput.publicKeyAlgorithm.parametersOid,\n\t\t\tinput.signerSpkiDer,\n\t\t\tinput.signature,\n\t\t\tinput.data,\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) {\n\t\t\tthrow error;\n\t\t}\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/**\n * Signs `data` with a WebCrypto private key and returns the signature beside\n * the resolved `AlgorithmIdentifier` material for embedding in a signed\n * structure.\n *\n * The algorithm is inferred from the key (RSASSA-PKCS1-v1_5, ECDSA, Ed25519);\n * RSA-PSS keys require an explicit `{ kind: 'rsa-pss' }` profile. ECDSA\n * signatures are returned DER-encoded. Throws on unsupported key algorithms.\n */\nexport async function signData(\n\tprivateKey: CryptoKey,\n\tdata: Uint8Array,\n\tprofile?: SignatureProfileInput,\n): Promise<SignDataResult> {\n\tconst algorithm = getSignatureAlgorithm(privateKey, profile);\n\tconst signature = await signBytes(privateKey, algorithm, data);\n\treturn algorithm.parameters === undefined\n\t\t? { signature, algorithmOid: algorithm.algorithmOid }\n\t\t: { signature, algorithmOid: algorithm.algorithmOid, parametersDer: algorithm.parameters };\n}\n\n/**\n * Converts a DER `ECDSA-Sig-Value` (RFC 5480: SEQUENCE of INTEGERs r and s)\n * to the fixed-width raw `r || s` encoding WebCrypto and JOSE use.\n * Throws on malformed DER or integers too large for the curve.\n */\nexport function ecdsaSignatureDerToRaw(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn derEcdsaSignatureToRaw(signature, ecdsaPartLength(curve));\n}\n\n/**\n * Converts a fixed-width raw `r || s` ECDSA signature to the DER\n * `ECDSA-Sig-Value` encoding X.509 and CMS structures embed.\n * Throws when the input length does not match the curve.\n */\nexport function ecdsaSignatureRawToDer(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn rawEcdsaSignatureToDer(signature, ecdsaPartLength(curve));\n}\n\n/** Byte width of one ECDSA signature integer for the given curve. */\nfunction ecdsaPartLength(curve: EcNamedCurve): number {\n\tswitch (curve) {\n\t\tcase 'P-256':\n\t\t\treturn 32;\n\t\tcase 'P-384':\n\t\t\treturn 48;\n\t\tcase 'P-521':\n\t\t\treturn 66;\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = curve;\n\t\t\tthrow new Error(`Unhandled EcNamedCurve: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsFA,eAAsB,uBACrB,GACiC;CACjC,IAAI;EACH,OAAO,MAAMC,EACZC,EAAM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;EACR,SAEC,MAAU,MAAM,2BAA2B,OAAOhB,CAAW,GAAG;CAElE;AACD"}
1
+ {"version":3,"file":"crypto.js","names":["_exhaustive","canonicalizeOid","DECODE_LIMIT_CODES","decodeRefusalOf","rethrowDecodeRefusal","derEcdsaSignatureToRaw","rawEcdsaSignatureToDer","callerVerification","verifySignedDataDetailed","verifySignedDataWithKeyDetailed","getSignatureAlgorithm","signBytes","input","error","refusal","oid","privateKey","data","profile","algorithm","signature","curve"],"sources":["../../src/crypto/crypto.ts"],"sourcesContent":["/**\n * Detached-signature primitives: verify a signature against a signer's SPKI or CryptoKey,\n * sign arbitrary bytes with a WebCrypto private key, and convert ECDSA\n * signatures between DER `ECDSA-Sig-Value` and fixed-width raw encodings.\n *\n * @module\n */\n\nimport { canonicalizeOid } from '#micro509/internal/asn1/asn1';\nimport {\n\tDECODE_LIMIT_CODES,\n\tdecodeRefusalOf,\n\trethrowDecodeRefusal,\n} from '#micro509/internal/asn1/decode-refusal';\nimport { derEcdsaSignatureToRaw, rawEcdsaSignatureToDer } from '#micro509/internal/crypto/ecdsa';\nimport type {\n\tSignatureVerifiers,\n\tVerifySignedDataResult,\n} from '#micro509/internal/crypto/sig-verify';\nimport {\n\tcallerVerification,\n\tverifySignedDataDetailed,\n\tverifySignedDataWithKeyDetailed,\n} from '#micro509/internal/crypto/sig-verify';\nimport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\nimport { getSignatureAlgorithm, signBytes } from '#micro509/internal/crypto/signing';\nimport type { EcNamedCurve } from '#micro509/keys/keys';\n\nexport type {\n\tSignatureVerifier,\n\tSignatureVerifierInput,\n\tSignatureVerifiers,\n\tVerifySignatureConfigFailure,\n\tVerifySignedDataFailure,\n\tVerifySignedDataResult,\n\tVerifySignedDataSuccess,\n} from '#micro509/internal/crypto/sig-verify';\nexport type { SignatureProfileInput } from '#micro509/internal/crypto/signing';\n\n/** Failure: the signature algorithm parameters exceed a micro509 decoding limit. */\nexport interface VerifySignatureLimitFailure {\n\t/** Discriminant for the failure branch. */\n\treadonly ok: false;\n\t/** Machine-readable failure code. */\n\treadonly code: 'limit_exceeded';\n\t/** Human-readable description of the limit. */\n\treadonly reason: string;\n}\n\n/** Result of {@linkcode verifySignature} and {@linkcode verifySignatureWithKey}. */\nexport type VerifySignatureResult = VerifySignedDataResult | VerifySignatureLimitFailure;\n\n/** Input for {@linkcode verifySignature}. */\nexport interface VerifySignatureInput {\n\t/** DER `SubjectPublicKeyInfo` of the signer (`subjectPublicKeyInfoDer` on a parsed certificate). */\n\treadonly signerSpkiDer: Uint8Array;\n\t/** The signature algorithm as carried beside the signature. */\n\treadonly signatureAlgorithm: {\n\t\t/** Dotted-decimal signature algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** DER algorithm parameters when the algorithm carries them (RSA-PSS). */\n\t\treadonly parametersDer?: Uint8Array;\n\t};\n\t/** The signer's public key algorithm as carried in its SPKI. */\n\treadonly publicKeyAlgorithm: {\n\t\t/** Dotted-decimal public key algorithm OID. */\n\t\treadonly oid: string;\n\t\t/** Named-curve or scheme parameters OID, when present. */\n\t\treadonly parametersOid?: string;\n\t};\n\t/** The signature bytes. ECDSA accepts DER or raw encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n\t/**\n\t * Caller verifiers for signature algorithms micro509 does not verify through\n\t * WebCrypto, keyed by dotted-decimal signature algorithm OID. One runs only\n\t * where the result would otherwise be\n\t * `unsupported_signature_algorithm_parameters`, with the parameters in\n\t * `signerSpkiDer`. A key that micro509 verifies natively, a key that is no OID,\n\t * or a value that is no function throws `RangeError`.\n\t */\n\treadonly signatureVerifiers?: SignatureVerifiers;\n}\n\n/** Input for {@linkcode verifySignatureWithKey}. */\nexport interface VerifySignatureWithKeyInput {\n\t/** An existing public key with verify usage; extractability is not required. */\n\treadonly publicKey: CryptoKey;\n\t/** Explicit signature OID and parameters, including RSA-PSS salt length. */\n\treadonly signatureAlgorithm: VerifySignatureInput['signatureAlgorithm'];\n\t/** ECDSA accepts raw r || s or DER; RSA and Ed25519 require raw. No encoding retry occurs. */\n\treadonly signatureEncoding: 'raw' | 'der';\n\t/** The signature bytes in the declared encoding. */\n\treadonly signature: Uint8Array;\n\t/** The exact bytes the signature covers. */\n\treadonly data: Uint8Array;\n}\n\n/**\n * Verifies a detached signature using an existing WebCrypto public key without\n * exporting or importing it. Repeated calls may reuse non-extractable keys.\n * Signature algorithms and parameters follow {@linkcode verifySignature}; RSA\n * scheme and hash must match the key. ECDSA encoding is explicit and never retried.\n * Returns the same validity, unsupported-parameter, operational-error and decoding-limit\n * branches as {@linkcode verifySignature}.\n */\nexport async function verifySignatureWithKey(\n\tinput: VerifySignatureWithKeyInput,\n): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataWithKeyDetailed(\n\t\t\tinput.publicKey,\n\t\t\tcanonicalSignatureOid(input.signatureAlgorithm.oid),\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.signature,\n\t\t\tinput.data,\n\t\t\tinput.signatureEncoding,\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) throw error;\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/**\n * `oid` in its canonical spelling, so dispatch and the caller verifier lookup\n * compare OIDs canonically. A string that is no OID stays as given, and\n * dispatch refuses it.\n */\nfunction canonicalSignatureOid(oid: string): string {\n\ttry {\n\t\treturn canonicalizeOid(oid);\n\t} catch (error) {\n\t\trethrowDecodeRefusal(error, DECODE_LIMIT_CODES);\n\t\treturn oid;\n\t}\n}\n\n/** Result of {@linkcode signData}: the signature plus its on-wire algorithm identity. */\nexport interface SignDataResult {\n\t/** The signature bytes. ECDSA is DER `ECDSA-Sig-Value`, everything else raw. */\n\treadonly signature: Uint8Array;\n\t/** Dotted-decimal signature algorithm OID. */\n\treadonly algorithmOid: string;\n\t/** DER algorithm parameters when the algorithm carries them (NULL for PKCS#1 v1.5, RSA-PSS params). */\n\treadonly parametersDer?: Uint8Array;\n}\n\n/**\n * Verifies a detached signature against the signer's DER `SubjectPublicKeyInfo`.\n *\n * Supports RSA PKCS#1 v1.5 (SHA-256/384/512), RSA-PSS with parsed parameters,\n * ECDSA P-256/P-384/P-521, and Ed25519. When an ECDSA signature fails to\n * verify under one encoding, the alternate DER/raw encoding is retried.\n *\n * Returns a typed union: `{ ok: true, valid }` when verification ran,\n * `unsupported_signature_algorithm_parameters`, `verification_error` or\n * `limit_exceeded` failures otherwise.\n */\nexport async function verifySignature(input: VerifySignatureInput): Promise<VerifySignatureResult> {\n\ttry {\n\t\treturn await verifySignedDataDetailed(\n\t\t\tcanonicalSignatureOid(input.signatureAlgorithm.oid),\n\t\t\tinput.signatureAlgorithm.parametersDer,\n\t\t\tinput.publicKeyAlgorithm.oid,\n\t\t\tinput.publicKeyAlgorithm.parametersOid,\n\t\t\tinput.signerSpkiDer,\n\t\t\tinput.signature,\n\t\t\t0,\n\t\t\tinput.data,\n\t\t\tcallerVerification(input.signatureVerifiers),\n\t\t);\n\t} catch (error) {\n\t\tconst refusal = decodeRefusalOf(error, DECODE_LIMIT_CODES);\n\t\tif (refusal === undefined) {\n\t\t\tthrow error;\n\t\t}\n\t\treturn { ok: false, code: refusal.code, reason: refusal.message };\n\t}\n}\n\n/**\n * Signs `data` with a WebCrypto private key and returns the signature beside\n * the resolved `AlgorithmIdentifier` material for embedding in a signed\n * structure.\n *\n * The algorithm is inferred from the key (RSASSA-PKCS1-v1_5, ECDSA, Ed25519);\n * RSA-PSS keys require an explicit `{ kind: 'rsa-pss' }` profile. ECDSA\n * signatures are returned DER-encoded. Throws on unsupported key algorithms.\n */\nexport async function signData(\n\tprivateKey: CryptoKey,\n\tdata: Uint8Array,\n\tprofile?: SignatureProfileInput,\n): Promise<SignDataResult> {\n\tconst algorithm = getSignatureAlgorithm(privateKey, profile);\n\tconst signature = await signBytes(privateKey, algorithm, data);\n\treturn algorithm.parameters === undefined\n\t\t? { signature, algorithmOid: algorithm.algorithmOid }\n\t\t: { signature, algorithmOid: algorithm.algorithmOid, parametersDer: algorithm.parameters };\n}\n\n/**\n * Converts a DER `ECDSA-Sig-Value` (RFC 5480: SEQUENCE of INTEGERs r and s)\n * to the fixed-width raw `r || s` encoding WebCrypto and JOSE use.\n * Throws on malformed DER or integers too large for the curve.\n */\nexport function ecdsaSignatureDerToRaw(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn derEcdsaSignatureToRaw(signature, ecdsaPartLength(curve));\n}\n\n/**\n * Converts a fixed-width raw `r || s` ECDSA signature to the DER\n * `ECDSA-Sig-Value` encoding X.509 and CMS structures embed.\n * Throws when the input length does not match the curve.\n */\nexport function ecdsaSignatureRawToDer(signature: Uint8Array, curve: EcNamedCurve): Uint8Array {\n\treturn rawEcdsaSignatureToDer(signature, ecdsaPartLength(curve));\n}\n\n/** Byte width of one ECDSA signature integer for the given curve. */\nfunction ecdsaPartLength(curve: EcNamedCurve): number {\n\tswitch (curve) {\n\t\tcase 'P-256':\n\t\t\treturn 32;\n\t\tcase 'P-384':\n\t\t\treturn 48;\n\t\tcase 'P-521':\n\t\t\treturn 66;\n\t\tdefault: {\n\t\t\tconst _exhaustive: never = curve;\n\t\t\tthrow new Error(`Unhandled EcNamedCurve: ${String(_exhaustive)}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2GA,eAAsB,uBACrBY,GACiC;CACjC,IAAI;EACH,OAAO,MAAMH,EACZG,EAAM,WACN,sBAAsBA,EAAM,mBAAmB,GAAG,GAClDA,EAAM,mBAAmB,eACzBA,EAAM,WACNA,EAAM,MACNA,EAAM,iBACP;CACD,SAASC,GAAO;EACf,IAAMC,IAAUX,EAAgBU,GAAOX,CAAkB;EACzD,IAAIY,MAAY,KAAA,GAAW,MAAMD;EACjC,OAAO;GAAE,IAAI;GAAO,MAAMC,EAAQ;GAAM,QAAQA,EAAQ;EAAQ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AAW,GAAG;CAElE;AACD"}
package/dist/crypto.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "./internal/crypto/sig-verify.js";
1
+ /**
2
+ * Canonical detached-signature crypto surface.
3
+ * Owns raw sign/verify primitives and ECDSA signature encoding conversion.
4
+ *
5
+ * @module micro509/crypto
6
+ */
7
+ import { SignatureVerifier, SignatureVerifierInput, SignatureVerifiers, VerifySignatureConfigFailure, VerifySignedDataFailure, VerifySignedDataResult, VerifySignedDataSuccess } from "./internal/crypto/sig-verify.js";
2
8
  import { SignatureProfileInput } from "./internal/crypto/signing.js";
3
9
  import { SignDataResult, VerifySignatureInput, VerifySignatureLimitFailure, VerifySignatureResult, VerifySignatureWithKeyInput, ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey } from "./crypto/crypto.js";
4
- export { type SignDataResult, type SignatureProfileInput, type VerifySignatureConfigFailure, type VerifySignatureInput, type VerifySignatureLimitFailure, type VerifySignatureResult, type VerifySignatureWithKeyInput, type VerifySignedDataFailure, type VerifySignedDataResult, type VerifySignedDataSuccess, ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey };
10
+ export { type SignDataResult, type SignatureProfileInput, type SignatureVerifier, type SignatureVerifierInput, type SignatureVerifiers, type VerifySignatureConfigFailure, type VerifySignatureInput, type VerifySignatureLimitFailure, type VerifySignatureResult, type VerifySignatureWithKeyInput, type VerifySignedDataFailure, type VerifySignedDataResult, type VerifySignedDataSuccess, ecdsaSignatureDerToRaw, ecdsaSignatureRawToDer, signData, verifySignature, verifySignatureWithKey };
package/dist/der/der.d.ts CHANGED
@@ -1,6 +1,17 @@
1
- import { DecodeFailureCode, ErrorResult, Micro509Error } from "../result/result.js";
2
- import { DerElement, ReadRootElementOptions, ReadSequenceChildrenOptions } from "../internal/asn1/der.js";
1
+ /**
2
+ * Element-oriented DER readers and decoders.
3
+ *
4
+ * Each decoder validates the element's tag before reading its value, so a
5
+ * mis-tagged element fails instead of yielding a wrong value.
6
+ *
7
+ * The `OrThrow` variants throw on malformed input.
8
+ * The plain variants return a {@linkcode DecodeDerResult}.
9
+ *
10
+ * @module
11
+ */
3
12
  import { DerBitString } from "../internal/asn1/asn1.js";
13
+ import { DerElement, ReadRootElementOptions, ReadSequenceChildrenOptions } from "../internal/asn1/der.js";
14
+ import { DecodeFailureCode, ErrorResult, Micro509Error } from "../result/result.js";
4
15
  /**
5
16
  * Machine-readable failure reason for the DER readers and decoders.
6
17
  *
@@ -131,5 +142,4 @@ export declare function decodeDerString(element: DerElement): DecodeDerResult<st
131
142
  */
132
143
  export declare function decodeDerTimeOrThrow(element: DerElement): Date;
133
144
  /** Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. */
134
- export declare function decodeDerTime(element: DerElement): DecodeDerResult<Date>;
135
- //# sourceMappingURL=der.d.ts.map
145
+ export declare function decodeDerTime(element: DerElement): DecodeDerResult<Date>;
package/dist/der/der.js CHANGED
@@ -1,13 +1,13 @@
1
- import { DECODE_REFUSAL_CODES as e, rethrowIfInvariant as t, successResult as n } from "../result/result.js";
2
- import { decodeFailureResult as r } from "../internal/asn1/decode-refusal.js";
3
- import { readElement as i, readRootElement as a, readSequenceChildren as o } from "../internal/asn1/der.js";
4
- import { childrenOf as s, decodeBitString as c, decodeBoolean as l, decodeIntegerNumber as u, decodeObjectIdentifier as d, decodeString as f, parseTime as p } from "../internal/asn1/asn1.js";
1
+ import { childrenOf as e, decodeBitString as t, decodeBoolean as n, decodeIntegerNumber as r, decodeObjectIdentifier as i, decodeString as a, parseTime as o } from "../internal/asn1/asn1.js";
2
+ import { decodeFailureResult as s } from "../internal/asn1/decode-refusal.js";
3
+ import { readElement as c, readRootElement as l, readSequenceChildren as u } from "../internal/asn1/der.js";
4
+ import { DECODE_REFUSAL_CODES as d, rethrowIfInvariant as f, successResult as p } from "../result/result.js";
5
5
  // src/der/der.ts
6
- function attempt(i, a) {
6
+ function attempt(e, t) {
7
7
  try {
8
- return n(i());
9
- } catch (n) {
10
- return t(n), r(n, e, a);
8
+ return p(e());
9
+ } catch (e) {
10
+ return f(e), s(e, d, t);
11
11
  }
12
12
  }
13
13
  function requireTag(e, t, n) {
@@ -21,7 +21,7 @@ function requireTag(e, t, n) {
21
21
  * @throws if the element is truncated, indefinite-length, or non-minimally encoded.
22
22
  */
23
23
  function readDerElementOrThrow(e, t = 0) {
24
- return i(e, t);
24
+ return c(e, t);
25
25
  }
26
26
  /**
27
27
  * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.
@@ -37,7 +37,7 @@ function readDerElement(e, t = 0) {
37
37
  * @throws if {@linkcode bytes} carries trailing data, or nesting exceeds the depth guard.
38
38
  */
39
39
  function readDerRootOrThrow(e, t) {
40
- return a(e, t);
40
+ return l(e, t);
41
41
  }
42
42
  /** Reads the single top-level TLV element from {@linkcode bytes}. */
43
43
  function readDerRoot(e, t) {
@@ -49,7 +49,7 @@ function readDerRoot(e, t) {
49
49
  * @throws if the root element is not a SEQUENCE, or if child boundaries are inconsistent.
50
50
  */
51
51
  function readDerSequenceOrThrow(e, t) {
52
- return o(e, t);
52
+ return u(e, t);
53
53
  }
54
54
  /** Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children. */
55
55
  function readDerSequence(e, t) {
@@ -60,8 +60,8 @@ function readDerSequence(e, t) {
60
60
  *
61
61
  * @throws if a child overflows {@linkcode parent}, or data is left between the last child and its end.
62
62
  */
63
- function derChildrenOrThrow(e, t) {
64
- return s(e, t);
63
+ function derChildrenOrThrow(t, n) {
64
+ return e(t, n);
65
65
  }
66
66
  /** Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}. */
67
67
  function derChildren(e, t) {
@@ -73,7 +73,7 @@ function derChildren(e, t) {
73
73
  * @throws if {@linkcode element} is mis-tagged, or holds anything but `0x00` or `0xff`.
74
74
  */
75
75
  function decodeDerBooleanOrThrow(e) {
76
- return l(requireTag(e, 1, "BOOLEAN").value);
76
+ return n(requireTag(e, 1, "BOOLEAN").value);
77
77
  }
78
78
  /** Decodes a BOOLEAN element (tag `0x01`). */
79
79
  function decodeDerBoolean(e) {
@@ -86,7 +86,7 @@ function decodeDerBoolean(e) {
86
86
  * or exceeds {@linkcode Number.MAX_SAFE_INTEGER}.
87
87
  */
88
88
  function decodeDerIntegerOrThrow(e) {
89
- return u(requireTag(e, 2, "INTEGER").value);
89
+ return r(requireTag(e, 2, "INTEGER").value);
90
90
  }
91
91
  /** Decodes an INTEGER element (tag `0x02`) into a `number`. */
92
92
  function decodeDerInteger(e) {
@@ -110,7 +110,7 @@ function decodeDerOctetString(e) {
110
110
  * @throws if {@linkcode element} is mis-tagged, or holds a malformed sub-identifier.
111
111
  */
112
112
  function decodeDerOidOrThrow(e) {
113
- return d(requireTag(e, 6, "OBJECT IDENTIFIER").value);
113
+ return i(requireTag(e, 6, "OBJECT IDENTIFIER").value);
114
114
  }
115
115
  /** Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form. */
116
116
  function decodeDerOid(e) {
@@ -125,7 +125,7 @@ function decodeDerOid(e) {
125
125
  * @throws if {@linkcode element} is mis-tagged, or claims more than seven unused bits.
126
126
  */
127
127
  function decodeDerBitStringOrThrow(e) {
128
- return c(e);
128
+ return t(e);
129
129
  }
130
130
  /**
131
131
  * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}.
@@ -145,7 +145,7 @@ function decodeDerBitString(e) {
145
145
  * @throws on every other string tag, and on a TeletexString octet outside that state.
146
146
  */
147
147
  function decodeDerStringOrThrow(e) {
148
- return f(e.tag, e.value);
148
+ return a(e.tag, e.value);
149
149
  }
150
150
  /**
151
151
  * Decodes a string element into text, dispatching on its tag.
@@ -162,7 +162,7 @@ function decodeDerString(e) {
162
162
  * @throws if {@linkcode element} carries any other tag, or a malformed time value.
163
163
  */
164
164
  function decodeDerTimeOrThrow(e) {
165
- return p(e);
165
+ return o(e);
166
166
  }
167
167
  /** Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. */
168
168
  function decodeDerTime(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"der.js","names":["successResult","decode","error","rethrowIfInvariant","decodeFailureResult","DECODE_REFUSAL_CODES","fallback","element","tag","label","readElement","bytes","offset","readRootElement","options","readSequenceChildren","childrenOf","source","parent","decodeBoolean","decodeIntegerNumber","decodeObjectIdentifier","decodeBitString","decodeString","parseTime"],"sources":["../../src/der/der.ts"],"sourcesContent":["/**\n * Element-oriented DER readers and decoders.\n *\n * Each decoder validates the element's tag before reading its value, so a\n * mis-tagged element fails instead of yielding a wrong value.\n *\n * The `OrThrow` variants throw on malformed input.\n * The plain variants return a {@linkcode DecodeDerResult}.\n *\n * @module\n */\n\nimport type { DerBitString } from '#micro509/internal/asn1/asn1';\nimport {\n\tchildrenOf,\n\tdecodeBitString,\n\tdecodeBoolean,\n\tdecodeIntegerNumber,\n\tdecodeObjectIdentifier,\n\tdecodeString,\n\tparseTime,\n} from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, decodeFailureResult } from '#micro509/internal/asn1/decode-refusal';\nimport type {\n\tDerElement,\n\tReadRootElementOptions,\n\tReadSequenceChildrenOptions,\n} from '#micro509/internal/asn1/der';\nimport { readElement, readRootElement, readSequenceChildren } from '#micro509/internal/asn1/der';\nimport type { DecodeFailureCode, ErrorResult, Micro509Error } from '#micro509/result/result';\nimport { rethrowIfInvariant, successResult } from '#micro509/result/result';\n\n/**\n * Machine-readable failure reason for the DER readers and decoders.\n *\n * `malformed` is input that breaks DER or the decoder's ASN.1 type.\n * `unsupported` is input the type may allow but micro509 does not decode: a\n * TeletexString octet outside the X.690 §8.23.5.2 initial state.\n * `limit_exceeded` is an implementation limit: an OBJECT IDENTIFIER\n * sub-identifier encoded in more than 64 octets, a tag number of 2^53 or more,\n * or DER nested deeper than 64 levels.\n */\nexport type DecodeDerErrorCode = DecodeFailureCode;\n\n/** Structured failure payload for DER reading and decoding. */\nexport interface DecodeDerFailure extends Micro509Error<DecodeDerErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from a DER reader or decoder. */\nexport type DecodeDerResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<DecodeDerErrorCode, Record<never, never>, DecodeDerFailure>;\n\nfunction attempt<TValue>(decode: () => TValue, fallback: string): DecodeDerResult<TValue> {\n\ttry {\n\t\treturn successResult(decode());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn decodeFailureResult(error, DECODE_REFUSAL_CODES, fallback);\n\t}\n}\n\nfunction requireTag(element: DerElement, tag: number, label: string): DerElement {\n\tif (element.tag !== tag) {\n\t\tthrow new Error(`Expected ${label}`);\n\t}\n\treturn element;\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * @param offset Byte position of the tag octet. Defaults to 0.\n * @throws if the element is truncated, indefinite-length, or non-minimally encoded.\n */\nexport function readDerElementOrThrow(bytes: Uint8Array, offset = 0): DerElement {\n\treturn readElement(bytes, offset);\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * @param offset Byte position of the tag octet. Defaults to 0.\n */\nexport function readDerElement(bytes: Uint8Array, offset = 0): DecodeDerResult<DerElement> {\n\treturn attempt(() => readDerElementOrThrow(bytes, offset), 'Malformed DER element');\n}\n\n/**\n * Reads the single top-level TLV element from {@linkcode bytes}.\n *\n * @throws if {@linkcode bytes} carries trailing data, or nesting exceeds the depth guard.\n */\nexport function readDerRootOrThrow(\n\tbytes: Uint8Array,\n\toptions?: ReadRootElementOptions,\n): DerElement {\n\treturn readRootElement(bytes, options);\n}\n\n/** Reads the single top-level TLV element from {@linkcode bytes}. */\nexport function readDerRoot(\n\tbytes: Uint8Array,\n\toptions?: ReadRootElementOptions,\n): DecodeDerResult<DerElement> {\n\treturn attempt(() => readDerRootOrThrow(bytes, options), 'Malformed DER element');\n}\n\n/**\n * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children.\n *\n * @throws if the root element is not a SEQUENCE, or if child boundaries are inconsistent.\n */\nexport function readDerSequenceOrThrow(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DerElement[] {\n\treturn readSequenceChildren(bytes, options);\n}\n\n/** Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children. */\nexport function readDerSequence(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DecodeDerResult<DerElement[]> {\n\treturn attempt(() => readDerSequenceOrThrow(bytes, options), 'Malformed DER sequence');\n}\n\n/**\n * Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}.\n *\n * @throws if a child overflows {@linkcode parent}, or data is left between the last child and its end.\n */\nexport function derChildrenOrThrow(source: Uint8Array, parent: DerElement): DerElement[] {\n\treturn childrenOf(source, parent);\n}\n\n/** Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}. */\nexport function derChildren(source: Uint8Array, parent: DerElement): DecodeDerResult<DerElement[]> {\n\treturn attempt(() => derChildrenOrThrow(source, parent), 'Malformed DER container');\n}\n\n/**\n * Decodes a BOOLEAN element (tag `0x01`).\n *\n * @throws if {@linkcode element} is mis-tagged, or holds anything but `0x00` or `0xff`.\n */\nexport function decodeDerBooleanOrThrow(element: DerElement): boolean {\n\treturn decodeBoolean(requireTag(element, 0x01, 'BOOLEAN').value);\n}\n\n/** Decodes a BOOLEAN element (tag `0x01`). */\nexport function decodeDerBoolean(element: DerElement): DecodeDerResult<boolean> {\n\treturn attempt(() => decodeDerBooleanOrThrow(element), 'Malformed BOOLEAN');\n}\n\n/**\n * Decodes an INTEGER element (tag `0x02`) into a `number`.\n *\n * @throws if {@linkcode element} is mis-tagged, negative, non-minimally encoded,\n * or exceeds {@linkcode Number.MAX_SAFE_INTEGER}.\n */\nexport function decodeDerIntegerOrThrow(element: DerElement): number {\n\treturn decodeIntegerNumber(requireTag(element, 0x02, 'INTEGER').value);\n}\n\n/** Decodes an INTEGER element (tag `0x02`) into a `number`. */\nexport function decodeDerInteger(element: DerElement): DecodeDerResult<number> {\n\treturn attempt(() => decodeDerIntegerOrThrow(element), 'Malformed INTEGER');\n}\n\n/**\n * Decodes an OCTET STRING element (tag `0x04`) into its payload bytes.\n *\n * @throws if {@linkcode element} is mis-tagged.\n */\nexport function decodeDerOctetStringOrThrow(element: DerElement): Uint8Array {\n\treturn requireTag(element, 0x04, 'OCTET STRING').value;\n}\n\n/** Decodes an OCTET STRING element (tag `0x04`) into its payload bytes. */\nexport function decodeDerOctetString(element: DerElement): DecodeDerResult<Uint8Array> {\n\treturn attempt(() => decodeDerOctetStringOrThrow(element), 'Malformed OCTET STRING');\n}\n\n/**\n * Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form.\n *\n * @throws if {@linkcode element} is mis-tagged, or holds a malformed sub-identifier.\n */\nexport function decodeDerOidOrThrow(element: DerElement): string {\n\treturn decodeObjectIdentifier(requireTag(element, 0x06, 'OBJECT IDENTIFIER').value);\n}\n\n/** Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form. */\nexport function decodeDerOid(element: DerElement): DecodeDerResult<string> {\n\treturn attempt(() => decodeDerOidOrThrow(element), 'Malformed OBJECT IDENTIFIER');\n}\n\n/**\n * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}.\n *\n * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported\n * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them.\n *\n * @throws if {@linkcode element} is mis-tagged, or claims more than seven unused bits.\n */\nexport function decodeDerBitStringOrThrow(element: DerElement): DerBitString {\n\treturn decodeBitString(element);\n}\n\n/**\n * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}.\n *\n * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported\n * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them.\n */\nexport function decodeDerBitString(element: DerElement): DecodeDerResult<DerBitString> {\n\treturn attempt(() => decodeDerBitStringOrThrow(element), 'Malformed BIT STRING');\n}\n\n/**\n * Decodes a string element into text, dispatching on its tag.\n *\n * Supports UTF8String, PrintableString, TeletexString, IA5String, UniversalString, and BMPString.\n * A TeletexString decodes only in its X.690 §8.23.5.2 initial state.\n *\n * @throws on every other string tag, and on a TeletexString octet outside that state.\n */\nexport function decodeDerStringOrThrow(element: DerElement): string {\n\treturn decodeString(element.tag, element.value);\n}\n\n/**\n * Decodes a string element into text, dispatching on its tag.\n *\n * Supports UTF8String, PrintableString, TeletexString, IA5String, UniversalString, and BMPString.\n * A TeletexString decodes only in its X.690 §8.23.5.2 initial state.\n */\nexport function decodeDerString(element: DerElement): DecodeDerResult<string> {\n\treturn attempt(() => decodeDerStringOrThrow(element), 'Malformed string');\n}\n\n/**\n * Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}.\n *\n * @throws if {@linkcode element} carries any other tag, or a malformed time value.\n */\nexport function decodeDerTimeOrThrow(element: DerElement): Date {\n\treturn parseTime(element);\n}\n\n/** Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. */\nexport function decodeDerTime(element: DerElement): DecodeDerResult<Date> {\n\treturn attempt(() => decodeDerTimeOrThrow(element), 'Malformed time');\n}\n"],"mappings":";;;;;AAuDA,SAAS,QAAgB,GAAsB,GAA2C;CACzF,IAAI;EACH,OAAOA,EAAcC,EAAO,CAAC;CAC9B,SAASC,GAAO;EAEf,OADAC,EAAmBD,CAAK,GACjBE,EAAoBF,GAAOG,GAAsBC,CAAQ;CACjE;AACD;AAEA,SAAS,WAAW,GAAqB,GAAa,GAA2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GAAS,GAAM,cAAc,CAAC,CAAC;AAClD;;AAGA,SAAgB,qBAAqB,GAAkD;CACtF,OAAO,cAAc,4BAA4BA,CAAO,GAAG,wBAAwB;AACpF;;;;;;AAOA,SAAgB,oBAAoB,GAA6B;CAChE,OAAOc,EAAuB,WAAWd,GAAS,GAAM,mBAAmB,CAAC,CAAC,KAAK;AACnF;;AAGA,SAAgB,aAAa,GAA8C;CAC1E,OAAO,cAAc,oBAAoBA,CAAO,GAAG,6BAA6B;AACjF;;;;;;;;;AAUA,SAAgB,0BAA0B,GAAmC;CAC5E,OAAOe,EAAgBf,CAAO;AAC/B;;;;;;;AAQA,SAAgB,mBAAmB,GAAoD;CACtF,OAAO,cAAc,0BAA0BA,CAAO,GAAG,sBAAsB;AAChF;;;;;;;;;AAUA,SAAgB,uBAAuB,GAA6B;CACnE,OAAOgB,EAAahB,EAAQ,KAAKA,EAAQ,KAAK;AAC/C;;;;;;;AAQA,SAAgB,gBAAgB,GAA8C;CAC7E,OAAO,cAAc,uBAAuBA,CAAO,GAAG,kBAAkB;AACzE;;;;;;AAOA,SAAgB,qBAAqB,GAA2B;CAC/D,OAAOiB,EAAUjB,CAAO;AACzB;;AAGA,SAAgB,cAAc,GAA4C;CACzE,OAAO,cAAc,qBAAqBA,CAAO,GAAG,gBAAgB;AACrE"}
1
+ {"version":3,"file":"der.js","names":["childrenOf","decodeBitString","decodeBoolean","decodeIntegerNumber","decodeObjectIdentifier","decodeString","parseTime","decodeFailureResult","readElement","readRootElement","readSequenceChildren","DECODE_REFUSAL_CODES","rethrowIfInvariant","successResult","decode","fallback","error","element","tag","label","bytes","offset","options","source","parent"],"sources":["../../src/der/der.ts"],"sourcesContent":["/**\n * Element-oriented DER readers and decoders.\n *\n * Each decoder validates the element's tag before reading its value, so a\n * mis-tagged element fails instead of yielding a wrong value.\n *\n * The `OrThrow` variants throw on malformed input.\n * The plain variants return a {@linkcode DecodeDerResult}.\n *\n * @module\n */\n\nimport type { DerBitString } from '#micro509/internal/asn1/asn1';\nimport {\n\tchildrenOf,\n\tdecodeBitString,\n\tdecodeBoolean,\n\tdecodeIntegerNumber,\n\tdecodeObjectIdentifier,\n\tdecodeString,\n\tparseTime,\n} from '#micro509/internal/asn1/asn1';\nimport { DECODE_REFUSAL_CODES, decodeFailureResult } from '#micro509/internal/asn1/decode-refusal';\nimport type {\n\tDerElement,\n\tReadRootElementOptions,\n\tReadSequenceChildrenOptions,\n} from '#micro509/internal/asn1/der';\nimport { readElement, readRootElement, readSequenceChildren } from '#micro509/internal/asn1/der';\nimport type { DecodeFailureCode, ErrorResult, Micro509Error } from '#micro509/result/result';\nimport { rethrowIfInvariant, successResult } from '#micro509/result/result';\n\n/**\n * Machine-readable failure reason for the DER readers and decoders.\n *\n * `malformed` is input that breaks DER or the decoder's ASN.1 type.\n * `unsupported` is input the type may allow but micro509 does not decode: a\n * TeletexString octet outside the X.690 §8.23.5.2 initial state.\n * `limit_exceeded` is an implementation limit: an OBJECT IDENTIFIER\n * sub-identifier encoded in more than 64 octets, a tag number of 2^53 or more,\n * or DER nested deeper than 64 levels.\n */\nexport type DecodeDerErrorCode = DecodeFailureCode;\n\n/** Structured failure payload for DER reading and decoding. */\nexport interface DecodeDerFailure extends Micro509Error<DecodeDerErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from a DER reader or decoder. */\nexport type DecodeDerResult<TValue> =\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<DecodeDerErrorCode, Record<never, never>, DecodeDerFailure>;\n\nfunction attempt<TValue>(decode: () => TValue, fallback: string): DecodeDerResult<TValue> {\n\ttry {\n\t\treturn successResult(decode());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn decodeFailureResult(error, DECODE_REFUSAL_CODES, fallback);\n\t}\n}\n\nfunction requireTag(element: DerElement, tag: number, label: string): DerElement {\n\tif (element.tag !== tag) {\n\t\tthrow new Error(`Expected ${label}`);\n\t}\n\treturn element;\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * @param offset Byte position of the tag octet. Defaults to 0.\n * @throws if the element is truncated, indefinite-length, or non-minimally encoded.\n */\nexport function readDerElementOrThrow(bytes: Uint8Array, offset = 0): DerElement {\n\treturn readElement(bytes, offset);\n}\n\n/**\n * Reads one TLV element from {@linkcode bytes} starting at {@linkcode offset}.\n *\n * @param offset Byte position of the tag octet. Defaults to 0.\n */\nexport function readDerElement(bytes: Uint8Array, offset = 0): DecodeDerResult<DerElement> {\n\treturn attempt(() => readDerElementOrThrow(bytes, offset), 'Malformed DER element');\n}\n\n/**\n * Reads the single top-level TLV element from {@linkcode bytes}.\n *\n * @throws if {@linkcode bytes} carries trailing data, or nesting exceeds the depth guard.\n */\nexport function readDerRootOrThrow(\n\tbytes: Uint8Array,\n\toptions?: ReadRootElementOptions,\n): DerElement {\n\treturn readRootElement(bytes, options);\n}\n\n/** Reads the single top-level TLV element from {@linkcode bytes}. */\nexport function readDerRoot(\n\tbytes: Uint8Array,\n\toptions?: ReadRootElementOptions,\n): DecodeDerResult<DerElement> {\n\treturn attempt(() => readDerRootOrThrow(bytes, options), 'Malformed DER element');\n}\n\n/**\n * Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children.\n *\n * @throws if the root element is not a SEQUENCE, or if child boundaries are inconsistent.\n */\nexport function readDerSequenceOrThrow(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DerElement[] {\n\treturn readSequenceChildren(bytes, options);\n}\n\n/** Reads a DER-encoded SEQUENCE from {@linkcode bytes} and returns its direct children. */\nexport function readDerSequence(\n\tbytes: Uint8Array,\n\toptions?: ReadSequenceChildrenOptions,\n): DecodeDerResult<DerElement[]> {\n\treturn attempt(() => readDerSequenceOrThrow(bytes, options), 'Malformed DER sequence');\n}\n\n/**\n * Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}.\n *\n * @throws if a child overflows {@linkcode parent}, or data is left between the last child and its end.\n */\nexport function derChildrenOrThrow(source: Uint8Array, parent: DerElement): DerElement[] {\n\treturn childrenOf(source, parent);\n}\n\n/** Reads the direct children of a constructed {@linkcode parent} within {@linkcode source}. */\nexport function derChildren(source: Uint8Array, parent: DerElement): DecodeDerResult<DerElement[]> {\n\treturn attempt(() => derChildrenOrThrow(source, parent), 'Malformed DER container');\n}\n\n/**\n * Decodes a BOOLEAN element (tag `0x01`).\n *\n * @throws if {@linkcode element} is mis-tagged, or holds anything but `0x00` or `0xff`.\n */\nexport function decodeDerBooleanOrThrow(element: DerElement): boolean {\n\treturn decodeBoolean(requireTag(element, 0x01, 'BOOLEAN').value);\n}\n\n/** Decodes a BOOLEAN element (tag `0x01`). */\nexport function decodeDerBoolean(element: DerElement): DecodeDerResult<boolean> {\n\treturn attempt(() => decodeDerBooleanOrThrow(element), 'Malformed BOOLEAN');\n}\n\n/**\n * Decodes an INTEGER element (tag `0x02`) into a `number`.\n *\n * @throws if {@linkcode element} is mis-tagged, negative, non-minimally encoded,\n * or exceeds {@linkcode Number.MAX_SAFE_INTEGER}.\n */\nexport function decodeDerIntegerOrThrow(element: DerElement): number {\n\treturn decodeIntegerNumber(requireTag(element, 0x02, 'INTEGER').value);\n}\n\n/** Decodes an INTEGER element (tag `0x02`) into a `number`. */\nexport function decodeDerInteger(element: DerElement): DecodeDerResult<number> {\n\treturn attempt(() => decodeDerIntegerOrThrow(element), 'Malformed INTEGER');\n}\n\n/**\n * Decodes an OCTET STRING element (tag `0x04`) into its payload bytes.\n *\n * @throws if {@linkcode element} is mis-tagged.\n */\nexport function decodeDerOctetStringOrThrow(element: DerElement): Uint8Array {\n\treturn requireTag(element, 0x04, 'OCTET STRING').value;\n}\n\n/** Decodes an OCTET STRING element (tag `0x04`) into its payload bytes. */\nexport function decodeDerOctetString(element: DerElement): DecodeDerResult<Uint8Array> {\n\treturn attempt(() => decodeDerOctetStringOrThrow(element), 'Malformed OCTET STRING');\n}\n\n/**\n * Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form.\n *\n * @throws if {@linkcode element} is mis-tagged, or holds a malformed sub-identifier.\n */\nexport function decodeDerOidOrThrow(element: DerElement): string {\n\treturn decodeObjectIdentifier(requireTag(element, 0x06, 'OBJECT IDENTIFIER').value);\n}\n\n/** Decodes an OBJECT IDENTIFIER element (tag `0x06`) into dotted-decimal form. */\nexport function decodeDerOid(element: DerElement): DecodeDerResult<string> {\n\treturn attempt(() => decodeDerOidOrThrow(element), 'Malformed OBJECT IDENTIFIER');\n}\n\n/**\n * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}.\n *\n * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported\n * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them.\n *\n * @throws if {@linkcode element} is mis-tagged, or claims more than seven unused bits.\n */\nexport function decodeDerBitStringOrThrow(element: DerElement): DerBitString {\n\treturn decodeBitString(element);\n}\n\n/**\n * Decodes a BIT STRING element (tag `0x03`) into a {@linkcode DerBitString}.\n *\n * Unused trailing bits are returned as encoded, with a violation of {@linkcode https://www.itu.int/rec/T-REC-X.690-202102-I/en | X.690 §11.2.1} reported\n * through {@linkcode DerBitString.nonZeroPadding}, since certificates in the wild carry them.\n */\nexport function decodeDerBitString(element: DerElement): DecodeDerResult<DerBitString> {\n\treturn attempt(() => decodeDerBitStringOrThrow(element), 'Malformed BIT STRING');\n}\n\n/**\n * Decodes a string element into text, dispatching on its tag.\n *\n * Supports UTF8String, PrintableString, TeletexString, IA5String, UniversalString, and BMPString.\n * A TeletexString decodes only in its X.690 §8.23.5.2 initial state.\n *\n * @throws on every other string tag, and on a TeletexString octet outside that state.\n */\nexport function decodeDerStringOrThrow(element: DerElement): string {\n\treturn decodeString(element.tag, element.value);\n}\n\n/**\n * Decodes a string element into text, dispatching on its tag.\n *\n * Supports UTF8String, PrintableString, TeletexString, IA5String, UniversalString, and BMPString.\n * A TeletexString decodes only in its X.690 §8.23.5.2 initial state.\n */\nexport function decodeDerString(element: DerElement): DecodeDerResult<string> {\n\treturn attempt(() => decodeDerStringOrThrow(element), 'Malformed string');\n}\n\n/**\n * Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}.\n *\n * @throws if {@linkcode element} carries any other tag, or a malformed time value.\n */\nexport function decodeDerTimeOrThrow(element: DerElement): Date {\n\treturn parseTime(element);\n}\n\n/** Decodes a UTCTime (tag `0x17`) or GeneralizedTime (tag `0x18`) element into a {@linkcode Date}. */\nexport function decodeDerTime(element: DerElement): DecodeDerResult<Date> {\n\treturn attempt(() => decodeDerTimeOrThrow(element), 'Malformed time');\n}\n"],"mappings":";;;;;AAuDA,SAAS,QAAgBc,GAAsBC,GAA2C;CACzF,IAAI;EACH,OAAOF,EAAcC,EAAO,CAAC;CAC9B,SAASE,GAAO;EAEf,OADAJ,EAAmBI,CAAK,GACjBT,EAAoBS,GAAOL,GAAsBI,CAAQ;CACjE;AACD;AAEA,SAAS,WAAWE,GAAqBC,GAAaC,GAA2B;CAChF,IAAIF,EAAQ,QAAQC,GACnB,MAAU,MAAM,YAAYC,GAAO;CAEpC,OAAOF;AACR;;;;;;;AAQA,SAAgB,sBAAsBG,GAAmBC,IAAS,GAAe;CAChF,OAAOb,EAAYY,GAAOC,CAAM;AACjC;;;;;;AAOA,SAAgB,eAAeD,GAAmBC,IAAS,GAAgC;CAC1F,OAAO,cAAc,sBAAsBD,GAAOC,CAAM,GAAG,uBAAuB;AACnF;;;;;;AAOA,SAAgB,mBACfD,GACAE,GACa;CACb,OAAOb,EAAgBW,GAAOE,CAAO;AACtC;;AAGA,SAAgB,YACfF,GACAE,GAC8B;CAC9B,OAAO,cAAc,mBAAmBF,GAAOE,CAAO,GAAG,uBAAuB;AACjF;;;;;;AAOA,SAAgB,uBACfF,GACAE,GACe;CACf,OAAOZ,EAAqBU,GAAOE,CAAO;AAC3C;;AAGA,SAAgB,gBACfF,G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