mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-24 15:12:31 +00:00
Internal: refactor uint8ArrayToHex
for performance and to avoid branching
This commit is contained in:
parent
56cd448a32
commit
089a14f9e0
16
src/util.js
16
src/util.js
@ -154,18 +154,10 @@ const util = {
|
||||
* @returns {String} Hexadecimal representation of the array.
|
||||
*/
|
||||
uint8ArrayToHex: function (bytes) {
|
||||
const r = [];
|
||||
const e = bytes.length;
|
||||
let c = 0;
|
||||
let h;
|
||||
while (c < e) {
|
||||
h = bytes[c++].toString(16);
|
||||
while (h.length < 2) {
|
||||
h = '0' + h;
|
||||
}
|
||||
r.push('' + h);
|
||||
}
|
||||
return r.join('');
|
||||
const hexAlphabet = '0123456789abcdef';
|
||||
let s = '';
|
||||
bytes.forEach(v => { s += hexAlphabet[v >> 4] + hexAlphabet[v & 15]; });
|
||||
return s;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ export default () => describe('TripleDES (EDE) cipher test with test vectors fro
|
||||
expect(encr, 'vector with block ' + util.uint8ArrayToHex(testvectors[i][0]) +
|
||||
' and key ' + util.uint8ArrayToHex(key) +
|
||||
' should be ' + util.uint8ArrayToHex(testvectors[i][1]) +
|
||||
' != ' + util.uint8ArrayToHex(encr)).to.be.equal(util.uint8ArrayToString(testvectors[i][1]));
|
||||
' != ' + encr).to.be.equal(util.uint8ArrayToString(testvectors[i][1]));
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user