Compare commits
No commits in common. "8f227d8c0e32960951b787354d13a4534edfe07f" and "e470b68ea57a85a3287afd67995c12cc3c5698aa" have entirely different histories.
8f227d8c0e
...
e470b68ea5
1
index.js
1
index.js
@ -39,6 +39,7 @@ function random_string (len = 8) {
|
|||||||
throw new Error ('invalid length');
|
throw new Error ('invalid length');
|
||||||
return crypto.randomBytes (Math.ceil (len * 3 / 4))
|
return crypto.randomBytes (Math.ceil (len * 3 / 4))
|
||||||
.toString ('base64')
|
.toString ('base64')
|
||||||
|
.replace (/[=]+$/u, '')
|
||||||
.substr (0, len);
|
.substr (0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ module.exports = function(config) {
|
|||||||
config.set({
|
config.set({
|
||||||
mutator: "javascript",
|
mutator: "javascript",
|
||||||
packageManager: "yarn",
|
packageManager: "yarn",
|
||||||
reporters: ["clear-text", "progress"],
|
reporters: ["clear-text"],
|
||||||
testRunner: "command",
|
testRunner: "command",
|
||||||
transpilers: [],
|
transpilers: [],
|
||||||
coverageAnalysis: "all",
|
coverageAnalysis: "all",
|
||||||
|
@ -29,13 +29,6 @@ test ('random_hex should refuse lenght smaller 1', (t) => {
|
|||||||
t.is(error.message, 'invalid length');
|
t.is(error.message, 'invalid length');
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('random_hex should always return correct length', (t)=>{
|
|
||||||
for (let i = 1; i < 32; i++) {
|
|
||||||
const hex = crypto.random_hex (i);
|
|
||||||
t.is (hex.length, i);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('random_string', (t) => {
|
test ('random_string', (t) => {
|
||||||
const str = crypto.random_string (16);
|
const str = crypto.random_string (16);
|
||||||
t.is (str.length, 16);
|
t.is (str.length, 16);
|
||||||
@ -53,14 +46,6 @@ test ('random_string should refuse lenght smaller 1', (t) => {
|
|||||||
t.is(error.message, 'invalid length');
|
t.is(error.message, 'invalid length');
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('random_string should always return correct length', (t)=>{
|
|
||||||
for (let i = 1; i < 32; i++) {
|
|
||||||
const str = crypto.random_string (i);
|
|
||||||
t.is (str.length, i);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
test ('hash_sha512', (t) => {
|
test ('hash_sha512', (t) => {
|
||||||
const hash = crypto.hash_sha512 ('a', 'b');
|
const hash = crypto.hash_sha512 ('a', 'b');
|
||||||
t.is (
|
t.is (
|
||||||
@ -107,16 +92,6 @@ test ('verify_signature', (t) => {
|
|||||||
t.deepEqual (obj, dec);
|
t.deepEqual (obj, dec);
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('do not fail verification if timeout unspecified', async (t) => {
|
|
||||||
const obj = { foo: 'bar' };
|
|
||||||
const str = crypto.sign_object (obj, 'baz');
|
|
||||||
await new Promise ((res) => {
|
|
||||||
setTimeout (res, 10);
|
|
||||||
});
|
|
||||||
const dec = crypto.verify_signature (str, 'baz');
|
|
||||||
t.deepEqual (obj, dec);
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('reject tampered signatures', (t) => {
|
test ('reject tampered signatures', (t) => {
|
||||||
const obj = { foo: 'bar' };
|
const obj = { foo: 'bar' };
|
||||||
const str = crypto.sign_object (obj, 'baz');
|
const str = crypto.sign_object (obj, 'baz');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user