mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-25 07:32:30 +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.
|
* @returns {String} Hexadecimal representation of the array.
|
||||||
*/
|
*/
|
||||||
uint8ArrayToHex: function (bytes) {
|
uint8ArrayToHex: function (bytes) {
|
||||||
const r = [];
|
const hexAlphabet = '0123456789abcdef';
|
||||||
const e = bytes.length;
|
let s = '';
|
||||||
let c = 0;
|
bytes.forEach(v => { s += hexAlphabet[v >> 4] + hexAlphabet[v & 15]; });
|
||||||
let h;
|
return s;
|
||||||
while (c < e) {
|
|
||||||
h = bytes[c++].toString(16);
|
|
||||||
while (h.length < 2) {
|
|
||||||
h = '0' + h;
|
|
||||||
}
|
|
||||||
r.push('' + h);
|
|
||||||
}
|
|
||||||
return r.join('');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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]) +
|
expect(encr, 'vector with block ' + util.uint8ArrayToHex(testvectors[i][0]) +
|
||||||
' and key ' + util.uint8ArrayToHex(key) +
|
' and key ' + util.uint8ArrayToHex(key) +
|
||||||
' should be ' + util.uint8ArrayToHex(testvectors[i][1]) +
|
' 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();
|
done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user