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.
|
|
|
|
*/
|
2021-05-12 06:35:00 +00:00
|
|
|
import forge from '../../node_modules/node-forge/lib/index';
|
2016-12-21 23:37:48 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
// WARNING: changing this to `export default` will break the mock and be incredibly hard to debug. Ask me how I know.
|
2017-02-26 21:12:51 +00:00
|
|
|
module.exports = {
|
|
|
|
jsbn: forge.jsbn,
|
|
|
|
util: forge.util,
|
|
|
|
pkcs5: {
|
2019-04-18 00:50:03 +00:00
|
|
|
pbkdf2: forge.pkcs5.pbkdf2,
|
2017-02-26 21:12:51 +00:00
|
|
|
},
|
|
|
|
md: {
|
2019-04-18 00:50:03 +00:00
|
|
|
sha256: forge.md.sha256,
|
2017-02-26 21:12:51 +00:00
|
|
|
},
|
|
|
|
rsa: {
|
2018-06-25 17:42:50 +00:00
|
|
|
setPublicKey() {
|
2017-01-09 21:59:52 +00:00
|
|
|
return {
|
2021-05-12 06:35:00 +00:00
|
|
|
encrypt(str: string) {
|
2017-03-03 20:09:08 +00:00
|
|
|
return str;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-03-03 20:09:08 +00:00
|
|
|
};
|
2017-01-09 21:59:52 +00:00
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
setPrivateKey() {
|
2017-01-09 21:59:52 +00:00
|
|
|
return {
|
2021-05-12 06:35:00 +00:00
|
|
|
decrypt(str: string) {
|
2017-03-03 20:09:08 +00:00
|
|
|
return str;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-03-03 20:09:08 +00:00
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-02-26 21:12:51 +00:00
|
|
|
},
|
|
|
|
random: {
|
2021-05-12 06:35:00 +00:00
|
|
|
getBytesSync(n: number) {
|
2016-12-21 23:37:48 +00:00
|
|
|
let s = '';
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
s += 'a';
|
|
|
|
}
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
return s;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2017-02-26 21:12:51 +00:00
|
|
|
},
|
|
|
|
pki: {
|
2017-01-09 21:59:52 +00:00
|
|
|
rsa: {
|
2018-06-25 17:42:50 +00:00
|
|
|
generateKeyPair() {
|
2017-01-09 21:59:52 +00:00
|
|
|
return {
|
|
|
|
privateKey: {
|
|
|
|
d: 'a',
|
|
|
|
dP: 'a',
|
|
|
|
dQ: 'a',
|
|
|
|
e: 'a',
|
|
|
|
n: 'a',
|
|
|
|
p: 'a',
|
|
|
|
q: 'a',
|
2018-12-12 17:36:11 +00:00
|
|
|
qInv: 'a',
|
2017-01-09 21:59:52 +00:00
|
|
|
},
|
|
|
|
publicKey: {
|
|
|
|
e: 'a',
|
2018-12-12 17:36:11 +00:00
|
|
|
n: 'a',
|
|
|
|
},
|
2017-03-03 20:09:08 +00:00
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
2017-02-26 21:12:51 +00:00
|
|
|
},
|
|
|
|
cipher: {
|
2021-05-12 06:35:00 +00:00
|
|
|
createCipher() {
|
2016-12-21 23:37:48 +00:00
|
|
|
return {
|
2018-06-25 17:42:50 +00:00
|
|
|
start(config) {
|
2016-12-21 23:37:48 +00:00
|
|
|
this._config = config;
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
update(buffer) {
|
2016-12-21 23:37:48 +00:00
|
|
|
this._data = buffer;
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
finish() {
|
2021-05-12 06:35:00 +00:00
|
|
|
this.mode = {
|
|
|
|
tag: 'tag',
|
|
|
|
};
|
2016-12-21 23:37:48 +00:00
|
|
|
this.output = this._data;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2016-12-21 23:37:48 +00:00
|
|
|
};
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
|
|
|
createDecipher() {
|
2016-12-21 23:37:48 +00:00
|
|
|
return {
|
2018-06-25 17:42:50 +00:00
|
|
|
start(config) {
|
2016-12-21 23:37:48 +00:00
|
|
|
this._config = config;
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
update(buffer) {
|
2016-12-21 23:37:48 +00:00
|
|
|
this.output = buffer;
|
|
|
|
},
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
finish() {
|
2016-12-21 23:37:48 +00:00
|
|
|
return true;
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
2016-12-21 23:37:48 +00:00
|
|
|
};
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
2017-02-26 21:12:51 +00:00
|
|
|
};
|