lib/keyderivation.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 25
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 2
c 0
b 0
f 0
nc 2
mnd 1
bc 2
fnc 1
dl 0
loc 25
rs 10
bpm 2
cpm 2
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A KeyDerivation.compute 0 14 2
1
var assert = require('assert'),
2
    pbkdf2Sha512 = require('./pbkdf2_sha512');
3
4
var KeyDerivation = {
5
    defaultIterations: 35000,
6
    subkeyIterations: 1,
7
    keySizeBits: 256
8
};
9
10
KeyDerivation.compute = function(pw, salt, iterations) {
11
    iterations = iterations || this.defaultIterations;
12
    assert(pw instanceof Buffer, 'Password must be provided as a Buffer');
0 ignored issues
show
Bug introduced by
The variable Buffer seems to be never declared. If this is a global, consider adding a /** global: Buffer */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
13
    assert(salt instanceof Buffer, 'Salt must be provided as a Buffer');
14
    assert(salt.length > 0, 'Salt must not be empty');
15
    assert(typeof iterations === 'number', 'Iterations must be a number');
16
    assert(iterations > 0, 'Iteration count should be at least 1');
17
18
    if (salt.length > 0x80) {
19
        throw new Error('Sanity check: Invalid salt, length can never be greater than 128');
20
    }
21
22
    return pbkdf2Sha512.digest(pw, salt, iterations, this.keySizeBits / 8);
23
};
24
25
module.exports = KeyDerivation;
26