2016-12-21 23:37:48 +00:00
|
|
|
/*
|
|
|
|
* This is a stupid little mock that basically disabled encryption.
|
|
|
|
* The reason it is needed is because the Forge module loader doesn't
|
|
|
|
* play along with Jest.
|
|
|
|
*/
|
|
|
|
|
2017-01-09 21:59:52 +00:00
|
|
|
const jsbn = require('jsbn');
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
module.exports = function (options) {
|
|
|
|
const forge = require('../../node_modules/node-forge/js/forge')(options);
|
|
|
|
|
2017-01-09 21:59:52 +00:00
|
|
|
forge.jsbn = jsbn;
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
forge.util = {
|
|
|
|
hexToBytes: forge.hexToBytes,
|
|
|
|
bytesToHex: forge.bytesToHex,
|
|
|
|
createBuffer (text) {
|
|
|
|
return new Buffer(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
forge.pkcs5 = {
|
|
|
|
pbkdf2 () {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-24 22:24:10 +00:00
|
|
|
forge.md = {
|
|
|
|
sha256: {
|
|
|
|
create () {
|
|
|
|
return 'TODO'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-09 21:59:52 +00:00
|
|
|
forge.rsa = {
|
|
|
|
setPublicKey() {
|
|
|
|
return {
|
|
|
|
encrypt (str) {
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setPrivateKey() {
|
|
|
|
return {
|
|
|
|
decrypt (str) {
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
forge.random = {
|
|
|
|
getBytesSync(n) {
|
|
|
|
let s = '';
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
s += 'a';
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-09 21:59:52 +00:00
|
|
|
forge.pki = {
|
|
|
|
rsa: {
|
|
|
|
generateKeyPair() {
|
|
|
|
return {
|
|
|
|
privateKey: {
|
|
|
|
d: 'a',
|
|
|
|
dP: 'a',
|
|
|
|
dQ: 'a',
|
|
|
|
e: 'a',
|
|
|
|
n: 'a',
|
|
|
|
p: 'a',
|
|
|
|
q: 'a',
|
|
|
|
qInv: 'a',
|
|
|
|
},
|
|
|
|
publicKey: {
|
|
|
|
e: 'a',
|
|
|
|
n: 'a',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
forge.cipher = {
|
|
|
|
createCipher(alg, key) {
|
|
|
|
return {
|
|
|
|
start(config) {
|
|
|
|
this._config = config;
|
|
|
|
},
|
|
|
|
update(buffer) {
|
|
|
|
this._data = buffer;
|
|
|
|
},
|
|
|
|
finish() {
|
|
|
|
this.mode = {tag: 'tag'};
|
|
|
|
this.output = this._data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
createDecipher(alg, key) {
|
|
|
|
return {
|
|
|
|
start (config) {
|
|
|
|
this._config = config;
|
|
|
|
},
|
|
|
|
update (buffer) {
|
|
|
|
this.output = buffer;
|
|
|
|
},
|
|
|
|
finish () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return forge;
|
2017-01-09 21:59:52 +00:00
|
|
|
}
|
|
|
|
;
|