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/dist/keys.d.ts CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Generate keys and move them between WebCrypto, PEM, DER, and JWK formats.
3
+ *
4
+ * Start with {@linkcode generateKeyPair}. Load a private key with
5
+ * {@linkcode importPkcs8Pem}, or protect an exported key with
6
+ * {@linkcode exportEncryptedPkcs8Pem}.
7
+ *
8
+ * @module micro509/keys
9
+ */
1
10
  import { KdfLimitOptions, Pbes2EncryptionOptions, Pbes2EncryptionScheme, Pbes2Parameters, Pbes2Prf, parsePbes2AlgorithmIdentifier } from "./internal/crypto/pbes2.js";
2
- import { DecryptRsaOaepErrorCode, DecryptRsaOaepFailure, DecryptRsaOaepResult, EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptRsaOaepErrorCode, EncryptRsaOaepFailure, EncryptRsaOaepResult, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyOptions, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaOaepOptions, RsaScheme, RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der } from "./keys/keys.js";
3
- export { type DecryptRsaOaepErrorCode, type DecryptRsaOaepFailure, type DecryptRsaOaepResult, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EncryptRsaOaepErrorCode, type EncryptRsaOaepFailure, type EncryptRsaOaepResult, type EncryptedPkcs8Options, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyOptions, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyFailure, type ImportKeyResult, type ImportRsaKeyInput, type KdfLimitOptions, type KeyAlgorithmInput, type KeyPairMaterial, type LegacyPemEncryptionOptions, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Parameters, type Pbes2Prf, type PrivateKeyImportInput, type PublicKeyImportInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaOaepOptions, type RsaScheme, type RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der, parsePbes2AlgorithmIdentifier };
11
+ import { DecryptRsaOaepErrorCode, DecryptRsaOaepFailure, DecryptRsaOaepResult, EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptRsaOaepErrorCode, EncryptRsaOaepFailure, EncryptRsaOaepResult, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyOptions, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyErrorDetails, ImportKeyFailure, ImportKeyReason, ImportKeyResult, ImportKeyStage, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaOaepOptions, RsaScheme, RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPrivateKeyPem, importPrivateKeyPemOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der } from "./keys/keys.js";
12
+ export { type DecryptRsaOaepErrorCode, type DecryptRsaOaepFailure, type DecryptRsaOaepResult, type EcKeyAlgorithmInput, type EcNamedCurve, type Ed25519KeyAlgorithmInput, type EncryptRsaOaepErrorCode, type EncryptRsaOaepFailure, type EncryptRsaOaepResult, type EncryptedPkcs8Options, type ImportEcKeyInput, type ImportEd25519KeyInput, type ImportEncryptedKeyErrorCode, type ImportEncryptedKeyFailure, type ImportEncryptedKeyOptions, type ImportEncryptedKeyResult, type ImportKeyErrorCode, type ImportKeyErrorDetails, type ImportKeyFailure, type ImportKeyReason, type ImportKeyResult, type ImportKeyStage, type ImportRsaKeyInput, type KdfLimitOptions, type KeyAlgorithmInput, type KeyPairMaterial, type LegacyPemEncryptionOptions, type Pbes2EncryptionOptions, type Pbes2EncryptionScheme, type Pbes2Parameters, type Pbes2Prf, type PrivateKeyImportInput, type PublicKeyImportInput, type RsaHash, type RsaKeyAlgorithmInput, type RsaOaepOptions, type RsaScheme, type RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPrivateKeyPem, importPrivateKeyPemOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow, inspectEncryptedPkcs8Der, parsePbes2AlgorithmIdentifier };
package/dist/keys.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { parsePbes2AlgorithmIdentifier as e } from "./internal/crypto/pbes2.js";
2
- import { decryptRsaOaep as t, decryptRsaOaepOrThrow as n, derivePublicKey as r, encryptRsaOaep as i, encryptRsaOaepOrThrow as a, exportBinaryBase64 as o, exportEncryptedPkcs1Pem as s, exportEncryptedPkcs8Der as c, exportEncryptedPkcs8Pem as l, exportEncryptedSec1Pem as u, exportPkcs1Der as d, exportPkcs1Pem as f, exportPkcs8Der as p, exportPkcs8Pem as m, exportPrivateJwk as h, exportPublicJwk as g, exportSec1Der as _, exportSec1Pem as v, exportSpkiDer as y, exportSpkiPem as b, generateKeyPair as x, importEncryptedPkcs1Pem as S, importEncryptedPkcs1PemOrThrow as C, importEncryptedPkcs8Der as w, importEncryptedPkcs8DerOrThrow as T, importEncryptedPkcs8Pem as E, importEncryptedPkcs8PemOrThrow as D, importEncryptedSec1Pem as O, importEncryptedSec1PemOrThrow as k, importPkcs1Der as A, importPkcs1DerOrThrow as j, importPkcs1Pem as M, importPkcs1PemOrThrow as N, importPkcs8Base64 as P, importPkcs8Base64OrThrow as F, importPkcs8Der as I, importPkcs8DerOrThrow as L, importPkcs8Pem as R, importPkcs8PemOrThrow as z, importPrivateJwk as B, importPrivateJwkOrThrow as V, importPublicJwk as H, importPublicJwkOrThrow as U, importSec1Der as W, importSec1DerOrThrow as G, importSec1Pem as K, importSec1PemOrThrow as q, importSpkiBase64 as J, importSpkiBase64OrThrow as Y, importSpkiDer as X, importSpkiDerOrThrow as Z, importSpkiPem as Q, importSpkiPemOrThrow as $, inspectEncryptedPkcs8Der as ee } from "./keys/keys.js";
3
- export { t as decryptRsaOaep, n as decryptRsaOaepOrThrow, r as derivePublicKey, i as encryptRsaOaep, a as encryptRsaOaepOrThrow, o as exportBinaryBase64, s as exportEncryptedPkcs1Pem, c as exportEncryptedPkcs8Der, l as exportEncryptedPkcs8Pem, u as exportEncryptedSec1Pem, d as exportPkcs1Der, f as exportPkcs1Pem, p as exportPkcs8Der, m as exportPkcs8Pem, h as exportPrivateJwk, g as exportPublicJwk, _ as exportSec1Der, v as exportSec1Pem, y as exportSpkiDer, b as exportSpkiPem, x as generateKeyPair, S as importEncryptedPkcs1Pem, C as importEncryptedPkcs1PemOrThrow, w as importEncryptedPkcs8Der, T as importEncryptedPkcs8DerOrThrow, E as importEncryptedPkcs8Pem, D as importEncryptedPkcs8PemOrThrow, O as importEncryptedSec1Pem, k as importEncryptedSec1PemOrThrow, A as importPkcs1Der, j as importPkcs1DerOrThrow, M as importPkcs1Pem, N as importPkcs1PemOrThrow, P as importPkcs8Base64, F as importPkcs8Base64OrThrow, I as importPkcs8Der, L as importPkcs8DerOrThrow, R as importPkcs8Pem, z as importPkcs8PemOrThrow, B as importPrivateJwk, V as importPrivateJwkOrThrow, H as importPublicJwk, U as importPublicJwkOrThrow, W as importSec1Der, G as importSec1DerOrThrow, K as importSec1Pem, q as importSec1PemOrThrow, J as importSpkiBase64, Y as importSpkiBase64OrThrow, X as importSpkiDer, Z as importSpkiDerOrThrow, Q as importSpkiPem, $ as importSpkiPemOrThrow, ee as inspectEncryptedPkcs8Der, e as parsePbes2AlgorithmIdentifier };
2
+ import { decryptRsaOaep as t, decryptRsaOaepOrThrow as n, derivePublicKey as r, encryptRsaOaep as i, encryptRsaOaepOrThrow as a, exportBinaryBase64 as o, exportEncryptedPkcs1Pem as s, exportEncryptedPkcs8Der as c, exportEncryptedPkcs8Pem as l, exportEncryptedSec1Pem as u, exportPkcs1Der as d, exportPkcs1Pem as f, exportPkcs8Der as p, exportPkcs8Pem as m, exportPrivateJwk as h, exportPublicJwk as g, exportSec1Der as _, exportSec1Pem as v, exportSpkiDer as y, exportSpkiPem as b, generateKeyPair as x, importEncryptedPkcs1Pem as S, importEncryptedPkcs1PemOrThrow as C, importEncryptedPkcs8Der as w, importEncryptedPkcs8DerOrThrow as T, importEncryptedPkcs8Pem as E, importEncryptedPkcs8PemOrThrow as D, importEncryptedSec1Pem as O, importEncryptedSec1PemOrThrow as k, importPkcs1Der as A, importPkcs1DerOrThrow as j, importPkcs1Pem as M, importPkcs1PemOrThrow as N, importPkcs8Base64 as P, importPkcs8Base64OrThrow as F, importPkcs8Der as I, importPkcs8DerOrThrow as L, importPkcs8Pem as R, importPkcs8PemOrThrow as z, importPrivateJwk as B, importPrivateJwkOrThrow as V, importPrivateKeyPem as H, importPrivateKeyPemOrThrow as U, importPublicJwk as W, importPublicJwkOrThrow as G, importSec1Der as K, importSec1DerOrThrow as q, importSec1Pem as J, importSec1PemOrThrow as Y, importSpkiBase64 as X, importSpkiBase64OrThrow as Z, importSpkiDer as Q, importSpkiDerOrThrow as $, importSpkiPem as ee, importSpkiPemOrThrow as te, inspectEncryptedPkcs8Der as ne } from "./keys/keys.js";
3
+ export { t as decryptRsaOaep, n as decryptRsaOaepOrThrow, r as derivePublicKey, i as encryptRsaOaep, a as encryptRsaOaepOrThrow, o as exportBinaryBase64, s as exportEncryptedPkcs1Pem, c as exportEncryptedPkcs8Der, l as exportEncryptedPkcs8Pem, u as exportEncryptedSec1Pem, d as exportPkcs1Der, f as exportPkcs1Pem, p as exportPkcs8Der, m as exportPkcs8Pem, h as exportPrivateJwk, g as exportPublicJwk, _ as exportSec1Der, v as exportSec1Pem, y as exportSpkiDer, b as exportSpkiPem, x as generateKeyPair, S as importEncryptedPkcs1Pem, C as importEncryptedPkcs1PemOrThrow, w as importEncryptedPkcs8Der, T as importEncryptedPkcs8DerOrThrow, E as importEncryptedPkcs8Pem, D as importEncryptedPkcs8PemOrThrow, O as importEncryptedSec1Pem, k as importEncryptedSec1PemOrThrow, A as importPkcs1Der, j as importPkcs1DerOrThrow, M as importPkcs1Pem, N as importPkcs1PemOrThrow, P as importPkcs8Base64, F as importPkcs8Base64OrThrow, I as importPkcs8Der, L as importPkcs8DerOrThrow, R as importPkcs8Pem, z as importPkcs8PemOrThrow, B as importPrivateJwk, V as importPrivateJwkOrThrow, H as importPrivateKeyPem, U as importPrivateKeyPemOrThrow, W as importPublicJwk, G as importPublicJwkOrThrow, K as importSec1Der, q as importSec1DerOrThrow, J as importSec1Pem, Y as importSec1PemOrThrow, X as importSpkiBase64, Z as importSpkiBase64OrThrow, Q as importSpkiDer, $ as importSpkiDerOrThrow, ee as importSpkiPem, te as importSpkiPemOrThrow, ne as inspectEncryptedPkcs8Der, e as parsePbes2AlgorithmIdentifier };
package/dist/pem/pem.d.ts CHANGED
@@ -101,5 +101,4 @@ export declare function splitPemBlocks(input: string): SplitPemBlocksResult;
101
101
  * or truncated PEM markers. For the throwing form use
102
102
  * {@linkcode categorizePemBlocksOrThrow}.
103
103
  */
104
- export declare function categorizePemBlocks(input: string | readonly PemBlock[]): CategorizePemBlocksResult;
105
- //# sourceMappingURL=pem.d.ts.map
104
+ export declare function categorizePemBlocks(input: string | readonly PemBlock[]): CategorizePemBlocksResult;
package/dist/pem/pem.js CHANGED
@@ -1,5 +1,5 @@
1
- import { failureResult as e, rethrowIfInvariant as t, successResult as n } from "../result/result.js";
2
- import { base64Decode as r, base64Encode as i } from "../internal/shared/base64.js";
1
+ import { base64Decode as e, base64Encode as t } from "../internal/shared/base64.js";
2
+ import { failureResult as n, rethrowIfInvariant as r, successResult as i, throwMicro509Error as a } from "../result/result.js";
3
3
  // src/pem/pem.ts
4
4
  /**
5
5
  * PEM helpers used across the public API.
@@ -9,16 +9,16 @@ import { base64Decode as r, base64Encode as i } from "../internal/shared/base64.
9
9
  *
10
10
  * @module
11
11
  */
12
- const a = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;
12
+ const o = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;
13
13
  /**
14
14
  * Wraps DER bytes in a PEM envelope with 64-character base64 lines.
15
15
  *
16
16
  * @param label PEM type label (e.g. `"CERTIFICATE"`, `"PRIVATE KEY"`).
17
17
  * @param der Raw DER-encoded content.
18
18
  */
19
- function pemEncode(e, t) {
19
+ function pemEncode(e, n) {
20
20
  if (!isPemLabel(e)) throw Error("Invalid PEM label");
21
- return `-----BEGIN ${e}-----\n${(i(t).match(/.{1,64}/g) ?? []).join("\n")}\n-----END ${e}-----\n`;
21
+ return `-----BEGIN ${e}-----\n${(t(n).match(/.{1,64}/g) ?? []).join("\n")}\n-----END ${e}-----\n`;
22
22
  }
23
23
  /**
24
24
  * Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the
@@ -28,15 +28,24 @@ function pemEncode(e, t) {
28
28
  * @param label Expected PEM type label.
29
29
  * @param pem PEM-encoded text (may contain `\r`).
30
30
  */
31
- function pemDecodeOrThrow(e, t) {
32
- let n = trimPemDocument(t.replace(/\r\n?/g, "\n")).split("\n"), i = findPreEncapsulationBoundary(n);
33
- if (i === void 0 || parsePemBoundaryLine(n[i] ?? "", "BEGIN") !== e || parsePemBoundaryLine(n[n.length - 1] ?? "", "END") !== e || n.length - i < 3) throw Error(`Invalid PEM for ${e}`);
34
- let a = normalizePemBodyLines(n.slice(i + 1, -1));
35
- if (a === void 0) throw Error(`Invalid PEM for ${e}`);
31
+ function pemDecodeOrThrow(t, n) {
32
+ let i = trimPemDocument(n.replace(/\r\n?/g, "\n")).split("\n"), o = findPreEncapsulationBoundary(i);
33
+ (o === void 0 || parsePemBoundaryLine(i[o] ?? "", "BEGIN") !== t || parsePemBoundaryLine(i[i.length - 1] ?? "", "END") !== t || i.length - o < 3) && a("malformed", `Invalid PEM for ${t}`, {
34
+ stage: "pem",
35
+ reason: "invalid_armor"
36
+ });
37
+ let s = normalizePemBodyLines(i.slice(o + 1, -1));
38
+ s === void 0 && a("malformed", `Invalid PEM for ${t}`, {
39
+ stage: "base64",
40
+ reason: "invalid_base64"
41
+ });
36
42
  try {
37
- return r(a.join(""));
38
- } catch {
39
- throw Error(`Invalid PEM for ${e}`);
43
+ return e(s.join(""));
44
+ } catch (e) {
45
+ r(e), a("malformed", `Invalid PEM for ${t}`, {
46
+ stage: "base64",
47
+ reason: "invalid_base64"
48
+ });
40
49
  }
41
50
  }
42
51
  /**
@@ -45,6 +54,13 @@ function pemDecodeOrThrow(e, t) {
45
54
  * and ignores non-PEM text between blocks.
46
55
  */
47
56
  function splitPemBlocksOrThrow(e) {
57
+ return splitPemTextBlocksOrThrow(e).map((e) => ({
58
+ ...e,
59
+ bytes: pemDecodeOrThrow(e.label, e.pem)
60
+ }));
61
+ }
62
+ /** @internal Shares the ordinary boundary scanner, retaining legacy encrypted bodies verbatim. */
63
+ function splitPemTextBlocksOrThrow(e) {
48
64
  let t = e.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n"), n = [], r, i = 0;
49
65
  for (; i < t.length;) {
50
66
  let e = t.indexOf("\n", i), a = e === -1 ? t.length : e, o = e === -1 ? t.length : e + 1, s = t.slice(i, a), c = s.replace(/^[ \t]+/, ""), l = parsePemBoundaryLine(s, "BEGIN"), u = parsePemBoundaryLine(s, "END");
@@ -67,7 +83,6 @@ function closePemBlock(e, t, n, r) {
67
83
  let i = e.slice(t.start, r);
68
84
  return {
69
85
  label: t.label,
70
- bytes: pemDecodeOrThrow(t.label, i),
71
86
  pem: i
72
87
  };
73
88
  }
@@ -124,7 +139,7 @@ function looksLikePemBoundary(e) {
124
139
  return /^[ \t]*-{5,}(?:BEGIN|END)/.test(e);
125
140
  }
126
141
  /** RFC 822 §3.2: `field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":">`. */
127
- const o = /^[\x21-\x39\x3b-\x7e]+$/;
142
+ const s = /^[\x21-\x39\x3b-\x7e]+$/;
128
143
  /** RFC 822 §3.3: `LWSP-char = SPACE / HTAB`. */
129
144
  function isLwspChar(e) {
130
145
  return e === " " || e === " ";
@@ -173,10 +188,10 @@ function parseTraditionalPemOrThrow(e) {
173
188
  }
174
189
  let n = e.indexOf(":");
175
190
  if (n === -1) break;
176
- let s = e.slice(0, n);
177
- if (!o.test(s)) throw Error(`Invalid PEM header name: ${s}`);
178
- if (r.has(s)) throw Error(`Duplicate PEM header: ${s}`);
179
- r.set(s, e.slice(n + 1).replace(/^[ \t]+/, "")), a = s, i += 1;
191
+ let o = e.slice(0, n);
192
+ if (!s.test(o)) throw Error(`Invalid PEM header name: ${o}`);
193
+ if (r.has(o)) throw Error(`Duplicate PEM header: ${o}`);
194
+ r.set(o, e.slice(n + 1).replace(/^[ \t]+/, "")), a = o, i += 1;
180
195
  }
181
196
  return {
182
197
  label: n,
@@ -185,7 +200,7 @@ function parseTraditionalPemOrThrow(e) {
185
200
  };
186
201
  }
187
202
  function isPemLabel(e) {
188
- return a.exec(e)?.[0] === e;
203
+ return o.exec(e)?.[0] === e;
189
204
  }
190
205
  /**
191
206
  * Extracts and base64-decodes the DER content from a PEM string.
@@ -222,13 +237,13 @@ function categorizePemBlocks(e) {
222
237
  return toPemResult(() => categorizePemBlocksOrThrow(e), "Malformed PEM block");
223
238
  }
224
239
  /** Shared Result wrapper around the throwing PEM cores. */
225
- function toPemResult(r, i) {
240
+ function toPemResult(e, t) {
226
241
  try {
227
- return n(r());
228
- } catch (n) {
229
- return t(n), e("malformed", n instanceof Error ? n.message : i);
242
+ return i(e());
243
+ } catch (e) {
244
+ return r(e), n("malformed", e instanceof Error ? e.message : t);
230
245
  }
231
246
  }
232
- export { categorizePemBlocks, categorizePemBlocksOrThrow, parseTraditionalPemOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow, trimLwsp };
247
+ export { categorizePemBlocks, categorizePemBlocksOrThrow, parseTraditionalPemOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow, splitPemTextBlocksOrThrow, trimLwsp };
233
248
 
234
249
  //# sourceMappingURL=pem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pem.js","names":["PEM_LABEL_PATTERN","label","base64Encode","der","lines","pem","begin","bodyLines","base64Decode","normalized","input","blocks","openBlock","lineStart","newline","lineEnd","nextLineStart","line","beginLine","beginLabel","endLabel","end","certificates","certificateRequests","privateKeys","publicKeys","others","block","nonEmptyLines","prefix","kind","withoutSurroundingWsp","index","RFC822_FIELD_NAME","character","value","headers","foldedName","delimiter","headerName","successResult","operation","error","rethrowIfInvariant","failureResult","fallbackMessage"],"sources":["../../src/pem/pem.ts"],"sourcesContent":["/**\n * PEM helpers used across the public API.\n *\n * Encodes, decodes, splits, and categorizes PEM blocks as defined by\n * RFC 7468.\n *\n * @module\n */\n\nimport { base64Decode, base64Encode } from '#micro509/internal/shared/base64';\nimport type { ErrorResult, Micro509Error } from '#micro509/result/result';\nimport { failureResult, rethrowIfInvariant, successResult } from '#micro509/result/result';\n\n/** A single decoded PEM block with its label, decoded DER bytes, and original PEM text. */\nexport interface PemBlock {\n\t/** RFC 7468 label between the `BEGIN` / `END` markers (e.g. `\"CERTIFICATE\"`). */\n\treadonly label: string;\n\t/** Decoded DER content of this block. */\n\treadonly bytes: Uint8Array;\n\t/** The original PEM text including `BEGIN`/`END` lines. */\n\treadonly pem: string;\n}\n\n/**\n * PEM blocks grouped by their label into well-known PKI categories.\n * Blocks that don't match any known label land in {@linkcode others}.\n */\nexport interface CategorizedPemBlocks {\n\t/** Blocks with label `CERTIFICATE`. */\n\treadonly certificates: readonly PemBlock[];\n\t/** Blocks with label `CERTIFICATE REQUEST`. */\n\treadonly certificateRequests: readonly PemBlock[];\n\t/** Blocks with label `PRIVATE KEY`, `RSA PRIVATE KEY`, or `EC PRIVATE KEY`. */\n\treadonly privateKeys: readonly PemBlock[];\n\t/** Blocks with label `PUBLIC KEY`. */\n\treadonly publicKeys: readonly PemBlock[];\n\t/** Blocks whose label doesn't match any of the above categories. */\n\treadonly others: readonly PemBlock[];\n}\n\n// RFC 7468 §3 label ABNF: labelchar = %x21-2C / %x2E-7E, joined by an optional\n// single \"-\" or SP; an empty label is legal.\nconst PEM_LABEL_PATTERN = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;\n\n/**\n * Wraps DER bytes in a PEM envelope with 64-character base64 lines.\n *\n * @param label PEM type label (e.g. `\"CERTIFICATE\"`, `\"PRIVATE KEY\"`).\n * @param der Raw DER-encoded content.\n */\nexport function pemEncode(label: string, der: Uint8Array): string {\n\tif (!isPemLabel(label)) {\n\t\tthrow new Error('Invalid PEM label');\n\t}\n\tconst body = base64Encode(der);\n\tconst lines = body.match(/.{1,64}/g) ?? [];\n\treturn `-----BEGIN ${label}-----\\n${lines.join('\\n')}\\n-----END ${label}-----\\n`;\n}\n\n/** Machine-readable failure reason for the PEM decoders. */\nexport type PemErrorCode = 'malformed';\n\n/** Structured failure payload for PEM decoding. */\nexport interface PemFailure extends Micro509Error<PemErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from {@linkcode pemDecode}. */\nexport type PemDecodeResult =\n\t| { readonly ok: true; readonly value: Uint8Array }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode splitPemBlocks}. */\nexport type SplitPemBlocksResult =\n\t| { readonly ok: true; readonly value: readonly PemBlock[] }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode categorizePemBlocks}. */\nexport type CategorizePemBlocksResult =\n\t| { readonly ok: true; readonly value: CategorizedPemBlocks }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/**\n * Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the\n * DER content from a PEM string. Text ahead of the `BEGIN` line is ignored.\n * Throws if the `BEGIN`/`END` markers don't match `label`.\n *\n * @param label Expected PEM type label.\n * @param pem PEM-encoded text (may contain `\\r`).\n */\nexport function pemDecodeOrThrow(label: string, pem: string): Uint8Array {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst begin = findPreEncapsulationBoundary(lines);\n\tif (\n\t\tbegin === undefined ||\n\t\tparsePemBoundaryLine(lines[begin] ?? '', 'BEGIN') !== label ||\n\t\tparsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label ||\n\t\tlines.length - begin < 3\n\t) {\n\t\tthrow new Error(`Invalid PEM for ${label}`);\n\t}\n\tconst bodyLines = normalizePemBodyLines(lines.slice(begin + 1, -1));\n\tif (bodyLines === undefined) {\n\t\tthrow new Error(`Invalid PEM for ${label}`);\n\t}\n\ttry {\n\t\treturn base64Decode(bodyLines.join(''));\n\t} catch {\n\t\tthrow new Error(`Invalid PEM for ${label}`);\n\t}\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns\n * them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files\n * and ignores non-PEM text between blocks.\n */\nexport function splitPemBlocksOrThrow(input: string): readonly PemBlock[] {\n\tconst normalized = input.replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n');\n\tconst blocks: PemBlock[] = [];\n\tlet openBlock: { readonly label: string; readonly start: number } | undefined;\n\tlet lineStart = 0;\n\twhile (lineStart < normalized.length) {\n\t\tconst newline = normalized.indexOf('\\n', lineStart);\n\t\tconst lineEnd = newline === -1 ? normalized.length : newline;\n\t\tconst nextLineStart = newline === -1 ? normalized.length : newline + 1;\n\t\tconst line = normalized.slice(lineStart, lineEnd);\n\t\tconst beginLine = line.replace(/^[ \\t]+/, '');\n\t\tconst beginLabel = parsePemBoundaryLine(line, 'BEGIN');\n\t\tconst endLabel = parsePemBoundaryLine(line, 'END');\n\n\t\tif (beginLabel !== undefined) {\n\t\t\tif (openBlock !== undefined) {\n\t\t\t\tthrow new Error('Malformed PEM block');\n\t\t\t}\n\t\t\topenBlock = { label: beginLabel, start: lineStart + line.length - beginLine.length };\n\t\t} else if (endLabel !== undefined) {\n\t\t\tblocks.push(closePemBlock(normalized, openBlock, endLabel, nextLineStart));\n\t\t\topenBlock = undefined;\n\t\t} else if (looksLikePemBoundary(line)) {\n\t\t\tthrow new Error('Malformed PEM block');\n\t\t}\n\n\t\tif (newline === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tlineStart = nextLineStart;\n\t}\n\tif (openBlock !== undefined) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\treturn blocks;\n}\n\nfunction closePemBlock(\n\tinput: string,\n\topenBlock: { readonly label: string; readonly start: number } | undefined,\n\tendLabel: string,\n\tend: number,\n): PemBlock {\n\tif (openBlock === undefined || openBlock.label !== endLabel) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\tconst pem = input.slice(openBlock.start, end);\n\treturn {\n\t\tlabel: openBlock.label,\n\t\tbytes: pemDecodeOrThrow(openBlock.label, pem),\n\t\tpem,\n\t};\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n */\nexport function categorizePemBlocksOrThrow(\n\tinput: string | readonly PemBlock[],\n): CategorizedPemBlocks {\n\tconst blocks = typeof input === 'string' ? splitPemBlocksOrThrow(input) : input;\n\tconst certificates: PemBlock[] = [];\n\tconst certificateRequests: PemBlock[] = [];\n\tconst privateKeys: PemBlock[] = [];\n\tconst publicKeys: PemBlock[] = [];\n\tconst others: PemBlock[] = [];\n\n\tfor (const block of blocks) {\n\t\tswitch (block.label) {\n\t\t\tcase 'CERTIFICATE':\n\t\t\t\tcertificates.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'CERTIFICATE REQUEST':\n\t\t\t\tcertificateRequests.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PRIVATE KEY':\n\t\t\tcase 'RSA PRIVATE KEY':\n\t\t\tcase 'EC PRIVATE KEY':\n\t\t\t\tprivateKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PUBLIC KEY':\n\t\t\t\tpublicKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tothers.push(block);\n\t\t}\n\t}\n\n\treturn { certificates, certificateRequests, privateKeys, publicKeys, others };\n}\n\nfunction normalizePemBodyLines(lines: readonly string[]): readonly string[] | undefined {\n\tconst normalizedLines = lines.map((line) => line.replace(/[ \\t]/g, ''));\n\tconst nonEmptyLines = normalizedLines.filter((line) => line !== '');\n\tif (nonEmptyLines.length === 0) {\n\t\treturn [''];\n\t}\n\treturn nonEmptyLines.every((line) => /^[A-Za-z0-9+/=]+$/.test(line)) ? nonEmptyLines : undefined;\n}\n\nfunction parsePemBoundaryLine(line: string, kind: 'BEGIN' | 'END'): string | undefined {\n\tconst prefix = `-----${kind} `;\n\tconst withoutSurroundingWsp = trimLwsp(line);\n\tif (!withoutSurroundingWsp.startsWith(prefix) || !withoutSurroundingWsp.endsWith('-----')) {\n\t\treturn undefined;\n\t}\n\tconst label = withoutSurroundingWsp.slice(prefix.length, -5);\n\treturn isPemLabel(label) ? label : undefined;\n}\n\n/** RFC 7468 §2: data before the encapsulation boundaries is permitted. */\nfunction findPreEncapsulationBoundary(lines: readonly string[]): number | undefined {\n\tfor (const [index, line] of lines.entries()) {\n\t\tif (parsePemBoundaryLine(line, 'BEGIN') !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tif (looksLikePemBoundary(line)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction looksLikePemBoundary(line: string): boolean {\n\treturn /^[ \\t]*-{5,}(?:BEGIN|END)/.test(line);\n}\n\n/** RFC 822 §3.2: `field-name = 1*<any CHAR, excluding CTLs, SPACE, and \":\">`. */\nconst RFC822_FIELD_NAME = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** RFC 822 §3.3: `LWSP-char = SPACE / HTAB`. */\nfunction isLwspChar(character: string): boolean {\n\treturn character === ' ' || character === '\\t';\n}\n\n/**\n * Strips the whitespace surrounding a PEM document: `LWSP-char`s and the line\n * terminators that separate the boundary lines from the body.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode\n * `Zs`, making those characters acceptable at a document edge while\n * {@linkcode parsePemBoundaryLine} rejects them everywhere else.\n */\nfunction trimPemDocument(value: string): string {\n\treturn value.replace(/^[ \\t\\n]+|[ \\t\\n]+$/g, '');\n}\n\n/**\n * @internal Strips surrounding RFC 822 §3.3 `LWSP-char`s.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode `Zs`,\n * none of which the grammar admits.\n */\nexport function trimLwsp(value: string): string {\n\treturn value.replace(/^[ \\t]+|[ \\t]+$/g, '');\n}\n\n/** A PEM block carrying RFC 1421 §4.6 encapsulated headers ahead of its body. */\nexport interface TraditionalPemBlock {\n\t/** PEM type label between the `BEGIN` / `END` markers. */\n\treadonly label: string;\n\t/** Encapsulated headers (e.g. `Proc-Type`, `DEK-Info`), unfolded. */\n\treadonly headers: ReadonlyMap<string, string>;\n\t/** Base64-encoded payload after the headers. */\n\treadonly base64Body: string;\n}\n\n/**\n * @internal Parses a PEM block with RFC 1421 §4.6 encapsulated headers.\n *\n * RFC 7468 §2 forbids headers, so this path exists only for the legacy\n * OpenSSL-style encrypted PKCS#1 and SEC1 blocks that predate it.\n */\nexport function parseTraditionalPemOrThrow(pem: string): TraditionalPemBlock {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst label = parsePemBoundaryLine(lines[0] ?? '', 'BEGIN');\n\tif (label === undefined || lines.length < 2) {\n\t\tthrow new Error('Invalid PEM block');\n\t}\n\tif (parsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label) {\n\t\tthrow new Error('PEM boundaries do not match');\n\t}\n\tconst headers = new Map<string, string>();\n\tlet index = 1;\n\tlet foldedName: string | undefined;\n\twhile (index < lines.length - 1) {\n\t\tconst line = lines[index];\n\t\tif (line === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (line.length === 0) {\n\t\t\tindex += 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (foldedName !== undefined && isLwspChar(line.charAt(0))) {\n\t\t\theaders.set(foldedName, `${headers.get(foldedName) ?? ''}${line}`);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst delimiter = line.indexOf(':');\n\t\tif (delimiter === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst headerName = line.slice(0, delimiter);\n\t\tif (!RFC822_FIELD_NAME.test(headerName)) {\n\t\t\tthrow new Error(`Invalid PEM header name: ${headerName}`);\n\t\t}\n\t\tif (headers.has(headerName)) {\n\t\t\tthrow new Error(`Duplicate PEM header: ${headerName}`);\n\t\t}\n\t\theaders.set(headerName, line.slice(delimiter + 1).replace(/^[ \\t]+/, ''));\n\t\tfoldedName = headerName;\n\t\tindex += 1;\n\t}\n\treturn { label, headers, base64Body: lines.slice(index, lines.length - 1).join('') };\n}\n\nfunction isPemLabel(label: string): boolean {\n\treturn PEM_LABEL_PATTERN.exec(label)?.[0] === label;\n}\n\n/**\n * Extracts and base64-decodes the DER content from a PEM string.\n * Text ahead of the `BEGIN` line is ignored.\n *\n * Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`\n * markers don't match `label` or the body is not valid base64. For the\n * throwing form use {@linkcode pemDecodeOrThrow}.\n */\nexport function pemDecode(label: string, pem: string): PemDecodeResult {\n\treturn toPemResult(() => pemDecodeOrThrow(label, pem), 'Invalid PEM');\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them\n * as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and\n * ignores non-PEM text between blocks.\n *\n * Returns a typed failure (`code: 'malformed'`) on stray or truncated PEM\n * markers. For the throwing form use {@linkcode splitPemBlocksOrThrow}.\n */\nexport function splitPemBlocks(input: string): SplitPemBlocksResult {\n\treturn toPemResult(() => splitPemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n *\n * Returns a typed failure (`code: 'malformed'`) when raw text contains stray\n * or truncated PEM markers. For the throwing form use\n * {@linkcode categorizePemBlocksOrThrow}.\n */\nexport function categorizePemBlocks(\n\tinput: string | readonly PemBlock[],\n): CategorizePemBlocksResult {\n\treturn toPemResult(() => categorizePemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/** Shared Result wrapper around the throwing PEM cores. */\nfunction toPemResult<TValue>(\n\toperation: () => TValue,\n\tfallbackMessage: string,\n):\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure> {\n\ttry {\n\t\treturn successResult(operation());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn failureResult('malformed', error instanceof Error ? error.message : fallbackMessage);\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA0CA,MAAMA,IAAoB;;;;;;;AAQ1B,SAAgB,UAAU,GAAe,GAAyB;CACjE,IAAI,CAAC,WAAWC,CAAK,GACpB,MAAU,MAAM,mBAAmB;CAIpC,OAAO,cAAcA,EAAM,UAFdC,EAAaC,CACT,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,EAAA,CACC,KAAK,IAAI,EAAE,aAAaF,EAAM;AACzE;;;;;;;;;AAkCA,SAAgB,iBAAiB,GAAe,GAAyB;CAExE,IAAMG,IADa,gBAAgBC,EAAI,QAAQ,UAAU,IAAI,CACtC,CAAC,CAAC,MAAM,IAAI,GAC7BC,IAAQ,6BAA6BF,CAAK;CAChD,IACCE,MAAU,KAAA,KACV,qBAAqBF,EAAME,MAAU,IAAI,OAAO,MAAML,KACtD,qBAAqBG,EAAMA,EAAM,SAAS,MAAM,IAAI,KAAK,MAAMH,KAC/DG,EAAM,SAASE,IAAQ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Y,GAAGD,EAAQ,IAAIC,CAAU,KAAK,KAAKpB,GAAM,GACjE,KAAS;GACT;EACD;EACA,IAAMqB,IAAYrB,EAAK,QAAQ,GAAG;EAClC,IAAIqB,MAAc,IACjB;EAED,IAAMC,IAAatB,EAAK,MAAM,GAAGqB,CAAS;EAC1C,IAAI,CAACL,EAAkB,KAAKM,CAAU,GACrC,MAAU,MAAM,4BAA4BA,GAAY;EAEzD,IAAIH,EAAQ,IAAIG,CAAU,GACzB,MAAU,MAAM,yBAAyBA,GAAY;EAItD,AAFAH,EAAQ,IAAIG,GAAYtB,EAAK,MAAMqB,IAAY,CAAC,CAAC,CAAC,QAAQ,WAAW,EAAE,CAAC,GACxE,IAAaC,GACb,KAAS;CACV;CACA,OAAO;EAAE;EAAO;EAAS,YAAYnC,EAAM,MAAM4B,GAAO5B,EAAM,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE;CAAE;AACpF;AAEA,SAAS,WAAW,GAAwB;CAC3C,OAAOJ,EAAkB,KAAKC,CAAK,CAAC,GAAG,OAAOA;AAC/C;;;;;;;;;AAUA,SAAgB,UAAU,GAAe,GAA8B;CACtE,OAAO,kBAAkB,iBAAiBA,GAAOI,CAAG,GAAG,aAAa;AACrE;;;;;;;;;AAUA,SAAgB,eAAe,GAAqC;CACnE,OAAO,kBAAkB,sBAAsBK,CAAK,GAAG,qBAAqB;AAC7E;;;;;;;;;;AAWA,SAAgB,oBACf,GAC4B;CAC5B,OAAO,kBAAkB,2BAA2BA,CAAK,GAAG,qBAAqB;AAClF;;AAGA,SAAS,YACR,GACA,GAG8D;CAC9D,IAAI;EACH,OAAO8B,EAAcC,EAAU,CAAC;CACjC,SAASC,GAAO;EAEf,OADAC,EAAmBD,CAAK,GACjBE,EAAc,aAAaF,aAAiB,QAAQA,EAAM,UAAUG,CAAe;CAC3F;AACD"}
1
+ {"version":3,"file":"pem.js","names":["base64Decode","base64Encode","failureResult","rethrowIfInvariant","successResult","throwMicro509Error","PEM_LABEL_PATTERN","label","der","pem","lines","begin","bodyLines","error","input","block","normalized","blocks","openBlock","lineStart","newline","lineEnd","nextLineStart","line","beginLine","beginLabel","endLabel","end","certificates","certificateRequests","privateKeys","publicKeys","others","nonEmptyLines","kind","prefix","withoutSurroundingWsp","index","RFC822_FIELD_NAME","character","value","headers","foldedName","delimiter","headerName","operation","fallbackMessage"],"sources":["../../src/pem/pem.ts"],"sourcesContent":["/**\n * PEM helpers used across the public API.\n *\n * Encodes, decodes, splits, and categorizes PEM blocks as defined by\n * RFC 7468.\n *\n * @module\n */\n\nimport { base64Decode, base64Encode } from '#micro509/internal/shared/base64';\nimport type { ErrorResult, Micro509Error } from '#micro509/result/result';\nimport {\n\tfailureResult,\n\trethrowIfInvariant,\n\tsuccessResult,\n\tthrowMicro509Error,\n} from '#micro509/result/result';\n\n/** A single decoded PEM block with its label, decoded DER bytes, and original PEM text. */\nexport interface PemBlock {\n\t/** RFC 7468 label between the `BEGIN` / `END` markers (e.g. `\"CERTIFICATE\"`). */\n\treadonly label: string;\n\t/** Decoded DER content of this block. */\n\treadonly bytes: Uint8Array;\n\t/** The original PEM text including `BEGIN`/`END` lines. */\n\treadonly pem: string;\n}\n\n/**\n * PEM blocks grouped by their label into well-known PKI categories.\n * Blocks that don't match any known label land in {@linkcode others}.\n */\nexport interface CategorizedPemBlocks {\n\t/** Blocks with label `CERTIFICATE`. */\n\treadonly certificates: readonly PemBlock[];\n\t/** Blocks with label `CERTIFICATE REQUEST`. */\n\treadonly certificateRequests: readonly PemBlock[];\n\t/** Blocks with label `PRIVATE KEY`, `RSA PRIVATE KEY`, or `EC PRIVATE KEY`. */\n\treadonly privateKeys: readonly PemBlock[];\n\t/** Blocks with label `PUBLIC KEY`. */\n\treadonly publicKeys: readonly PemBlock[];\n\t/** Blocks whose label doesn't match any of the above categories. */\n\treadonly others: readonly PemBlock[];\n}\n\n// RFC 7468 §3 label ABNF: labelchar = %x21-2C / %x2E-7E, joined by an optional\n// single \"-\" or SP; an empty label is legal.\nconst PEM_LABEL_PATTERN = /^(?:[!-,.-~](?:[- ]?[!-,.-~])*)?$/;\n\n/**\n * Wraps DER bytes in a PEM envelope with 64-character base64 lines.\n *\n * @param label PEM type label (e.g. `\"CERTIFICATE\"`, `\"PRIVATE KEY\"`).\n * @param der Raw DER-encoded content.\n */\nexport function pemEncode(label: string, der: Uint8Array): string {\n\tif (!isPemLabel(label)) {\n\t\tthrow new Error('Invalid PEM label');\n\t}\n\tconst body = base64Encode(der);\n\tconst lines = body.match(/.{1,64}/g) ?? [];\n\treturn `-----BEGIN ${label}-----\\n${lines.join('\\n')}\\n-----END ${label}-----\\n`;\n}\n\n/** Machine-readable failure reason for the PEM decoders. */\nexport type PemErrorCode = 'malformed';\n\n/** Structured failure payload for PEM decoding. */\nexport interface PemFailure extends Micro509Error<PemErrorCode> {\n\t/** Always `false` for failures. */\n\treadonly ok: false;\n}\n\n/** Success-or-failure result from {@linkcode pemDecode}. */\nexport type PemDecodeResult =\n\t| { readonly ok: true; readonly value: Uint8Array }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode splitPemBlocks}. */\nexport type SplitPemBlocksResult =\n\t| { readonly ok: true; readonly value: readonly PemBlock[] }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/** Success-or-failure result from {@linkcode categorizePemBlocks}. */\nexport type CategorizePemBlocksResult =\n\t| { readonly ok: true; readonly value: CategorizedPemBlocks }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure>;\n\n/**\n * Throwing core for {@linkcode pemDecode}: extracts and base64-decodes the\n * DER content from a PEM string. Text ahead of the `BEGIN` line is ignored.\n * Throws if the `BEGIN`/`END` markers don't match `label`.\n *\n * @param label Expected PEM type label.\n * @param pem PEM-encoded text (may contain `\\r`).\n */\nexport function pemDecodeOrThrow(label: string, pem: string): Uint8Array {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst begin = findPreEncapsulationBoundary(lines);\n\tif (\n\t\tbegin === undefined ||\n\t\tparsePemBoundaryLine(lines[begin] ?? '', 'BEGIN') !== label ||\n\t\tparsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label ||\n\t\tlines.length - begin < 3\n\t) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'pem',\n\t\t\treason: 'invalid_armor',\n\t\t} as const);\n\t}\n\tconst bodyLines = normalizePemBodyLines(lines.slice(begin + 1, -1));\n\tif (bodyLines === undefined) {\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n\ttry {\n\t\treturn base64Decode(bodyLines.join(''));\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\tthrowMicro509Error('malformed', `Invalid PEM for ${label}`, {\n\t\t\tstage: 'base64',\n\t\t\treason: 'invalid_base64',\n\t\t} as const);\n\t}\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns\n * them as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files\n * and ignores non-PEM text between blocks.\n */\nexport function splitPemBlocksOrThrow(input: string): readonly PemBlock[] {\n\treturn splitPemTextBlocksOrThrow(input).map((block) => ({\n\t\t...block,\n\t\tbytes: pemDecodeOrThrow(block.label, block.pem),\n\t}));\n}\n\n/** @internal A bounded-by-input PEM block before decoding its body. */\nexport interface PemTextBlock {\n\treadonly label: string;\n\treadonly pem: string;\n}\n\n/** @internal Shares the ordinary boundary scanner, retaining legacy encrypted bodies verbatim. */\nexport function splitPemTextBlocksOrThrow(input: string): readonly PemTextBlock[] {\n\tconst normalized = input.replace(/^\\uFEFF/, '').replace(/\\r\\n?/g, '\\n');\n\tconst blocks: PemTextBlock[] = [];\n\tlet openBlock: { readonly label: string; readonly start: number } | undefined;\n\tlet lineStart = 0;\n\twhile (lineStart < normalized.length) {\n\t\tconst newline = normalized.indexOf('\\n', lineStart);\n\t\tconst lineEnd = newline === -1 ? normalized.length : newline;\n\t\tconst nextLineStart = newline === -1 ? normalized.length : newline + 1;\n\t\tconst line = normalized.slice(lineStart, lineEnd);\n\t\tconst beginLine = line.replace(/^[ \\t]+/, '');\n\t\tconst beginLabel = parsePemBoundaryLine(line, 'BEGIN');\n\t\tconst endLabel = parsePemBoundaryLine(line, 'END');\n\n\t\tif (beginLabel !== undefined) {\n\t\t\tif (openBlock !== undefined) {\n\t\t\t\tthrow new Error('Malformed PEM block');\n\t\t\t}\n\t\t\topenBlock = { label: beginLabel, start: lineStart + line.length - beginLine.length };\n\t\t} else if (endLabel !== undefined) {\n\t\t\tblocks.push(closePemBlock(normalized, openBlock, endLabel, nextLineStart));\n\t\t\topenBlock = undefined;\n\t\t} else if (looksLikePemBoundary(line)) {\n\t\t\tthrow new Error('Malformed PEM block');\n\t\t}\n\n\t\tif (newline === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tlineStart = nextLineStart;\n\t}\n\tif (openBlock !== undefined) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\treturn blocks;\n}\n\nfunction closePemBlock(\n\tinput: string,\n\topenBlock: { readonly label: string; readonly start: number } | undefined,\n\tendLabel: string,\n\tend: number,\n): PemTextBlock {\n\tif (openBlock === undefined || openBlock.label !== endLabel) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\tconst pem = input.slice(openBlock.start, end);\n\treturn {\n\t\tlabel: openBlock.label,\n\t\tpem,\n\t};\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n */\nexport function categorizePemBlocksOrThrow(\n\tinput: string | readonly PemBlock[],\n): CategorizedPemBlocks {\n\tconst blocks = typeof input === 'string' ? splitPemBlocksOrThrow(input) : input;\n\tconst certificates: PemBlock[] = [];\n\tconst certificateRequests: PemBlock[] = [];\n\tconst privateKeys: PemBlock[] = [];\n\tconst publicKeys: PemBlock[] = [];\n\tconst others: PemBlock[] = [];\n\n\tfor (const block of blocks) {\n\t\tswitch (block.label) {\n\t\t\tcase 'CERTIFICATE':\n\t\t\t\tcertificates.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'CERTIFICATE REQUEST':\n\t\t\t\tcertificateRequests.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PRIVATE KEY':\n\t\t\tcase 'RSA PRIVATE KEY':\n\t\t\tcase 'EC PRIVATE KEY':\n\t\t\t\tprivateKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tcase 'PUBLIC KEY':\n\t\t\t\tpublicKeys.push(block);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tothers.push(block);\n\t\t}\n\t}\n\n\treturn { certificates, certificateRequests, privateKeys, publicKeys, others };\n}\n\nfunction normalizePemBodyLines(lines: readonly string[]): readonly string[] | undefined {\n\tconst normalizedLines = lines.map((line) => line.replace(/[ \\t]/g, ''));\n\tconst nonEmptyLines = normalizedLines.filter((line) => line !== '');\n\tif (nonEmptyLines.length === 0) {\n\t\treturn [''];\n\t}\n\treturn nonEmptyLines.every((line) => /^[A-Za-z0-9+/=]+$/.test(line)) ? nonEmptyLines : undefined;\n}\n\nfunction parsePemBoundaryLine(line: string, kind: 'BEGIN' | 'END'): string | undefined {\n\tconst prefix = `-----${kind} `;\n\tconst withoutSurroundingWsp = trimLwsp(line);\n\tif (!withoutSurroundingWsp.startsWith(prefix) || !withoutSurroundingWsp.endsWith('-----')) {\n\t\treturn undefined;\n\t}\n\tconst label = withoutSurroundingWsp.slice(prefix.length, -5);\n\treturn isPemLabel(label) ? label : undefined;\n}\n\n/** RFC 7468 §2: data before the encapsulation boundaries is permitted. */\nfunction findPreEncapsulationBoundary(lines: readonly string[]): number | undefined {\n\tfor (const [index, line] of lines.entries()) {\n\t\tif (parsePemBoundaryLine(line, 'BEGIN') !== undefined) {\n\t\t\treturn index;\n\t\t}\n\t\tif (looksLikePemBoundary(line)) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction looksLikePemBoundary(line: string): boolean {\n\treturn /^[ \\t]*-{5,}(?:BEGIN|END)/.test(line);\n}\n\n/** RFC 822 §3.2: `field-name = 1*<any CHAR, excluding CTLs, SPACE, and \":\">`. */\nconst RFC822_FIELD_NAME = /^[\\x21-\\x39\\x3b-\\x7e]+$/;\n\n/** RFC 822 §3.3: `LWSP-char = SPACE / HTAB`. */\nfunction isLwspChar(character: string): boolean {\n\treturn character === ' ' || character === '\\t';\n}\n\n/**\n * Strips the whitespace surrounding a PEM document: `LWSP-char`s and the line\n * terminators that separate the boundary lines from the body.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode\n * `Zs`, making those characters acceptable at a document edge while\n * {@linkcode parsePemBoundaryLine} rejects them everywhere else.\n */\nfunction trimPemDocument(value: string): string {\n\treturn value.replace(/^[ \\t\\n]+|[ \\t\\n]+$/g, '');\n}\n\n/**\n * @internal Strips surrounding RFC 822 §3.3 `LWSP-char`s.\n *\n * `String.prototype.trim` would also strip VT, FF, NBSP, and every Unicode `Zs`,\n * none of which the grammar admits.\n */\nexport function trimLwsp(value: string): string {\n\treturn value.replace(/^[ \\t]+|[ \\t]+$/g, '');\n}\n\n/** A PEM block carrying RFC 1421 §4.6 encapsulated headers ahead of its body. */\nexport interface TraditionalPemBlock {\n\t/** PEM type label between the `BEGIN` / `END` markers. */\n\treadonly label: string;\n\t/** Encapsulated headers (e.g. `Proc-Type`, `DEK-Info`), unfolded. */\n\treadonly headers: ReadonlyMap<string, string>;\n\t/** Base64-encoded payload after the headers. */\n\treadonly base64Body: string;\n}\n\n/**\n * @internal Parses a PEM block with RFC 1421 §4.6 encapsulated headers.\n *\n * RFC 7468 §2 forbids headers, so this path exists only for the legacy\n * OpenSSL-style encrypted PKCS#1 and SEC1 blocks that predate it.\n */\nexport function parseTraditionalPemOrThrow(pem: string): TraditionalPemBlock {\n\tconst normalized = trimPemDocument(pem.replace(/\\r\\n?/g, '\\n'));\n\tconst lines = normalized.split('\\n');\n\tconst label = parsePemBoundaryLine(lines[0] ?? '', 'BEGIN');\n\tif (label === undefined || lines.length < 2) {\n\t\tthrow new Error('Invalid PEM block');\n\t}\n\tif (parsePemBoundaryLine(lines[lines.length - 1] ?? '', 'END') !== label) {\n\t\tthrow new Error('PEM boundaries do not match');\n\t}\n\tconst headers = new Map<string, string>();\n\tlet index = 1;\n\tlet foldedName: string | undefined;\n\twhile (index < lines.length - 1) {\n\t\tconst line = lines[index];\n\t\tif (line === undefined) {\n\t\t\tbreak;\n\t\t}\n\t\tif (line.length === 0) {\n\t\t\tindex += 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (foldedName !== undefined && isLwspChar(line.charAt(0))) {\n\t\t\theaders.set(foldedName, `${headers.get(foldedName) ?? ''}${line}`);\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst delimiter = line.indexOf(':');\n\t\tif (delimiter === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst headerName = line.slice(0, delimiter);\n\t\tif (!RFC822_FIELD_NAME.test(headerName)) {\n\t\t\tthrow new Error(`Invalid PEM header name: ${headerName}`);\n\t\t}\n\t\tif (headers.has(headerName)) {\n\t\t\tthrow new Error(`Duplicate PEM header: ${headerName}`);\n\t\t}\n\t\theaders.set(headerName, line.slice(delimiter + 1).replace(/^[ \\t]+/, ''));\n\t\tfoldedName = headerName;\n\t\tindex += 1;\n\t}\n\treturn { label, headers, base64Body: lines.slice(index, lines.length - 1).join('') };\n}\n\nfunction isPemLabel(label: string): boolean {\n\treturn PEM_LABEL_PATTERN.exec(label)?.[0] === label;\n}\n\n/**\n * Extracts and base64-decodes the DER content from a PEM string.\n * Text ahead of the `BEGIN` line is ignored.\n *\n * Returns a typed failure (`code: 'malformed'`) when the `BEGIN`/`END`\n * markers don't match `label` or the body is not valid base64. For the\n * throwing form use {@linkcode pemDecodeOrThrow}.\n */\nexport function pemDecode(label: string, pem: string): PemDecodeResult {\n\treturn toPemResult(() => pemDecodeOrThrow(label, pem), 'Invalid PEM');\n}\n\n/**\n * Finds all `BEGIN`/`END`-delimited PEM blocks in a string and returns them\n * as parsed {@linkcode PemBlock} entries. Handles concatenated PEM files and\n * ignores non-PEM text between blocks.\n *\n * Returns a typed failure (`code: 'malformed'`) on stray or truncated PEM\n * markers. For the throwing form use {@linkcode splitPemBlocksOrThrow}.\n */\nexport function splitPemBlocks(input: string): SplitPemBlocksResult {\n\treturn toPemResult(() => splitPemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/**\n * Groups PEM blocks by label into well-known PKI categories\n * (certificates, CSRs, private keys, public keys, and everything else).\n * Accepts either raw PEM text or pre-split {@linkcode PemBlock} entries.\n *\n * Returns a typed failure (`code: 'malformed'`) when raw text contains stray\n * or truncated PEM markers. For the throwing form use\n * {@linkcode categorizePemBlocksOrThrow}.\n */\nexport function categorizePemBlocks(\n\tinput: string | readonly PemBlock[],\n): CategorizePemBlocksResult {\n\treturn toPemResult(() => categorizePemBlocksOrThrow(input), 'Malformed PEM block');\n}\n\n/** Shared Result wrapper around the throwing PEM cores. */\nfunction toPemResult<TValue>(\n\toperation: () => TValue,\n\tfallbackMessage: string,\n):\n\t| { readonly ok: true; readonly value: TValue }\n\t| ErrorResult<PemErrorCode, Record<never, never>, PemFailure> {\n\ttry {\n\t\treturn successResult(operation());\n\t} catch (error) {\n\t\trethrowIfInvariant(error);\n\t\treturn failureResult('malformed', error instanceof Error ? error.message : fallbackMessage);\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAMM,IAAoB;;;;;;;AAQ1B,SAAgB,UAAUC,GAAeC,GAAyB;CACjE,IAAI,CAAC,WAAWD,CAAK,GACpB,MAAU,MAAM,mBAAmB;CAIpC,OAAO,cAAcA,EAAM,UAFdN,EAAaO,CACT,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,EAAA,CACC,KAAK,IAAI,E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OAAOD,EAAkB,KAAKC,CAAK,CAAC,GAAG,OAAOA;AAC/C;;;;;;;;;AAUA,SAAgB,UAAUA,GAAeE,GAA8B;CACtE,OAAO,kBAAkB,iBAAiBF,GAAOE,CAAG,GAAG,aAAa;AACrE;;;;;;;;;AAUA,SAAgB,eAAeK,GAAqC;CACnE,OAAO,kBAAkB,sBAAsBA,CAAK,GAAG,qBAAqB;AAC7E;;;;;;;;;;AAWA,SAAgB,oBACfA,GAC4B;CAC5B,OAAO,kBAAkB,2BAA2BA,CAAK,GAAG,qBAAqB;AAClF;;AAGA,SAAS,YACR+B,GACAC,GAG8D;CAC9D,IAAI;EACH,OAAO1C,EAAcyC,EAAU,CAAC;CACjC,SAAShC,GAAO;EAEf,OADAV,EAAmBU,CAAK,GACjBX,EAAc,aAAaW,aAAiB,QAAQA,EAAM,UAAUiC,CAAe;CAC3F;AACD"}
package/dist/pem.d.ts CHANGED
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Canonical PEM boundary surface.
3
+ * Owns the stable `micro509/pem` entrypoint.
4
+ *
5
+ * @module micro509/pem
6
+ */
1
7
  import { CategorizePemBlocksResult, CategorizedPemBlocks, PemBlock, PemDecodeResult, PemErrorCode, PemFailure, SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow } from "./pem/pem.js";
2
8
  export { type CategorizePemBlocksResult, type CategorizedPemBlocks, type PemBlock, type PemDecodeResult, type PemErrorCode, type PemFailure, type SplitPemBlocksResult, categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
@@ -1,7 +1,7 @@
1
1
  import { KdfLimitOptions } from "../internal/crypto/pbes2.js";
2
- import { DecodeFailureCode, ErrorResult, Micro509Error } from "../result/result.js";
3
2
  import { EncryptedPkcs8Options } from "../keys/keys.js";
4
3
  import { CreatePkcs12MacDataErrorCode, ParsePkcs12MacDataErrorCode, ParsePkcs12MacDataFailure, ParsePkcs12MacDataOptions, ParsePkcs12MacDataResult, ParsedPkcs12MacData, Pkcs12MacOptions, createPkcs12MacData, parsePkcs12MacData, parsePkcs12MacDataOrThrow } from "./pkcs12-mac.js";
4
+ import { DecodeFailureCode, ErrorResult, Micro509Error } from "../result/result.js";
5
5
  import { ParsedCertificate } from "../x509/parse.js";
6
6
  /** PEM string or DER bytes for a certificate to include in a PFX bag. */
7
7
  export type PfxCertificateSource = string | Uint8Array | ParsedCertificate;
@@ -239,5 +239,4 @@ export declare function parsePfxDer(der: Uint8Array, options?: ParsePfxOptions):
239
239
  * ```
240
240
  */
241
241
  export declare function parsePfxPem(pem: string, options?: ParsePfxOptions): Promise<ParsePfxResult>;
242
- export type { CreatePkcs12MacDataErrorCode, KdfLimitOptions, ParsePkcs12MacDataErrorCode, ParsePkcs12MacDataFailure, ParsePkcs12MacDataOptions, ParsePkcs12MacDataResult, ParsedPkcs12MacData, Pkcs12MacOptions, createPkcs12MacData, parsePkcs12MacData, parsePkcs12MacDataOrThrow };
243
- //# sourceMappingURL=pfx.d.ts.map
242
+ export type { CreatePkcs12MacDataErrorCode, KdfLimitOptions, ParsePkcs12MacDataErrorCode, ParsePkcs12MacDataFailure, ParsePkcs12MacDataOptions, ParsePkcs12MacDataResult, ParsedPkcs12MacData, Pkcs12MacOptions, createPkcs12MacData, parsePkcs12MacData, parsePkcs12MacDataOrThrow };