MCPcopy Index your code
hub / github.com/nodejs/node / assertApproximateSize

Function assertApproximateSize

test/common/crypto.js:39–47  ·  view source on GitHub ↗
(key, expectedSize)

Source from the content-addressed store, hash-verified

37// Asserts that the size of the given key (in chars or bytes) is within 10% of
38// the expected size.
39function assertApproximateSize(key, expectedSize) {
40 const u = typeof key === 'string' ? 'chars' : 'bytes';
41 const min = Math.floor(0.9 * expectedSize);
42 const max = Math.ceil(1.1 * expectedSize);
43 assert(key.length >= min,
44 `Key (${key.length} ${u}) is shorter than expected (${min} ${u})`);
45 assert(key.length <= max,
46 `Key (${key.length} ${u}) is longer than expected (${max} ${u})`);
47}
48
49// Tests that a key pair can be used for encryption / decryption.
50function testEncryptDecrypt(publicKey, privateKey) {

Calls 1

assertFunction · 0.50

Tested by

no test coverage detected