Skip to content

Commit

Permalink
refactor(webcrypto): use isCryptoKey in checkCekLength
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 20, 2021
1 parent 9948de8 commit 319d1c0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/runtime/browser/check_cek_length.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { JWEInvalid, JOSENotSupported } from '../../util/errors.js'
import { isCryptoKey } from './webcrypto.js'

const checkCekLength = (enc: string, cek: Uint8Array | CryptoKey) => {
let expected: number
Expand Down Expand Up @@ -30,7 +31,7 @@ const checkCekLength = (enc: string, cek: Uint8Array | CryptoKey) => {
}

// CryptoKey
if (cek.algorithm !== undefined) {
if (isCryptoKey(cek)) {
const { length } = <AesKeyAlgorithm>cek.algorithm
if (length !== expected) {
throw new JWEInvalid('Invalid Content Encryption Key length')
Expand Down

0 comments on commit 319d1c0

Please sign in to comment.