aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Key.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-07-27 18:56:11 +0000
committerMaximilian Krambach <[email protected]>2018-07-27 18:56:11 +0000
commit522121ea7e105acc22795b1997ca500c7b227b4f (patch)
tree6abcd2aaceb3460b366d3c3e57491186a9e5fe94 /lang/js/src/Key.js
parentjs: change the write access for js class methods (diff)
downloadgpgme-522121ea7e105acc22795b1997ca500c7b227b4f.tar.gz
gpgme-522121ea7e105acc22795b1997ca500c7b227b4f.zip
js: fix indentaion
-- * doing the indentation changes that became neccesary in the last commit.
Diffstat (limited to 'lang/js/src/Key.js')
-rw-r--r--lang/js/src/Key.js493
1 files changed, 246 insertions, 247 deletions
diff --git a/lang/js/src/Key.js b/lang/js/src/Key.js
index a7f7dd26..d5873a70 100644
--- a/lang/js/src/Key.js
+++ b/lang/js/src/Key.js
@@ -66,224 +66,226 @@ export class GPGME_Key {
return _data.fingerprint;
};
- /**
- * Property indicating if the Key possesses a private/secret part. If this
- * information is not yet cached, it returns an {@link GPGME_Error} with
- * code 'KEY_NO_INIT'. Running {@link refreshKey} may help in this case.
- * @returns {Boolean} If the Key has a secret subkey.
- */
- this.hasSecret= function (){
- return this.get('hasSecret', true);
- };
+ /**
+ * Property indicating if the Key possesses a private/secret part. If
+ * this information is not yet cached, it returns an
+ * {@link GPGME_Error} with code 'KEY_NO_INIT'. Running
+ * {@link refreshKey} may help in this case.
+ * @returns {Boolean} If the Key has a secret subkey.
+ */
+ this.hasSecret= function (){
+ return this.get('hasSecret', true);
+ };
- /**
- * @param {Object} data Bulk set the data for this key, with an Object sent
- * by gpgme-json.
- * @returns {GPGME_Key|GPGME_Error} Itself after values have been set, an
- * error if something went wrong
- * @private
- */
- this.setKeyData = function (data){
- if (typeof(data) !== 'object') {
- return gpgme_error('KEY_INVALID');
- }
- if (!data.fingerprint || data.fingerprint !== _data.fingerprint){
- return gpgme_error('KEY_INVALID');
- }
- let keys = Object.keys(data);
- for (let i=0; i< keys.length; i++){
- if (!validKeyProperties.hasOwnProperty(keys[i])){
- return gpgme_error('KEY_INVALID');
- }
- //running the defined validation function
- if (validKeyProperties[keys[i]](data[keys[i]]) !== true ){
- return gpgme_error('KEY_INVALID');
- }
- switch (keys[i]){
- case 'subkeys':
- _data.subkeys = [];
- for (let i=0; i< data.subkeys.length; i++) {
- _data.subkeys.push(
- new GPGME_Subkey(data.subkeys[i]));
+ /**
+ * @param {Object} data Bulk set the data for this key, with an Object
+ * sent by gpgme-json.
+ * @returns {GPGME_Key|GPGME_Error} Itself after values have been set,
+ * an error if something went wrong.
+ * @private
+ */
+ this.setKeyData = function (data){
+ if (typeof(data) !== 'object') {
+ return gpgme_error('KEY_INVALID');
+ }
+ if (!data.fingerprint || data.fingerprint !== _data.fingerprint){
+ return gpgme_error('KEY_INVALID');
+ }
+ let keys = Object.keys(data);
+ for (let i=0; i< keys.length; i++){
+ if (!validKeyProperties.hasOwnProperty(keys[i])){
+ return gpgme_error('KEY_INVALID');
}
- break;
- case 'userids':
- _data.userids = [];
- for (let i=0; i< data.userids.length; i++) {
- _data.userids.push(
- new GPGME_UserId(data.userids[i]));
+ //running the defined validation function
+ if (validKeyProperties[keys[i]](data[keys[i]]) !== true ){
+ return gpgme_error('KEY_INVALID');
}
- break;
- case 'last_update':
- _data[keys[i]] = new Date( data[keys[i]] * 1000 );
- break;
- default:
+ switch (keys[i]){
+ case 'subkeys':
+ _data.subkeys = [];
+ for (let i=0; i< data.subkeys.length; i++) {
+ _data.subkeys.push(
+ new GPGME_Subkey(data.subkeys[i]));
+ }
+ break;
+ case 'userids':
+ _data.userids = [];
+ for (let i=0; i< data.userids.length; i++) {
+ _data.userids.push(
+ new GPGME_UserId(data.userids[i]));
+ }
+ break;
+ case 'last_update':
+ _data[keys[i]] = new Date( data[keys[i]] * 1000 );
+ break;
+ default:
_data[keys[i]] = data[keys[i]];
- }
- }
- return this;
- };
-
- /**
- * Query any property of the Key listed in {@link validKeyProperties}
- * @param {String} property property to be retreived
- * @returns {*|Promise<*>} the value (Boolean, String, Array, Object).
- * If 'cached' is false, the value will be resolved as a Promise.
- */
- this.get = function(property) {
- if (this.isAsync === true) {
- let me = this;
- return new Promise(function(resolve, reject) {
- if (property === 'armored'){
- resolve(me.getArmor());
- } else if (property === 'hasSecret'){
- resolve(me.getHasSecret());
- } else if (validKeyProperties.hasOwnProperty(property)){
- let msg = createMessage('keylist');
- msg.setParameter('keys', _data.fingerprint);
- msg.post().then(function(result){
- if (result.keys && result.keys.length === 1 &&
- result.keys[0].hasOwnProperty(property)){
- resolve(result.keys[0][property]);
- } else {
- reject(gpgme_error('CONN_UNEXPECTED_ANSWER'));
- }
- }, function(error){
- reject(gpgme_error(error));
- });
- } else {
- reject(gpgme_error('PARAM_WRONG'));
}
- });
- } else {
- if (!validKeyProperties.hasOwnProperty(property)){
- return gpgme_error('PARAM_WRONG');
}
- if (!_data.hasOwnProperty(property)){
- return gpgme_error('KEY_NO_INIT');
+ return this;
+ };
+
+ /**
+ * Query any property of the Key listed in {@link validKeyProperties}
+ * @param {String} property property to be retreived
+ * @returns {*|Promise<*>} the value (Boolean, String, Array, Object).
+ * If 'cached' is false, the value will be resolved as a Promise.
+ */
+ this.get = function(property) {
+ if (this.isAsync === true) {
+ let me = this;
+ return new Promise(function(resolve, reject) {
+ if (property === 'armored'){
+ resolve(me.getArmor());
+ } else if (property === 'hasSecret'){
+ resolve(me.getHasSecret());
+ } else if (validKeyProperties.hasOwnProperty(property)){
+ let msg = createMessage('keylist');
+ msg.setParameter('keys', _data.fingerprint);
+ msg.post().then(function(result){
+ if (result.keys && result.keys.length === 1 &&
+ result.keys[0].hasOwnProperty(property)){
+ resolve(result.keys[0][property]);
+ } else {
+ reject(gpgme_error('CONN_UNEXPECTED_ANSWER'));
+ }
+ }, function(error){
+ reject(gpgme_error(error));
+ });
+ } else {
+ reject(gpgme_error('PARAM_WRONG'));
+ }
+ });
} else {
+ if (!validKeyProperties.hasOwnProperty(property)){
+ return gpgme_error('PARAM_WRONG');
+ }
+ if (!_data.hasOwnProperty(property)){
+ return gpgme_error('KEY_NO_INIT');
+ } else {
return (_data[property]);
+ }
}
- }
- };
+ };
- /**
- * Reloads the Key information from gnupg. This is only useful if you use
- * the GPGME_Keys cached. Note that this is a performance hungry operation.
- * If you desire more than a few refreshs, it may be advisable to run
- * {@link Keyring.getKeys} instead.
- * @returns {Promise<GPGME_Key|GPGME_Error>}
- * @async
- */
- this.refreshKey = function() {
- let me = this;
- return new Promise(function(resolve, reject) {
- if (!_data.fingerprint){
- reject(gpgme_error('KEY_INVALID'));
- }
- let msg = createMessage('keylist');
- msg.setParameter('sigs', true);
- msg.setParameter('keys', _data.fingerprint);
- msg.post().then(function(result){
- if (result.keys.length === 1){
- me.setKeyData(result.keys[0]);
- me.getHasSecret().then(function(){
- me.getArmor().then(function(){
- resolve(me);
+ /**
+ * Reloads the Key information from gnupg. This is only useful if you
+ * use the GPGME_Keys cached. Note that this is a performance hungry
+ * operation. If you desire more than a few refreshs, it may be
+ * advisable to run {@link Keyring.getKeys} instead.
+ * @returns {Promise<GPGME_Key|GPGME_Error>}
+ * @async
+ */
+ this.refreshKey = function() {
+ let me = this;
+ return new Promise(function(resolve, reject) {
+ if (!_data.fingerprint){
+ reject(gpgme_error('KEY_INVALID'));
+ }
+ let msg = createMessage('keylist');
+ msg.setParameter('sigs', true);
+ msg.setParameter('keys', _data.fingerprint);
+ msg.post().then(function(result){
+ if (result.keys.length === 1){
+ me.setKeyData(result.keys[0]);
+ me.getHasSecret().then(function(){
+ me.getArmor().then(function(){
+ resolve(me);
+ }, function(error){
+ reject(error);
+ });
}, function(error){
reject(error);
});
- }, function(error){
- reject(error);
- });
- } else {
- reject(gpgme_error('KEY_NOKEY'));
- }
- }, function (error) {
- reject(gpgme_error('GNUPG_ERROR'), error);
+ } else {
+ reject(gpgme_error('KEY_NOKEY'));
+ }
+ }, function (error) {
+ reject(gpgme_error('GNUPG_ERROR'), error);
+ });
});
- });
- };
+ };
- /**
- * Query the armored block of the Key directly from gnupg. Please note that
- * this will not get you any export of the secret/private parts of a Key
- * @returns {Promise<String|GPGME_Error>}
- * @async
- */
- this.getArmor = function(){
- return new Promise(function(resolve, reject) {
- if (!_data.fingerprint){
- reject(gpgme_error('KEY_INVALID'));
- }
- let msg = createMessage('export');
- msg.setParameter('armor', true);
- msg.setParameter('keys', _data.fingerprint);
- msg.post().then(function(result){
- _data.armored = result.data;
- resolve(result.data);
- }, function(error){
- reject(error);
+ /**
+ * Query the armored block of the Key directly from gnupg. Please note
+ * that this will not get you any export of the secret/private parts of
+ * a Key
+ * @returns {Promise<String|GPGME_Error>}
+ * @async
+ */
+ this.getArmor = function(){
+ return new Promise(function(resolve, reject) {
+ if (!_data.fingerprint){
+ reject(gpgme_error('KEY_INVALID'));
+ }
+ let msg = createMessage('export');
+ msg.setParameter('armor', true);
+ msg.setParameter('keys', _data.fingerprint);
+ msg.post().then(function(result){
+ _data.armored = result.data;
+ resolve(result.data);
+ }, function(error){
+ reject(error);
+ });
});
- });
- };
+ };
- /**
- * Find out if the Key includes a secret part. Note that this is a rather
- * nonperformant operation, as it needs to query gnupg twice. If you want
- * this inforrmation about more than a few Keys, it may be advisable to run
- * {@link Keyring.getKeys} instead.
- * @returns {Promise<Boolean|GPGME_Error>} True if a secret/private Key is
- * available in the gnupg Keyring
- * @async
- */
- this.getHasSecret = function (){
- return new Promise(function(resolve, reject) {
- if (!_data.fingerprint){
- reject(gpgme_error('KEY_INVALID'));
- }
- let msg = createMessage('keylist');
- msg.setParameter('keys', _data.fingerprint);
- msg.setParameter('secret', true);
- msg.post().then(function(result){
- _data.hasSecret = null;
- if (
- result.keys &&
- result.keys.length === 1 &&
- result.keys[0].secret === true
- ) {
- _data.hasSecret = true;
- resolve(true);
- } else {
- _data.hasSecret = false;
- resolve(false);
+ /**
+ * Find out if the Key includes a secret part. Note that this is a
+ * rather nonperformant operation, as it needs to query gnupg twice.
+ * If you want this inforrmation about more than a few Keys, it may be
+ * advisable to run {@link Keyring.getKeys} instead.
+ * @returns {Promise<Boolean|GPGME_Error>} True if a secret/private Key
+ * is available in the gnupg Keyring
+ * @async
+ */
+ this.getHasSecret = function (){
+ return new Promise(function(resolve, reject) {
+ if (!_data.fingerprint){
+ reject(gpgme_error('KEY_INVALID'));
}
- }, function(error){
- reject(error);
+ let msg = createMessage('keylist');
+ msg.setParameter('keys', _data.fingerprint);
+ msg.setParameter('secret', true);
+ msg.post().then(function(result){
+ _data.hasSecret = null;
+ if (
+ result.keys &&
+ result.keys.length === 1 &&
+ result.keys[0].secret === true
+ ) {
+ _data.hasSecret = true;
+ resolve(true);
+ } else {
+ _data.hasSecret = false;
+ resolve(false);
+ }
+ }, function(error){
+ reject(error);
+ });
});
- });
- };
+ };
- /**
- * Deletes the (public) Key from the GPG Keyring. Note that a deletion of a
- * secret key is not supported by the native backend.
- * @returns {Promise<Boolean|GPGME_Error>} Success if key was deleted,
- * rejects with a GPG error otherwise.
- */
- this.delete= function (){
- return new Promise(function(resolve, reject){
- if (!_data.fingerprint){
- reject(gpgme_error('KEY_INVALID'));
- }
- let msg = createMessage('delete');
- msg.setParameter('key', _data.fingerprint);
- msg.post().then(function(result){
- resolve(result.success);
- }, function(error){
- reject(error);
+ /**
+ * Deletes the (public) Key from the GPG Keyring. Note that a deletion
+ * of a secret key is not supported by the native backend.
+ * @returns {Promise<Boolean|GPGME_Error>} Success if key was deleted,
+ * rejects with a GPG error otherwise.
+ */
+ this.delete= function (){
+ return new Promise(function(resolve, reject){
+ if (!_data.fingerprint){
+ reject(gpgme_error('KEY_INVALID'));
+ }
+ let msg = createMessage('delete');
+ msg.setParameter('key', _data.fingerprint);
+ msg.post().then(function(result){
+ resolve(result.success);
+ }, function(error){
+ reject(error);
+ });
});
- });
- };
+ };
}
/**
@@ -320,42 +322,39 @@ class GPGME_Subkey {
let _data = {};
let keys = Object.keys(data);
- /**
- * Validates a subkey property against {@link validSubKeyProperties} and
- * sets it if validation is successful
- * @param {String} property
- * @param {*} value
- * @param private
- */
- const setProperty = function (property, value){
- if (validSubKeyProperties.hasOwnProperty(property)){
- if (validSubKeyProperties[property](value) === true) {
- if (property === 'timestamp' || property === 'expires'){
- _data[property] = new Date(value * 1000);
- } else {
- _data[property] = value;
+ /**
+ * Validates a subkey property against {@link validSubKeyProperties} and
+ * sets it if validation is successful
+ * @param {String} property
+ * @param {*} value
+ * @param private
+ */
+ const setProperty = function (property, value){
+ if (validSubKeyProperties.hasOwnProperty(property)){
+ if (validSubKeyProperties[property](value) === true) {
+ if (property === 'timestamp' || property === 'expires'){
+ _data[property] = new Date(value * 1000);
+ } else {
+ _data[property] = value;
+ }
}
}
+ };
+ for (let i=0; i< keys.length; i++) {
+ setProperty(keys[i], data[keys[i]]);
}
- };
- for (let i=0; i< keys.length; i++) {
- setProperty(keys[i], data[keys[i]]);
- }
-
-
-
- /**
- * Fetches any information about this subkey
- * @param {String} property Information to request
- * @returns {String | Number | Date}
- */
- this.get = function(property) {
- if (_data.hasOwnProperty(property)){
- return (_data[property]);
- }
- };
-}
+ /**
+ * Fetches any information about this subkey
+ * @param {String} property Information to request
+ * @returns {String | Number | Date}
+ */
+ this.get = function(property) {
+ if (_data.hasOwnProperty(property)){
+ return (_data[property]);
+ }
+ };
+ }
}
/**
@@ -388,28 +387,28 @@ class GPGME_UserId {
setProperty(keys[i], data[keys[i]]);
}
- /**
- * Validates a subkey property against {@link validUserIdProperties} and
- * sets it if validation is successful
- * @param {String} property
- * @param {*} value
- * @param private
- */
+ /**
+ * Validates a subkey property against {@link validUserIdProperties} and
+ * sets it if validation is successful
+ * @param {String} property
+ * @param {*} value
+ * @param private
+ */
- /**
- * Fetches information about the user
- * @param {String} property Information to request
- * @returns {String | Number}
- */
- this.get = function (property) {
- if (_data.hasOwnProperty(property)){
- return (_data[property]);
- }
- };
+ /**
+ * Fetches information about the user
+ * @param {String} property Information to request
+ * @returns {String | Number}
+ */
+ this.get = function (property) {
+ if (_data.hasOwnProperty(property)){
+ return (_data[property]);
+ }
+ };
+ }
}
-}
/**
* Validation definition for userIds. Each valid userId property is represented
* as a key- Value pair, with their value being a validation function to check