Fix GenerateKey lint: JSDoc on helper functions and constructor
This commit is contained in:
parent
7a4b47fa6b
commit
0dda2fe08a
@ -23,6 +23,12 @@ const KEY_SPECS = {
|
|||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates n cryptographically random bytes using WebCrypto or node-forge.
|
||||||
|
*
|
||||||
|
* @param {number} n
|
||||||
|
* @returns {Uint8Array}
|
||||||
|
*/
|
||||||
function randomBytes(n) {
|
function randomBytes(n) {
|
||||||
const buf = new Uint8Array(n);
|
const buf = new Uint8Array(n);
|
||||||
if (typeof globalThis !== "undefined" && globalThis.crypto && globalThis.crypto.getRandomValues) {
|
if (typeof globalThis !== "undefined" && globalThis.crypto && globalThis.crypto.getRandomValues) {
|
||||||
@ -34,14 +40,32 @@ function randomBytes(n) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Uint8Array to an uppercase hex string.
|
||||||
|
*
|
||||||
|
* @param {Uint8Array} bytes
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function toHex(bytes) {
|
function toHex(bytes) {
|
||||||
return Array.from(bytes, b => b.toString(16).padStart(2, "0").toUpperCase()).join("");
|
return Array.from(bytes, b => b.toString(16).padStart(2, "0").toUpperCase()).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Uint8Array to a byte string for use with node-forge.
|
||||||
|
*
|
||||||
|
* @param {Uint8Array} bytes
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function toByteStr(bytes) {
|
function toByteStr(bytes) {
|
||||||
return Array.from(bytes, b => String.fromCharCode(b)).join("");
|
return Array.from(bytes, b => String.fromCharCode(b)).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Left-shifts a byte array by one bit.
|
||||||
|
*
|
||||||
|
* @param {Uint8Array} a
|
||||||
|
* @returns {Uint8Array}
|
||||||
|
*/
|
||||||
function shiftLeft1(a) {
|
function shiftLeft1(a) {
|
||||||
const out = new Uint8Array(a.length);
|
const out = new Uint8Array(a.length);
|
||||||
for (let i = 0; i < a.length - 1; i++)
|
for (let i = 0; i < a.length - 1; i++)
|
||||||
@ -50,7 +74,13 @@ function shiftLeft1(a) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** AES-CMAC KCV: CMAC(key, zero-block), first 3 bytes (AES-128 key). */
|
/**
|
||||||
|
* Computes the AES CMAC KCV: CMAC(key, zero-block), first 3 bytes.
|
||||||
|
* Uses the PCI PIN-required method, not the legacy ECB-zeros method.
|
||||||
|
*
|
||||||
|
* @param {Uint8Array} key
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function aesCmacKcv(key) {
|
function aesCmacKcv(key) {
|
||||||
const k = key.slice(0, 16);
|
const k = key.slice(0, 16);
|
||||||
const RB = new Uint8Array(16); RB[15] = 0x87;
|
const RB = new Uint8Array(16); RB[15] = 0x87;
|
||||||
@ -81,6 +111,9 @@ function aesCmacKcv(key) {
|
|||||||
*/
|
*/
|
||||||
class GenerateKey extends Operation {
|
class GenerateKey extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GenerateKey constructor.
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user