js: don't allow message operation changes
-- Once an operation is changed, their set of allowed/required parameters will change. So we shouldn't set/change the operation later.
This commit is contained in:
parent
d62f66b1fb
commit
727340b295
@ -49,8 +49,7 @@ export class GPGME_Keyring {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
getKeys(pattern, include_secret){
|
getKeys(pattern, include_secret){
|
||||||
let msg = new GPGME_Message;
|
let msg = new GPGME_Message('listkeys');
|
||||||
msg.operation = 'listkeys';
|
|
||||||
if (pattern && typeof(pattern) === 'string'){
|
if (pattern && typeof(pattern) === 'string'){
|
||||||
msg.setParameter('pattern', pattern);
|
msg.setParameter('pattern', pattern);
|
||||||
}
|
}
|
||||||
|
@ -23,28 +23,7 @@ export class GPGME_Message {
|
|||||||
//TODO getter
|
//TODO getter
|
||||||
|
|
||||||
constructor(operation){
|
constructor(operation){
|
||||||
if (operation){
|
setOperation(this, operation);
|
||||||
this.operation(operation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines the operation this message will have
|
|
||||||
* @param {String} operation Must be defined in permittedOperations
|
|
||||||
* TODO: move to constructor?
|
|
||||||
*/
|
|
||||||
set operation (operation){
|
|
||||||
if (!operation || typeof(operation) !== 'string'){
|
|
||||||
return new GPGMEJS_Error('WRONGPARAM');
|
|
||||||
}
|
|
||||||
if (operation in permittedOperations){
|
|
||||||
if (!this._msg){
|
|
||||||
this._msg = {};
|
|
||||||
}
|
|
||||||
this._msg.op = operation;
|
|
||||||
} else {
|
|
||||||
return new GPGMEJS_Error('WRONG_OP');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get operation(){
|
get operation(){
|
||||||
@ -111,3 +90,22 @@ export class GPGME_Message {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the operation this message will have
|
||||||
|
* @param {String} operation Must be defined in permittedOperations
|
||||||
|
* TODO: move to constructor?
|
||||||
|
*/
|
||||||
|
function setOperation (scope, operation){
|
||||||
|
if (!operation || typeof(operation) !== 'string'){
|
||||||
|
return new GPGMEJS_Error('WRONGTYPE');
|
||||||
|
}
|
||||||
|
if (permittedOperations.hasOwnProperty(operation)){
|
||||||
|
if (!scope._msg){
|
||||||
|
scope._msg = {};
|
||||||
|
}
|
||||||
|
scope._msg.op = operation;
|
||||||
|
} else {
|
||||||
|
return new GPGMEJS_Error('WRONG_OP');
|
||||||
|
}
|
||||||
|
}
|
@ -76,8 +76,7 @@ export class GpgME {
|
|||||||
*/
|
*/
|
||||||
encrypt (data, publicKeys, wildcard=false){
|
encrypt (data, publicKeys, wildcard=false){
|
||||||
|
|
||||||
let msg = new GPGME_Message;
|
let msg = new GPGME_Message('encrypt');
|
||||||
msg.operation = 'encrypt';
|
|
||||||
|
|
||||||
// TODO temporary
|
// TODO temporary
|
||||||
msg.setParameter('armor', true);
|
msg.setParameter('armor', true);
|
||||||
@ -108,8 +107,7 @@ export class GpgME {
|
|||||||
if (data === undefined){
|
if (data === undefined){
|
||||||
return Promise.reject(new GPGMEJS_Error ('EMPTY_MSG'));
|
return Promise.reject(new GPGMEJS_Error ('EMPTY_MSG'));
|
||||||
}
|
}
|
||||||
let msg = new GPGME_Message;
|
let msg = new GPGME_Message('decrypt');
|
||||||
msg.operation = 'decrypt';
|
|
||||||
putData(msg, data);
|
putData(msg, data);
|
||||||
return this._connection.post(msg);
|
return this._connection.post(msg);
|
||||||
|
|
||||||
@ -117,8 +115,7 @@ export class GpgME {
|
|||||||
|
|
||||||
deleteKey(key, delete_secret = false, no_confirm = false){
|
deleteKey(key, delete_secret = false, no_confirm = false){
|
||||||
return Promise.reject(new GPGMEJS_Error ('NOT_YET_IMPLEMENTED'));
|
return Promise.reject(new GPGMEJS_Error ('NOT_YET_IMPLEMENTED'));
|
||||||
let msg = new GPGME_Message;
|
let msg = new GPGME_Message('deletekey');
|
||||||
msg.operation = 'deletekey';
|
|
||||||
let key_arr = toKeyIdArray(key);
|
let key_arr = toKeyIdArray(key);
|
||||||
if (key_arr.length !== 1){
|
if (key_arr.length !== 1){
|
||||||
throw('TODO');
|
throw('TODO');
|
||||||
|
Loading…
Reference in New Issue
Block a user