micro509 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -4
- package/dist/index.js +16 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +583 -547
- package/dist/keys/keys.js +519 -431
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +579 -636
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/fingerprint.d.ts +55 -0
- package/dist/x509/fingerprint.js +55 -0
- package/dist/x509/fingerprint.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +288 -185
- package/dist/x509/parse.js +762 -677
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.d.ts +3 -2
- package/dist/x509.js +7 -6
- package/package.json +79 -41
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pem.js","names":[],"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/**\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\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/** 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. Throws if the `BEGIN`/`END` markers don't\n * 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 = pem.replace(/\\r/g, '').trim();\n\tconst begin = `-----BEGIN ${label}-----`;\n\tconst end = `-----END ${label}-----`;\n\tconst lines = normalized.split('\\n');\n\tif (lines[0] !== begin || lines[lines.length - 1] !== end || lines.length < 3) {\n\t\tthrow new Error(`Invalid PEM for ${label}`);\n\t}\n\tconst bodyLines = normalizePemBodyLines(lines.slice(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(/\\r/g, '');\n\tconst blocks: PemBlock[] = [];\n\tconst beginToken = '-----BEGIN ';\n\t// Linear `indexOf` scan rather than a global regex with a lazy body: a\n\t// backtracking pattern like `([\\s\\S]*?)…\\1` is polynomial on many unclosed\n\t// BEGIN markers (ReDoS). `indexOf` advances monotonically, so this stays O(n)\n\t// while preserving the original block/gap/label semantics.\n\tlet cursor = 0;\n\tlet scan = 0;\n\twhile (scan < normalized.length) {\n\t\tconst beginIdx = normalized.indexOf(beginToken, scan);\n\t\tif (beginIdx === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst labelStart = beginIdx + beginToken.length;\n\t\tconst dashIdx = normalized.indexOf('-----', labelStart);\n\t\tif (dashIdx === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst label = normalized.slice(labelStart, dashIdx);\n\t\tconst beginLineEnd = dashIdx + 5;\n\t\t// A well-formed begin line is `-----BEGIN <label>-----\\n` with a dash-free,\n\t\t// single-line label (RFC 7468). Anything else is not a block start; skip it\n\t\t// so it surfaces in the stray-marker checks instead of being parsed.\n\t\tif (\n\t\t\tlabel.length === 0 ||\n\t\t\tlabel.includes('-') ||\n\t\t\tlabel.includes('\\n') ||\n\t\t\tnormalized[beginLineEnd] !== '\\n'\n\t\t) {\n\t\t\tscan = labelStart;\n\t\t\tcontinue;\n\t\t}\n\t\tconst bodyStart = beginLineEnd + 1;\n\t\tconst endToken = `\\n-----END ${label}-----`;\n\t\tconst endIdx = normalized.indexOf(endToken, bodyStart);\n\t\tif (endIdx === -1) {\n\t\t\tbreak;\n\t\t}\n\t\tconst blockEnd = endIdx + endToken.length;\n\t\tconst pem = normalized.slice(beginIdx, blockEnd);\n\t\tif (containsPemMarker(normalized.slice(cursor, beginIdx))) {\n\t\t\tthrow new Error('Malformed PEM block');\n\t\t}\n\t\tblocks.push({\n\t\t\tlabel,\n\t\t\tbytes: pemDecodeOrThrow(label, pem),\n\t\t\tpem,\n\t\t});\n\t\tcursor = blockEnd;\n\t\tscan = blockEnd;\n\t}\n\tif (containsPemMarker(normalized.slice(cursor))) {\n\t\tthrow new Error('Malformed PEM block');\n\t}\n\treturn blocks;\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 containsPemMarker(value: string): boolean {\n\treturn value.includes('-----BEGIN ') || value.includes('-----END ');\n}\n\n/**\n * Extracts and base64-decodes the DER content from a PEM string.\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":";;;;;;;;;;;;;;;;;AA8CA,SAAgB,UAAU,GAAe,GAAyB;CAGjE,OAAO,cAAc,EAAM,UAFd,EAAa,CACT,CAAC,CAAC,MAAM,UAAU,KAAK,CAAC,EAAA,CACC,KAAK,IAAI,EAAE,aAAa,EAAM;AACzE;;;;;;;;;AAkCA,SAAgB,iBAAiB,GAAe,GAAyB;CACxE,IAAM,IAAa,EAAI,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK,GACzC,IAAQ,cAAc,EAAM,QAC5B,IAAM,YAAY,EAAM,QACxB,IAAQ,EAAW,MAAM,IAAI;CACnC,IAAI,EAAM,OAAO,KAAS,EAAM,EAAM,SAAS,OAAO,KAAO,EAAM,SAAS,GAC3E,MAAU,MAAM,mBAAmB,GAAO;CAE3C,IAAM,IAAY,sBAAsB,EAAM,MAAM,GAAG,EAAE,CAAC;CAC1D,IAAI,MAAc,KAAA,GACjB,MAAU,MAAM,mBAAmB,GAAO;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emDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow } from "./pem/pem.js";
|
|
2
|
-
export { categorizePemBlocks, categorizePemBlocksOrThrow, pemDecode, pemDecodeOrThrow, pemEncode, splitPemBlocks, splitPemBlocksOrThrow };
|
|
1
|
+
import { categorizePemBlocks as e, categorizePemBlocksOrThrow as t, pemDecode as n, pemDecodeOrThrow as r, pemEncode as i, splitPemBlocks as a, splitPemBlocksOrThrow as o } from "./pem/pem.js";
|
|
2
|
+
export { e as categorizePemBlocks, t as categorizePemBlocksOrThrow, n as pemDecode, r as pemDecodeOrThrow, i as pemEncode, a as splitPemBlocks, o as splitPemBlocksOrThrow };
|
package/dist/pkcs/pfx.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
2
|
import { EncryptedPkcs8Options } from "../keys/keys.js";
|
|
3
|
-
import { ParsedCertificate } from "../x509/parse.js";
|
|
4
3
|
import { ParsePkcs12MacDataErrorCode, ParsePkcs12MacDataFailure, ParsePkcs12MacDataResult, ParsedPkcs12MacData, Pkcs12MacOptions, createPkcs12MacData, parsePkcs12MacData, parsePkcs12MacDataOrThrow } from "./pkcs12-mac.js";
|
|
5
|
-
|
|
4
|
+
import { ParsedCertificate } from "../x509/parse.js";
|
|
6
5
|
//#region src/pkcs/pfx.d.ts
|
|
7
6
|
/** PEM string or DER bytes for a certificate to include in a PFX bag. */
|
|
8
7
|
type PfxCertificateSource = string | Uint8Array | ParsedCertificate;
|
|
@@ -75,24 +74,36 @@ interface ParsedPfxBagAttributes {
|
|
|
75
74
|
readonly localKeyId?: string;
|
|
76
75
|
}
|
|
77
76
|
/**
|
|
78
|
-
* Discriminated union of SafeBag types decoded from a PFX container.
|
|
79
|
-
*
|
|
80
|
-
* Use `kind` to narrow: `'certificate'` | `'privateKey'` | `'unknown'`.
|
|
81
|
-
*/
|
|
77
|
+
* Discriminated union of SafeBag types decoded from a PFX container.
|
|
78
|
+
*
|
|
79
|
+
* Use `kind` to narrow: `'certificate'` | `'privateKey'` | `'unknown'`.
|
|
80
|
+
*/
|
|
82
81
|
type ParsedPfxBag = {
|
|
83
|
-
/** Bag contains an X.509 certificate. */
|
|
84
|
-
readonly
|
|
85
|
-
|
|
82
|
+
/** Bag contains an X.509 certificate. */
|
|
83
|
+
readonly kind: "certificate";
|
|
84
|
+
/** Dotted-decimal OID of the bag type. */
|
|
85
|
+
readonly bagId: string;
|
|
86
|
+
/** Decoded bag-level attributes. */
|
|
87
|
+
readonly attributes: ParsedPfxBagAttributes;
|
|
88
|
+
/** Parsed certificate from the certBag. */
|
|
86
89
|
readonly certificate: ParsedCertificate;
|
|
87
90
|
} | {
|
|
88
|
-
/** Bag contains a PKCS#8 private key. */
|
|
89
|
-
readonly
|
|
90
|
-
|
|
91
|
+
/** Bag contains a PKCS#8 private key. */
|
|
92
|
+
readonly kind: "privateKey";
|
|
93
|
+
/** Dotted-decimal OID of the bag type. */
|
|
94
|
+
readonly bagId: string;
|
|
95
|
+
/** Decoded bag-level attributes. */
|
|
96
|
+
readonly attributes: ParsedPfxBagAttributes;
|
|
97
|
+
/** Raw DER-encoded PKCS#8 PrivateKeyInfo. */
|
|
91
98
|
readonly pkcs8Der: Uint8Array;
|
|
92
99
|
} | {
|
|
93
|
-
/** Bag type not recognized by this library. */
|
|
94
|
-
readonly
|
|
95
|
-
|
|
100
|
+
/** Bag type not recognized by this library. */
|
|
101
|
+
readonly kind: "unknown";
|
|
102
|
+
/** Dotted-decimal OID of the bag type. */
|
|
103
|
+
readonly bagId: string;
|
|
104
|
+
/** Decoded bag-level attributes. */
|
|
105
|
+
readonly attributes: ParsedPfxBagAttributes;
|
|
106
|
+
/** Raw DER of the unrecognized bag value. */
|
|
96
107
|
readonly valueDer: Uint8Array;
|
|
97
108
|
};
|
|
98
109
|
/** Fully decoded PFX container returned by {@linkcode parsePfxDer} / {@linkcode parsePfxPem}. */
|
|
@@ -115,17 +126,19 @@ interface ParsePfxFailure extends Micro509Error<ParsePfxErrorCode> {
|
|
|
115
126
|
}
|
|
116
127
|
/** Success-or-failure result from {@linkcode parsePfxDer} / {@linkcode parsePfxPem}. */
|
|
117
128
|
type ParsePfxResult = {
|
|
118
|
-
/** Parse succeeded. */
|
|
129
|
+
/** Parse succeeded. */
|
|
130
|
+
readonly ok: true;
|
|
131
|
+
/** Decoded PFX container. */
|
|
119
132
|
readonly value: ParsedPfx;
|
|
120
133
|
} | ErrorResult<ParsePfxErrorCode, Record<never, never>, ParsePfxFailure>;
|
|
121
134
|
/**
|
|
122
|
-
* Caller-correctable failure code from {@linkcode createPfx}.
|
|
123
|
-
*
|
|
124
|
-
* The only parse boundary in creation is the certificate source: it is
|
|
125
|
-
* normalized from untrusted PEM/DER. Private keys are either a WebCrypto
|
|
126
|
-
* `CryptoKey` (platform errors stay throws) or raw PKCS#8 bytes passed through
|
|
127
|
-
* unvalidated, so there is no distinct `invalid_private_key` failure to model.
|
|
128
|
-
*/
|
|
135
|
+
* Caller-correctable failure code from {@linkcode createPfx}.
|
|
136
|
+
*
|
|
137
|
+
* The only parse boundary in creation is the certificate source: it is
|
|
138
|
+
* normalized from untrusted PEM/DER. Private keys are either a WebCrypto
|
|
139
|
+
* `CryptoKey` (platform errors stay throws) or raw PKCS#8 bytes passed through
|
|
140
|
+
* unvalidated, so there is no distinct `invalid_private_key` failure to model.
|
|
141
|
+
*/
|
|
129
142
|
type CreatePfxErrorCode = "invalid_certificate";
|
|
130
143
|
/** Error payload for a failed PFX creation. */
|
|
131
144
|
interface CreatePfxFailure extends Micro509Error<CreatePfxErrorCode> {
|
|
@@ -134,69 +147,72 @@ interface CreatePfxFailure extends Micro509Error<CreatePfxErrorCode> {
|
|
|
134
147
|
}
|
|
135
148
|
/** Success-or-failure result from {@linkcode createPfx}. */
|
|
136
149
|
type CreatePfxResult = {
|
|
137
|
-
/** Creation succeeded. */
|
|
150
|
+
/** Creation succeeded. */
|
|
151
|
+
readonly ok: true;
|
|
152
|
+
/** DER, PEM, and base64 forms of the PFX container. */
|
|
138
153
|
readonly value: PfxMaterial;
|
|
139
154
|
} | ErrorResult<CreatePfxErrorCode, Record<never, never>, CreatePfxFailure>;
|
|
140
155
|
/**
|
|
141
|
-
* Builds a PKCS#12/PFX archive containing certificates and/or private keys.
|
|
142
|
-
*
|
|
143
|
-
* When `encryption` is provided, the key-bag ContentInfo is PBES2-encrypted.
|
|
144
|
-
* When `mac` is provided, a PKCS#12 MAC integrity block is appended.
|
|
145
|
-
*
|
|
146
|
-
* Returns a {@linkcode CreatePfxResult}: the container material on success, or a
|
|
147
|
-
* typed `invalid_certificate` failure when a certificate source is not a single
|
|
148
|
-
* PEM/DER certificate.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```ts
|
|
152
|
-
* import { createPfx, unwrap } from 'micro509';
|
|
153
|
-
*
|
|
154
|
-
* const result = await createPfx({
|
|
155
|
-
* certificates: [{ certificate: certPem }],
|
|
156
|
-
* privateKeys: [{ privateKey: keyPair.privateKey }],
|
|
157
|
-
* encryption: { password: 's3cret' },
|
|
158
|
-
* mac: { password: 's3cret' },
|
|
159
|
-
* });
|
|
160
|
-
* if (result.ok) {
|
|
161
|
-
* const pfx = result.value; // pfx.der, pfx.pem, pfx.base64
|
|
162
|
-
* }
|
|
163
|
-
* // or, when inputs are already validated: const pfx = unwrap(result);
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
156
|
+
* Builds a PKCS#12/PFX archive containing certificates and/or private keys.
|
|
157
|
+
*
|
|
158
|
+
* When `encryption` is provided, the key-bag ContentInfo is PBES2-encrypted.
|
|
159
|
+
* When `mac` is provided, a PKCS#12 MAC integrity block is appended.
|
|
160
|
+
*
|
|
161
|
+
* Returns a {@linkcode CreatePfxResult}: the container material on success, or a
|
|
162
|
+
* typed `invalid_certificate` failure when a certificate source is not a single
|
|
163
|
+
* PEM/DER certificate.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { createPfx, unwrap } from 'micro509';
|
|
168
|
+
*
|
|
169
|
+
* const result = await createPfx({
|
|
170
|
+
* certificates: [{ certificate: certPem }],
|
|
171
|
+
* privateKeys: [{ privateKey: keyPair.privateKey }],
|
|
172
|
+
* encryption: { password: 's3cret' },
|
|
173
|
+
* mac: { password: 's3cret' },
|
|
174
|
+
* });
|
|
175
|
+
* if (result.ok) {
|
|
176
|
+
* const pfx = result.value; // pfx.der, pfx.pem, pfx.base64
|
|
177
|
+
* }
|
|
178
|
+
* // or, when inputs are already validated: const pfx = unwrap(result);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
166
181
|
declare function createPfx(input: CreatePfxInput): Promise<CreatePfxResult>;
|
|
167
182
|
/**
|
|
168
|
-
* Decodes a DER-encoded PKCS#12/PFX container into its constituent bags.
|
|
169
|
-
*
|
|
170
|
-
* Returns a result union — check `ok` before accessing `value`.
|
|
171
|
-
* Encrypted containers require `options.password`. MAC verification uses
|
|
172
|
-
* `options.macPassword` (falls back to `options.password`).
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* import { parsePfxDer } from 'micro509';
|
|
177
|
-
*
|
|
178
|
-
* const result = await parsePfxDer(pfxBytes, { password: 's3cret' });
|
|
179
|
-
* if (result.ok) {
|
|
180
|
-
* console.log(result.value.certificates.length);
|
|
181
|
-
* }
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
183
|
+
* Decodes a DER-encoded PKCS#12/PFX container into its constituent bags.
|
|
184
|
+
*
|
|
185
|
+
* Returns a result union — check `ok` before accessing `value`.
|
|
186
|
+
* Encrypted containers require `options.password`. MAC verification uses
|
|
187
|
+
* `options.macPassword` (falls back to `options.password`).
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { parsePfxDer } from 'micro509';
|
|
192
|
+
*
|
|
193
|
+
* const result = await parsePfxDer(pfxBytes, { password: 's3cret' });
|
|
194
|
+
* if (result.ok) {
|
|
195
|
+
* console.log(result.value.certificates.length);
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
184
199
|
declare function parsePfxDer(der: Uint8Array, options?: ParsePfxOptions): Promise<ParsePfxResult>;
|
|
185
200
|
/**
|
|
186
|
-
* Decodes a PEM-armored PKCS#12/PFX container. Expects exactly one `PKCS12` block.
|
|
187
|
-
*
|
|
188
|
-
* Delegates to {@linkcode parsePfxDer} after PEM decoding.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```ts
|
|
192
|
-
* import { parsePfxPem } from 'micro509';
|
|
193
|
-
*
|
|
194
|
-
* const result = await parsePfxPem(pfxPemString, { password: 's3cret' });
|
|
195
|
-
* if (result.ok) {
|
|
196
|
-
* console.log(result.value.privateKeys.length);
|
|
197
|
-
* }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
201
|
+
* Decodes a PEM-armored PKCS#12/PFX container. Expects exactly one `PKCS12` block.
|
|
202
|
+
*
|
|
203
|
+
* Delegates to {@linkcode parsePfxDer} after PEM decoding.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { parsePfxPem } from 'micro509';
|
|
208
|
+
*
|
|
209
|
+
* const result = await parsePfxPem(pfxPemString, { password: 's3cret' });
|
|
210
|
+
* if (result.ok) {
|
|
211
|
+
* console.log(result.value.privateKeys.length);
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
200
215
|
declare function parsePfxPem(pem: string, options?: ParsePfxOptions): Promise<ParsePfxResult>;
|
|
201
216
|
//#endregion
|
|
202
|
-
export { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, type ParsedPkcs12MacData, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, type Pkcs12MacOptions, createPfx, type createPkcs12MacData, parsePfxDer, parsePfxPem, type parsePkcs12MacData, type parsePkcs12MacDataOrThrow };
|
|
217
|
+
export { CreatePfxErrorCode, CreatePfxFailure, CreatePfxInput, CreatePfxResult, ParsePfxErrorCode, ParsePfxFailure, ParsePfxOptions, ParsePfxResult, type ParsePkcs12MacDataErrorCode, type ParsePkcs12MacDataFailure, type ParsePkcs12MacDataResult, ParsedPfx, ParsedPfxAttribute, ParsedPfxBag, ParsedPfxBagAttributes, type ParsedPkcs12MacData, PfxBagAttributesInput, PfxCertificateBagInput, PfxCertificateSource, PfxEncryptionOptions, PfxMaterial, PfxPrivateKeyBagInput, PfxPrivateKeySource, type Pkcs12MacOptions, createPfx, type createPkcs12MacData, parsePfxDer, parsePfxPem, type parsePkcs12MacData, type parsePkcs12MacDataOrThrow };
|
|
218
|
+
//# sourceMappingURL=pfx.d.ts.map
|