mirror of
https://github.com/danbulant/jose
synced 2026-05-25 04:51:47 +00:00
15 lines
626 B
JavaScript
15 lines
626 B
JavaScript
export default (alg, key) => {
|
|
if (alg.startsWith('HS')) {
|
|
const bitlen = parseInt(alg.substr(-3), 10);
|
|
const { length } = key.algorithm;
|
|
if (typeof length !== 'number' || length < bitlen) {
|
|
throw new TypeError(`${alg} requires symmetric keys to be ${bitlen} bits or larger`);
|
|
}
|
|
}
|
|
if (alg.startsWith('RS') || alg.startsWith('PS')) {
|
|
const { modulusLength } = key.algorithm;
|
|
if (typeof modulusLength !== 'number' || modulusLength < 2048) {
|
|
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
}
|
|
}
|
|
};
|