diff options
author | Maximilian Krambach <[email protected]> | 2018-06-11 10:08:50 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-06-11 10:08:50 +0000 |
commit | e97e6c06e950cfad424e120f4f3752b594214c94 (patch) | |
tree | 38bb741a72b256c10c8e3df10ed4839ae97c7e3c /lang/js/src/Keyring.js | |
parent | js: change chunksize handling and decoding (diff) | |
download | gpgme-e97e6c06e950cfad424e120f4f3752b594214c94.tar.gz gpgme-e97e6c06e950cfad424e120f4f3752b594214c94.zip |
js: Add key creation to Keyring
--
* src/Keyring.js: Added method generateKey for new Keys
Still TODO: Key length and some further testing. Automated testing
does not work in this case, and gpgmejs will not be able to delete
test keys again.
* src/permittedOperations.js Added new method's definitions according
to gpgme-json
Diffstat (limited to 'lang/js/src/Keyring.js')
-rw-r--r-- | lang/js/src/Keyring.js | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js index 71585878..0d4e3c52 100644 --- a/lang/js/src/Keyring.js +++ b/lang/js/src/Keyring.js @@ -197,5 +197,63 @@ export class GPGME_Keyring { } } - // generateKey + /** + * Generates a new Key pair directly in gpg, and returns a GPGME_Key + * representing that Key. Please note that due to security concerns, secret + * Keys can not be _deleted_ from inside gpgmejs. + * + * @param {String} userId The user Id, e.g. "Foo Bar <[email protected]>" + * @param {*} algo (optional) algorithm to be used. See + * {@link supportedKeyAlgos } below for supported values. + * @param {Number} keyLength (optional) TODO + * @param {Date} expires (optional) Expiration date. If not set, expiration + * will be set to 'never' + * + * @returns{Promise<Key>} + */ + generateKey(userId, algo = 'default', keyLength, expires){ + if ( + typeof(userId) !== 'string' || + supportedKeyAlgos.indexOf(algo) < 0 || + (expires && !(expires instanceof Date)) + // TODO keylength + // TODO check for completeness of algos + ){ + return Promise.reject(gpgme_error('PARAM_WRONG')); + } + let me = this; + return new Promise(function(resolve, reject){ + let msg = createMessage('createkey'); + msg.setParameter('userid', userId); + msg.setParameter('algo', algo); + if (expires){ + msg.setParameter('expires', + Math.floor(expires.valueOf()/1000)); + } + // TODO append keylength to algo + msg.post().then(function(response){ + me.getKeys(response.fingerprint, true).then( + // TODO make prepare_sync (second parameter) optional here. + function(result){ + resolve(result); + }, function(error){ + reject(error); + }); + }, function(error) { + reject(error); + }); + }); + } } + +/** + * A list of algorithms supported for key generation. + */ +const supportedKeyAlgos = [ + 'default', + 'rsa', + 'dsa', + 'elg', + 'ed25519', + 'cv25519' +];
\ No newline at end of file |