Skip to content

Commit 478c42d

Browse files
committedApr 23, 2024·
docs
1 parent 13230cd commit 478c42d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
 

‎src/cryptokeys.ts

+9
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ function formatAsPem(header: string, keyData: ArrayBuffer) {
205205
return `-----BEGIN ${header}-----\n${lines.join("\n")}\n-----END ${header}-----`;
206206
}
207207

208+
/**
209+
* Imports a CryptoKey from a PEM-formatted string or file.
210+
*
211+
* @param {string} keyDataOrPath - The PEM-formatted key data or the path to a file containing the PEM data.
212+
* @param {SupportedKeyPairAlgorithms} algorithm - The identifier of the key algorithm.
213+
* @returns {Promise<CryptoKey>} A Promise resolving to the imported CryptoKey.
214+
* @throws {JWTUnsupportedAlgorithmError} If the specified algorithm is not supported.
215+
* @throws {JWTFormatError} If the provided keyDataOrPath is not in a valid PEM format.
216+
*/
208217
export async function importPEMKey(keyDataOrPath: string, algorithm: SupportedKeyPairAlgorithms): Promise<CryptoKey> {
209218
if (algorithm === "none" || !algorithmMapping[algorithm]) {
210219
throw new JWTUnsupportedAlgorithmError("Unsupported key algorithm");

0 commit comments

Comments
 (0)
Please sign in to comment.