js: separate gpgme answer by type of data
-- * src/Connection.js; src/permittedOperations.js: To avoid further encoding problems, data sent by gpgme is now sorted as either 'payload' or 'info'. Payload data may come in any encoding, and here the 'expected' and 'format' options are used, 'info' data may contain text created by gnupg which may need re-encoding, but this should not be affected by 'expected' and 'format'
This commit is contained in:
parent
1d00fb987b
commit
a9863717b1
@ -243,7 +243,7 @@ class Answer{
|
|||||||
for (let i= 0; i < messageKeys.length; i++){
|
for (let i= 0; i < messageKeys.length; i++){
|
||||||
let key = messageKeys[i];
|
let key = messageKeys[i];
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'type':
|
case 'type': {
|
||||||
if (_decodedResponse.type === 'error'){
|
if (_decodedResponse.type === 'error'){
|
||||||
return (gpgme_error('GNUPG_ERROR',
|
return (gpgme_error('GNUPG_ERROR',
|
||||||
decode(_decodedResponse.msg)));
|
decode(_decodedResponse.msg)));
|
||||||
@ -251,39 +251,60 @@ class Answer{
|
|||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'base64':
|
}
|
||||||
|
case 'base64': {
|
||||||
break;
|
break;
|
||||||
case 'msg':
|
}
|
||||||
|
case 'msg': {
|
||||||
if (_decodedResponse.type === 'error'){
|
if (_decodedResponse.type === 'error'){
|
||||||
return (gpgme_error('GNUPG_ERROR', _decodedResponse.msg));
|
return (gpgme_error('GNUPG_ERROR', _decodedResponse.msg));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
if (!poa.data.hasOwnProperty(key)){
|
default: {
|
||||||
|
let answerType = null;
|
||||||
|
if (poa.payload && poa.payload.hasOwnProperty(key)){
|
||||||
|
answerType = 'p';
|
||||||
|
} else if (poa.info && poa.info.hasOwnProperty(key)){
|
||||||
|
answerType = 'i';
|
||||||
|
}
|
||||||
|
if (answerType !== 'p' && answerType !== 'i'){
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
if ( typeof (_decodedResponse[key]) !== poa.data[key] ){
|
|
||||||
|
if (answerType === 'i') {
|
||||||
|
if ( typeof (_decodedResponse[key]) !== poa.info[key] ){
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
|
_response[key] = decode(_decodedResponse[key]);
|
||||||
|
|
||||||
|
} else if (answerType === 'p') {
|
||||||
if (_decodedResponse.base64 === true
|
if (_decodedResponse.base64 === true
|
||||||
&& poa.data[key] === 'string'
|
&& poa.payload[key] === 'string'
|
||||||
) {
|
) {
|
||||||
if (this.expected === 'uint8'){
|
if (this.expected === 'uint8'){
|
||||||
_response[key] = atobArray(_decodedResponse[key]);
|
_response[key] = atobArray(_decodedResponse[key]);
|
||||||
_response.format = 'uint8';
|
_response.format = 'uint8';
|
||||||
|
|
||||||
} else if (this.expected === 'base64'){
|
} else if (this.expected === 'base64'){
|
||||||
_response[key] = _decodedResponse[key];
|
_response[key] = _decodedResponse[key];
|
||||||
_response.format = 'base64';
|
_response.format = 'base64';
|
||||||
} else {
|
|
||||||
|
} else { // no 'expected'
|
||||||
_response[key] = Utf8ArrayToStr(
|
_response[key] = Utf8ArrayToStr(
|
||||||
atobArray(_decodedResponse[key]));
|
atobArray(_decodedResponse[key]));
|
||||||
_response.format = 'string';
|
_response.format = 'string';
|
||||||
}
|
}
|
||||||
|
} else if (poa.payload[key] === 'string') {
|
||||||
|
_response[key] = _decodedResponse[key];
|
||||||
} else {
|
} else {
|
||||||
_response[key] = decode(_decodedResponse[key]);
|
// fallthrough, should not be reached
|
||||||
|
// (payload is always string)
|
||||||
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
} }
|
||||||
}
|
}
|
||||||
return _response;
|
return _response;
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,12 @@
|
|||||||
* @property {Object} answer The definition on what to expect as answer, if the
|
* @property {Object} answer The definition on what to expect as answer, if the
|
||||||
* answer is not an error
|
* answer is not an error
|
||||||
* @property {Array<String>} answer.type the type(s) as reported by gpgme-json.
|
* @property {Array<String>} answer.type the type(s) as reported by gpgme-json.
|
||||||
* @property {Object} answer.data key-value combinations of expected properties
|
* @property {Object} answer.payload key-value combinations of expected
|
||||||
* of an answer and their type ('boolean', 'string', object)
|
* properties of an answer and their type ('boolean', 'string', object), which
|
||||||
|
* may need further decoding from base64
|
||||||
|
* @property {Object} answer.info key-value combinations of expected
|
||||||
|
* properties of an answer and their type ('boolean', 'string', object), which
|
||||||
|
* are meant to be data directly sent by gpgme (i.e. user ids)
|
||||||
@const
|
@const
|
||||||
*/
|
*/
|
||||||
export const permittedOperations = {
|
export const permittedOperations = {
|
||||||
@ -104,8 +108,10 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['ciphertext'],
|
type: ['ciphertext'],
|
||||||
data: {
|
payload: {
|
||||||
'data': 'string',
|
'data': 'string'
|
||||||
|
},
|
||||||
|
info: {
|
||||||
'base64':'boolean'
|
'base64':'boolean'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,8 +135,10 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['plaintext'],
|
type: ['plaintext'],
|
||||||
data: {
|
payload: {
|
||||||
'data': 'string',
|
'data': 'string',
|
||||||
|
},
|
||||||
|
info: {
|
||||||
'base64': 'boolean',
|
'base64': 'boolean',
|
||||||
'mime': 'boolean',
|
'mime': 'boolean',
|
||||||
'info': 'object',
|
'info': 'object',
|
||||||
@ -171,11 +179,12 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['signature', 'ciphertext'],
|
type: ['signature', 'ciphertext'],
|
||||||
data: {
|
payload: {
|
||||||
'data': 'string',
|
'data': 'string',
|
||||||
|
},
|
||||||
|
info: {
|
||||||
'base64':'boolean'
|
'base64':'boolean'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -223,9 +232,9 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['keys'],
|
type: ['keys'],
|
||||||
data: {
|
info: {
|
||||||
|
'keys': 'object',
|
||||||
'base64': 'boolean',
|
'base64': 'boolean',
|
||||||
'keys': 'object'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -263,8 +272,10 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['keys'],
|
type: ['keys'],
|
||||||
data: {
|
payload: {
|
||||||
'data': 'string',
|
'data': 'string',
|
||||||
|
},
|
||||||
|
info: {
|
||||||
'base64': 'boolean',
|
'base64': 'boolean',
|
||||||
'sec-fprs': 'object'
|
'sec-fprs': 'object'
|
||||||
}
|
}
|
||||||
@ -288,7 +299,7 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: [],
|
type: [],
|
||||||
data: {
|
info: {
|
||||||
'result': 'object'
|
'result': 'object'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,7 +319,7 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
data: {
|
info: {
|
||||||
'success': 'boolean'
|
'success': 'boolean'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +330,7 @@ export const permittedOperations = {
|
|||||||
optional: {},
|
optional: {},
|
||||||
answer: {
|
answer: {
|
||||||
type: [''],
|
type: [''],
|
||||||
data: {
|
info: {
|
||||||
'gpgme': 'string',
|
'gpgme': 'string',
|
||||||
'info': 'object'
|
'info': 'object'
|
||||||
}
|
}
|
||||||
@ -346,7 +357,7 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: [''],
|
type: [''],
|
||||||
data: { 'fingerprint': 'string' }
|
info: { 'fingerprint': 'string' }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -370,10 +381,12 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: ['plaintext'],
|
type: ['plaintext'],
|
||||||
data:{
|
payload:{
|
||||||
data: 'string',
|
'data': 'string'
|
||||||
base64:'boolean',
|
},
|
||||||
info: 'object'
|
info: {
|
||||||
|
'base64':'boolean',
|
||||||
|
'info': 'object'
|
||||||
// info.file_name: Optional string of the plaintext file name.
|
// info.file_name: Optional string of the plaintext file name.
|
||||||
// info.is_mime: Boolean if the messages claims it is MIME.
|
// info.is_mime: Boolean if the messages claims it is MIME.
|
||||||
// info.signatures: Array of signatures
|
// info.signatures: Array of signatures
|
||||||
@ -395,15 +408,9 @@ export const permittedOperations = {
|
|||||||
optional: {},
|
optional: {},
|
||||||
answer: {
|
answer: {
|
||||||
type: [],
|
type: [],
|
||||||
data: {
|
info: {
|
||||||
option: 'object'
|
'option': 'object'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TBD handling of secrets
|
|
||||||
* TBD key modification?
|
|
||||||
*/
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user