mirror of
https://github.com/danbulant/jose
synced 2026-05-19 20:38:42 +00:00
refactor: SHA-2 digests
This commit is contained in:
parent
8b997bb330
commit
5770d303dd
4 changed files with 12 additions and 11 deletions
|
|
@ -39,6 +39,14 @@ export async function calculateJwkThumbprint(
|
|||
throw new TypeError('JWK must be an object')
|
||||
}
|
||||
|
||||
if (
|
||||
digestAlgorithm !== 'sha256' &&
|
||||
digestAlgorithm !== 'sha384' &&
|
||||
digestAlgorithm !== 'sha512'
|
||||
) {
|
||||
throw new TypeError('digestAlgorithm must one of "sha256", "sha384, or "sha512"')
|
||||
}
|
||||
|
||||
let components: JWK
|
||||
switch (jwk.kty) {
|
||||
case 'EC':
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { DigestFunction } from '../runtime/interfaces.d'
|
||||
import digest from '../runtime/digest.js'
|
||||
|
||||
export const encoder = new TextEncoder()
|
||||
export const decoder = new TextDecoder()
|
||||
|
|
@ -46,12 +46,7 @@ export function lengthAndInput(input: Uint8Array) {
|
|||
return concat(uint32be(input.length), input)
|
||||
}
|
||||
|
||||
export async function concatKdf(
|
||||
digest: DigestFunction,
|
||||
secret: Uint8Array,
|
||||
bits: number,
|
||||
value: Uint8Array,
|
||||
) {
|
||||
export async function concatKdf(secret: Uint8Array, bits: number, value: Uint8Array) {
|
||||
const iterations = Math.ceil((bits >> 3) / 32)
|
||||
let res!: Uint8Array
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../../lib/buffer_utils.js'
|
||||
import crypto, { isCryptoKey } from './webcrypto.js'
|
||||
import { checkEncCryptoKey } from '../../lib/crypto_key.js'
|
||||
import digest from './digest.js'
|
||||
import invalidKeyInput from '../../lib/invalid_key_input.js'
|
||||
import { types } from './is_key_like.js'
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ export async function deriveKey(
|
|||
),
|
||||
)
|
||||
|
||||
return concatKdf(digest, sharedSecret, keyLength, value)
|
||||
return concatKdf(sharedSecret, keyLength, value)
|
||||
}
|
||||
|
||||
export async function generateEpk(key: unknown) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { promisify } from 'util'
|
|||
|
||||
import getNamedCurve from './get_named_curve.js'
|
||||
import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../../lib/buffer_utils.js'
|
||||
import digest from './digest.js'
|
||||
import { JOSENotSupported } from '../../util/errors.js'
|
||||
import { isCryptoKey } from './webcrypto.js'
|
||||
import { checkEncCryptoKey } from '../../lib/crypto_key.js'
|
||||
|
|
@ -49,7 +48,7 @@ export async function deriveKey(
|
|||
)
|
||||
|
||||
const sharedSecret = diffieHellman({ privateKey, publicKey })
|
||||
return concatKdf(digest, sharedSecret, keyLength, value)
|
||||
return concatKdf(sharedSecret, keyLength, value)
|
||||
}
|
||||
|
||||
export async function generateEpk(kee: unknown) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue