-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact(der-to-jose) add additional param length checks
- Loading branch information
Showing
3 changed files
with
200 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
function getParamSize(keySize) { | ||
var result = ((keySize / 8) | 0) + (keySize % 8 === 0 ? 0 : 1); | ||
return result; | ||
} | ||
|
||
var paramBytesForAlg = { | ||
ES256: getParamSize(256), | ||
ES384: getParamSize(384), | ||
ES512: getParamSize(521) | ||
}; | ||
|
||
function getParamBytesForAlg(alg) { | ||
var paramBytes = paramBytesForAlg[alg]; | ||
if (paramBytes) { | ||
return paramBytes; | ||
} | ||
|
||
throw new Error('Unknown algorithm "' + alg + '"'); | ||
} | ||
|
||
module.exports = getParamBytesForAlg; |