-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: importJWK always returns a Uint8Array for symmetric key inputs
BREAKING CHANGE: importJWK "octAsKeyObject" option was removed. importJWK will no longer return CryptoKey or KeyObject for "oct" (octet sequence) JWK key types, it will instead always return a Uint8Array formed from the "k" (Key Value) Parameter regardless of the other JWK Parameters that may be present.
- Loading branch information
Showing
6 changed files
with
29 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import { createPrivateKey, createPublicKey, createSecretKey } from 'node:crypto' | ||
import { createPrivateKey, createPublicKey } from 'node:crypto' | ||
import type { KeyObject } from 'node:crypto' | ||
|
||
import type { JWKImportFunction } from '../interfaces.d' | ||
import { decode as base64url } from './base64url.js' | ||
import type { JWK } from '../../types.d' | ||
|
||
const parse: JWKImportFunction = (jwk: JWK): KeyObject => { | ||
if (jwk.kty === 'oct') { | ||
return createSecretKey(base64url(jwk.k!)) | ||
} | ||
|
||
return jwk.d | ||
? createPrivateKey({ format: 'jwk', key: jwk }) | ||
: createPublicKey({ format: 'jwk', key: jwk }) | ||
return (jwk.d ? createPrivateKey : createPublicKey)({ format: 'jwk', key: jwk }) | ||
} | ||
export default parse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters