mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-07 01:21:35 +00:00
Store named key params in key objects (#1141)
- Store private and public params separately and by name in objects, instead of as an array - Do not keep params in MPI form, but convert them to Uint8Arrays when generating/parsing the key - Modify low-level crypto functions to always accept and return Uint8Arrays instead of BigIntegers - Move PKCS1 padding to lower level functions
This commit is contained in:
25
src/util.js
25
src/util.js
@@ -167,6 +167,31 @@ export default {
|
||||
return str;
|
||||
},
|
||||
|
||||
/**
|
||||
* Read one MPI from bytes in input
|
||||
* @param {Uint8Array} bytes input data to parse
|
||||
* @returns {Uint8Array} parsed MPI
|
||||
*/
|
||||
readMPI: function (bytes) {
|
||||
const bits = (bytes[0] << 8) | bytes[1];
|
||||
const bytelen = (bits + 7) >>> 3;
|
||||
return bytes.subarray(2, 2 + bytelen);
|
||||
},
|
||||
|
||||
/**
|
||||
* Pad Uint8Array to length by adding 0x0 bytes
|
||||
* @param {Uint8Array} bytes data to pad
|
||||
* @param {Number} length padded length
|
||||
* @param {'be'|'le'} endianess endianess of input data
|
||||
* @return {Uint8Array} padded bytes
|
||||
*/
|
||||
padToLength(bytes, length, endianess = 'be') {
|
||||
const padded = new Uint8Array(length);
|
||||
const offset = (endianess === 'be') ? 0 : (length - bytes.length);
|
||||
padded.set(bytes, offset);
|
||||
return padded;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert a Uint8Array to an MPI-formatted Uint8Array.
|
||||
* Note: the output is **not** an MPI object.
|
||||
|
||||
Reference in New Issue
Block a user