From 8b8c009dee8ae5493e7f888ee518468dbfcf5375 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 21 Aug 2018 11:42:11 +0200 Subject: [PATCH] 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. --- lang/js/src/Keyring.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lang/js/src/Keyring.js b/lang/js/src/Keyring.js index 81a047ca..ab0144ef 100644 --- a/lang/js/src/Keyring.js +++ b/lang/js/src/Keyring.js @@ -367,8 +367,8 @@ export class GPGME_Keyring { * @param {String} algo (optional) algorithm (and optionally key size) * to be used. See {@link supportedKeyAlgos} below for supported * values. If ommitted, 'default' is used. - * @param {Date} expires (optional) Expiration date. If not set, - * expiration will be set to 'never' + * @param {Number} expires (optional) Expiration time in seconds from now. + * If not set or set to 0, expiration will be 'never' * @param {String} subkey_algo (optional) algorithm of the encryption * subkey. If ommited the same as algo is used. * @@ -380,7 +380,7 @@ export class GPGME_Keyring { typeof (userId) !== 'string' || // eslint-disable-next-line no-use-before-define supportedKeyAlgos.indexOf(algo) < 0 || - (expires && !(expires instanceof Date)) + (expires && !( Number.isInteger(expires) || expires < 0 )) ){ return Promise.reject(gpgme_error('PARAM_WRONG')); } @@ -397,9 +397,7 @@ export class GPGME_Keyring { msg.setParameter('subkey-algo', subkey_algo ); } if (expires){ - const now = new Date(); - msg.setParameter('expires', - Math.floor((expires - now) /1000)); + msg.setParameter('expires', expires); } else { msg.setParameter('expires', 0); }