Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinta365 committed Apr 23, 2024
1 parent 13230cd commit 478c42d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cryptokeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CryptoKey>} 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<CryptoKey> {
if (algorithm === "none" || !algorithmMapping[algorithm]) {
throw new JWTUnsupportedAlgorithmError("Unsupported key algorithm");
Expand Down

0 comments on commit 478c42d

Please sign in to comment.