node-ebics-client/lib/keymanagers/Keys.js

65 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
2019-11-01 11:49:33 +00:00
// const Key = require('./keyRSA');
const Key = require('./Key');
2019-11-01 11:49:33 +00:00
const keyOrNull = (key) => {
if (key instanceof Key)
return key;
return key ? new Key({ pem: key }) : null;
};
module.exports = class Keys {
constructor({
A006,
E002,
X002,
bankX002,
bankE002,
}) {
this.keys = {
A006: keyOrNull(A006),
E002: keyOrNull(E002),
X002: keyOrNull(X002),
bankX002: keyOrNull(bankX002),
bankE002: keyOrNull(bankE002),
};
}
static generate() {
const keys = {};
Object.keys({ A006: '', X002: '', E002: '' }).forEach((key) => {
2019-11-01 11:49:33 +00:00
keys[key] = Key.generate(); // Key().generate();
});
return new Keys(keys);
}
setBankKeys(bankKeys) {
2019-11-01 11:49:33 +00:00
this.keys.bankX002 = new Key(bankKeys.bankX002); // Key().importKey(bankKeys.bankX002);
this.keys.bankE002 = new Key(bankKeys.bankE002); // Key().importKey(bankKeys.bankE002);
}
a() {
return this.keys.A006;
}
e() {
return this.keys.E002;
}
x() {
return this.keys.X002;
}
bankX() {
return this.keys.bankX002;
}
bankE() {
return this.keys.bankE002;
}
};