js: set expiry of generatedKey to seconds from now

--

* src/Keyring.js: Changed key ecpiration from Date to seconds from
  creation, as in gpgme. The Date parameter used before was due to a
  misunderstanding in documentation and requests from potential users.
This commit is contained in:
Maximilian Krambach 2018-08-21 11:42:11 +02:00
parent d77a1c887d
commit 8b8c009dee

View File

@ -367,8 +367,8 @@ export class GPGME_Keyring {
* @param {String} algo (optional) algorithm (and optionally key size) * @param {String} algo (optional) algorithm (and optionally key size)
* to be used. See {@link supportedKeyAlgos} below for supported * to be used. See {@link supportedKeyAlgos} below for supported
* values. If ommitted, 'default' is used. * values. If ommitted, 'default' is used.
* @param {Date} expires (optional) Expiration date. If not set, * @param {Number} expires (optional) Expiration time in seconds from now.
* expiration will be set to 'never' * If not set or set to 0, expiration will be 'never'
* @param {String} subkey_algo (optional) algorithm of the encryption * @param {String} subkey_algo (optional) algorithm of the encryption
* subkey. If ommited the same as algo is used. * subkey. If ommited the same as algo is used.
* *
@ -380,7 +380,7 @@ export class GPGME_Keyring {
typeof (userId) !== 'string' || typeof (userId) !== 'string' ||
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
supportedKeyAlgos.indexOf(algo) < 0 || supportedKeyAlgos.indexOf(algo) < 0 ||
(expires && !(expires instanceof Date)) (expires && !( Number.isInteger(expires) || expires < 0 ))
){ ){
return Promise.reject(gpgme_error('PARAM_WRONG')); return Promise.reject(gpgme_error('PARAM_WRONG'));
} }
@ -397,9 +397,7 @@ export class GPGME_Keyring {
msg.setParameter('subkey-algo', subkey_algo ); msg.setParameter('subkey-algo', subkey_algo );
} }
if (expires){ if (expires){
const now = new Date(); msg.setParameter('expires', expires);
msg.setParameter('expires',
Math.floor((expires - now) /1000));
} else { } else {
msg.setParameter('expires', 0); msg.setParameter('expires', 0);
} }