From 478c42db7ed908bfe2883d9299d573e72e265119 Mon Sep 17 00:00:00 2001 From: Pinta365 Date: Tue, 23 Apr 2024 19:12:49 +0200 Subject: [PATCH] docs --- src/cryptokeys.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cryptokeys.ts b/src/cryptokeys.ts index 45b8502..54a3f9c 100644 --- a/src/cryptokeys.ts +++ b/src/cryptokeys.ts @@ -205,6 +205,15 @@ function formatAsPem(header: string, keyData: ArrayBuffer) { return `-----BEGIN ${header}-----\n${lines.join("\n")}\n-----END ${header}-----`; } +/** + * Imports a CryptoKey from a PEM-formatted string or file. + * + * @param {string} keyDataOrPath - The PEM-formatted key data or the path to a file containing the PEM data. + * @param {SupportedKeyPairAlgorithms} algorithm - The identifier of the key algorithm. + * @returns {Promise} A Promise resolving to the imported CryptoKey. + * @throws {JWTUnsupportedAlgorithmError} If the specified algorithm is not supported. + * @throws {JWTFormatError} If the provided keyDataOrPath is not in a valid PEM format. + */ export async function importPEMKey(keyDataOrPath: string, algorithm: SupportedKeyPairAlgorithms): Promise { if (algorithm === "none" || !algorithmMapping[algorithm]) { throw new JWTUnsupportedAlgorithmError("Unsupported key algorithm");