js: add and apply eslint rules
-- * mainly spacing, see .eslintrc.json for details
This commit is contained in:
parent
1954d27be8
commit
dd32daad0b
@ -27,6 +27,23 @@
|
|||||||
"no-var": [
|
"no-var": [
|
||||||
"warn"
|
"warn"
|
||||||
],
|
],
|
||||||
"max-len": 1
|
"max-len": 1,
|
||||||
|
"default-case": 2,
|
||||||
|
"no-invalid-this": 2,
|
||||||
|
"no-lone-blocks": 1,
|
||||||
|
"no-self-compare": 2,
|
||||||
|
"radix": 2,
|
||||||
|
"no-use-before-define": ["error", {
|
||||||
|
"functions": false,
|
||||||
|
"classes": false,
|
||||||
|
"variables": true
|
||||||
|
}],
|
||||||
|
"no-useless-constructor": 1,
|
||||||
|
"space-before-function-paren": ["error", "always"],
|
||||||
|
"keyword-spacing": 2,
|
||||||
|
"spaced-comment": 1,
|
||||||
|
"space-unary-ops": 2,
|
||||||
|
"object-curly-spacing": ["error", "always"],
|
||||||
|
"array-bracket-spacing": ["error", "never"]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,16 +31,16 @@ describe('Key importing', function () {
|
|||||||
const changedKey = ImportablePublicKey.keyChangedUserId;
|
const changedKey = ImportablePublicKey.keyChangedUserId;
|
||||||
|
|
||||||
let context = null;
|
let context = null;
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
context.Keyring.getKeys(fpr).then(
|
context.Keyring.getKeys(fpr).then(
|
||||||
function(result){
|
function (result){
|
||||||
if (result.length === 1) {
|
if (result.length === 1) {
|
||||||
result[0].delete().then(function(){
|
result[0].delete().then(function (){
|
||||||
done();
|
done();
|
||||||
},function(){
|
},function (){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -50,14 +50,14 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function(done){
|
afterEach(function (done){
|
||||||
// delete the test key if still present
|
// delete the test key if still present
|
||||||
context.Keyring.getKeys(fpr).then(
|
context.Keyring.getKeys(fpr).then(
|
||||||
function(result){
|
function (result){
|
||||||
if (result.length === 1) {
|
if (result.length === 1) {
|
||||||
result[0].delete().then(function(){
|
result[0].delete().then(function (){
|
||||||
done();
|
done();
|
||||||
},function(){
|
},function (){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -67,10 +67,10 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Importing Key', function (done) {
|
it('Importing Key', function (done) {
|
||||||
context.Keyring.getKeys(fpr).then(function(result){
|
context.Keyring.getKeys(fpr).then(function (result){
|
||||||
expect(result).to.be.an('array');
|
expect(result).to.be.an('array');
|
||||||
expect(result.length).to.equal(0);
|
expect(result.length).to.equal(0);
|
||||||
context.Keyring.importKey(pubKey).then(function(result){
|
context.Keyring.importKey(pubKey).then(function (result){
|
||||||
expect(result.Keys).to.be.an('array');
|
expect(result.Keys).to.be.an('array');
|
||||||
expect(result.Keys[0]).to.not.be.undefined;
|
expect(result.Keys[0]).to.not.be.undefined;
|
||||||
expect(result.Keys[0].key).to.be.an('object');
|
expect(result.Keys[0].key).to.be.an('object');
|
||||||
@ -83,12 +83,12 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Updating Key', function(done){
|
it('Updating Key', function (done){
|
||||||
context.Keyring.importKey(pubKey)
|
context.Keyring.importKey(pubKey)
|
||||||
.then(function(result){
|
.then(function (result){
|
||||||
expect(result.Keys[0].key).to.not.be.undefined;
|
expect(result.Keys[0].key).to.not.be.undefined;
|
||||||
expect(result.Keys[0].status).to.equal('newkey');
|
expect(result.Keys[0].status).to.equal('newkey');
|
||||||
context.Keyring.importKey(changedKey).then(function(res){
|
context.Keyring.importKey(changedKey).then(function (res){
|
||||||
expect(res.Keys[0].key).to.be.an('object');
|
expect(res.Keys[0].key).to.be.an('object');
|
||||||
expect(res.Keys[0].key.fingerprint).to.equal(fpr);
|
expect(res.Keys[0].key.fingerprint).to.equal(fpr);
|
||||||
expect(res.Keys[0].status).to.equal('change');
|
expect(res.Keys[0].status).to.equal('change');
|
||||||
@ -101,24 +101,24 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deleting Key', function(done) {
|
it('Deleting Key', function (done) {
|
||||||
context.Keyring.importKey(pubKey).then(function(result){
|
context.Keyring.importKey(pubKey).then(function (result){
|
||||||
expect(result.Keys[0].key).to.be.an('object');
|
expect(result.Keys[0].key).to.be.an('object');
|
||||||
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
|
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
|
||||||
result.Keys[0].key.delete().then(function(result){
|
result.Keys[0].key.delete().then(function (result){
|
||||||
expect(result).to.be.true;
|
expect(result).to.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Import result feedback', function(done){
|
it('Import result feedback', function (done){
|
||||||
context.Keyring.importKey(pubKey, true).then(function(result){
|
context.Keyring.importKey(pubKey, true).then(function (result){
|
||||||
expect(result).to.be.an('object');
|
expect(result).to.be.an('object');
|
||||||
expect(result.Keys[0]).to.be.an('object');
|
expect(result.Keys[0]).to.be.an('object');
|
||||||
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
|
expect(result.Keys[0].key.fingerprint).to.equal(fpr);
|
||||||
expect(result.Keys[0].status).to.equal('newkey');
|
expect(result.Keys[0].status).to.equal('newkey');
|
||||||
result.Keys[0].key.getArmor().then(function(armor){
|
result.Keys[0].key.getArmor().then(function (armor){
|
||||||
expect(armor).to.be.a('string');
|
expect(armor).to.be.a('string');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -126,8 +126,8 @@ describe('Key importing', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exporting armored Key with getKeysArmored', function (done) {
|
it('exporting armored Key with getKeysArmored', function (done) {
|
||||||
context.Keyring.importKey(pubKey).then(function(){
|
context.Keyring.importKey(pubKey).then(function (){
|
||||||
context.Keyring.getKeysArmored(fpr).then(function(result){
|
context.Keyring.getKeysArmored(fpr).then(function (result){
|
||||||
expect(result).to.be.an('object');
|
expect(result).to.be.an('object');
|
||||||
expect(result.armored).to.be.a('string');
|
expect(result.armored).to.be.a('string');
|
||||||
expect(result.secret_fprs).to.be.undefined;
|
expect(result.secret_fprs).to.be.undefined;
|
||||||
@ -138,7 +138,7 @@ describe('Key importing', function () {
|
|||||||
|
|
||||||
it('Exporting Key (including secret fingerprints)', function (done) {
|
it('Exporting Key (including secret fingerprints)', function (done) {
|
||||||
const key_secret = inputvalues.encrypt.good.fingerprint;
|
const key_secret = inputvalues.encrypt.good.fingerprint;
|
||||||
context.Keyring.getKeysArmored(key_secret, true).then(function(result){
|
context.Keyring.getKeysArmored(key_secret, true).then(function (result){
|
||||||
expect(result).to.be.an('object');
|
expect(result).to.be.an('object');
|
||||||
expect(result.armored).to.be.a('string');
|
expect(result.armored).to.be.a('string');
|
||||||
expect(result.secret_fprs).to.be.an('array');
|
expect(result.secret_fprs).to.be.an('array');
|
||||||
|
@ -26,17 +26,17 @@
|
|||||||
|
|
||||||
describe('Key information', function () {
|
describe('Key information', function () {
|
||||||
let context = null;
|
let context = null;
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('A fingerprint is consistently returned upper case hex', function(done){
|
it('A fingerprint is consistently returned upper case hex', function (done){
|
||||||
const mixedCase = inputvalues.encrypt.good.fingerprint_mixedcase;
|
const mixedCase = inputvalues.encrypt.good.fingerprint_mixedcase;
|
||||||
context.Keyring.getKeys(mixedCase).then(function(result){
|
context.Keyring.getKeys(mixedCase).then(function (result){
|
||||||
expect(result).to.be.an('array');
|
expect(result).to.be.an('array');
|
||||||
expect(result.length).to.equal(1);
|
expect(result.length).to.equal(1);
|
||||||
expect(result[0].fingerprint).to.equal(mixedCase.toUpperCase());
|
expect(result[0].fingerprint).to.equal(mixedCase.toUpperCase());
|
||||||
@ -44,9 +44,9 @@ describe('Key information', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('A userId keeps their encoding', function(done){
|
it('A userId keeps their encoding', function (done){
|
||||||
context.Keyring.importKey(inputvalues.publicKeyNonAscii.key, true)
|
context.Keyring.importKey(inputvalues.publicKeyNonAscii.key, true)
|
||||||
.then(function(result){
|
.then(function (result){
|
||||||
expect(result.Keys[0]).to.be.an('object');
|
expect(result.Keys[0]).to.be.an('object');
|
||||||
const user = result.Keys[0].key.get('userids')[0];
|
const user = result.Keys[0].key.get('userids')[0];
|
||||||
expect(user.get('name')).to.equal(
|
expect(user.get('name')).to.equal(
|
||||||
|
@ -28,9 +28,9 @@ describe('Decryption', function () {
|
|||||||
let context = null;
|
let context = null;
|
||||||
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
|
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -39,8 +39,8 @@ describe('Decryption', function () {
|
|||||||
it('Decryption of random string fails', function (done) {
|
it('Decryption of random string fails', function (done) {
|
||||||
let data = bigString(20 * 1024);
|
let data = bigString(20 * 1024);
|
||||||
context.decrypt(data).then(
|
context.decrypt(data).then(
|
||||||
function(){},
|
function (){},
|
||||||
function(error){
|
function (error){
|
||||||
expect(error).to.be.an('error');
|
expect(error).to.be.an('error');
|
||||||
expect(error.code).to.equal('GNUPG_ERROR');
|
expect(error.code).to.equal('GNUPG_ERROR');
|
||||||
done();
|
done();
|
||||||
@ -49,10 +49,10 @@ describe('Decryption', function () {
|
|||||||
|
|
||||||
it('Decryption of slightly corrupted message fails', function (done) {
|
it('Decryption of slightly corrupted message fails', function (done) {
|
||||||
const data = bigString(10000);
|
const data = bigString(10000);
|
||||||
context.encrypt(data, good_fpr).then(function(enc){
|
context.encrypt(data, good_fpr).then(function (enc){
|
||||||
context.decrypt(sabotageMsg(enc.data)).then(
|
context.decrypt(sabotageMsg(enc.data)).then(
|
||||||
function(){},
|
function (){},
|
||||||
function(error){
|
function (error){
|
||||||
expect(error).to.be.an('error');
|
expect(error).to.be.an('error');
|
||||||
expect(error.code).to.equal('GNUPG_ERROR');
|
expect(error.code).to.equal('GNUPG_ERROR');
|
||||||
done();
|
done();
|
||||||
|
@ -24,13 +24,13 @@
|
|||||||
/* global describe, it, expect, before, Gpgmejs */
|
/* global describe, it, expect, before, Gpgmejs */
|
||||||
/* global inputvalues, encryptedData, bigString, bigBoringString */
|
/* global inputvalues, encryptedData, bigString, bigBoringString */
|
||||||
|
|
||||||
describe('Encryption and Decryption', function () {
|
describe('Encryption and Decryption', function (){
|
||||||
let context = null;
|
let context = null;
|
||||||
let good_fpr = inputvalues.encrypt.good.fingerprint;
|
let good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
|
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
describe('Encryption', function () {
|
describe('Encryption', function () {
|
||||||
let context = null;
|
let context = null;
|
||||||
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -64,7 +64,7 @@ describe('Encryption', function () {
|
|||||||
const data = inputvalues.encrypt.good.data;
|
const data = inputvalues.encrypt.good.data;
|
||||||
context.encrypt(data,null).then(function (answer) {
|
context.encrypt(data,null).then(function (answer) {
|
||||||
expect(answer).to.be.undefined;
|
expect(answer).to.be.undefined;
|
||||||
}, function(error){
|
}, function (error){
|
||||||
expect(error).to.be.an('Error');
|
expect(error).to.be.an('Error');
|
||||||
expect(error.code).to.equal('MSG_INCOMPLETE');
|
expect(error.code).to.equal('MSG_INCOMPLETE');
|
||||||
done();
|
done();
|
||||||
@ -86,7 +86,7 @@ describe('Encryption', function () {
|
|||||||
const bad_fpr = inputvalues.encrypt.bad.fingerprint;
|
const bad_fpr = inputvalues.encrypt.bad.fingerprint;
|
||||||
context.encrypt(data, bad_fpr).then(function (answer) {
|
context.encrypt(data, bad_fpr).then(function (answer) {
|
||||||
expect(answer).to.be.undefined;
|
expect(answer).to.be.undefined;
|
||||||
}, function(error){
|
}, function (error){
|
||||||
expect(error).to.be.an('Error');
|
expect(error).to.be.an('Error');
|
||||||
expect(error.code).to.not.be.undefined;
|
expect(error.code).to.not.be.undefined;
|
||||||
expect(error.code).to.equal('GNUPG_ERROR');
|
expect(error.code).to.equal('GNUPG_ERROR');
|
||||||
@ -98,7 +98,7 @@ describe('Encryption', function () {
|
|||||||
const data = fixedLengthString(65);
|
const data = fixedLengthString(65);
|
||||||
context.encrypt(data, good_fpr).then(function (answer) {
|
context.encrypt(data, good_fpr).then(function (answer) {
|
||||||
expect(answer).to.be.undefined;
|
expect(answer).to.be.undefined;
|
||||||
}, function(error){
|
}, function (error){
|
||||||
expect(error).to.be.an.instanceof(Error);
|
expect(error).to.be.an.instanceof(Error);
|
||||||
// TODO: there is a 64 MB hard limit at least in chrome at:
|
// TODO: there is a 64 MB hard limit at least in chrome at:
|
||||||
// chromium//extensions/renderer/messaging_util.cc:
|
// chromium//extensions/renderer/messaging_util.cc:
|
||||||
|
@ -126,7 +126,7 @@ const inputvalues = {// eslint-disable-line no-unused-vars
|
|||||||
};
|
};
|
||||||
|
|
||||||
// (Pseudo-)Random String covering all of utf8.
|
// (Pseudo-)Random String covering all of utf8.
|
||||||
function bigString(length){// eslint-disable-line no-unused-vars
|
function bigString (length){// eslint-disable-line no-unused-vars
|
||||||
let arr = [];
|
let arr = [];
|
||||||
for (let i= 0; i < length; i++){
|
for (let i= 0; i < length; i++){
|
||||||
arr.push(String.fromCharCode(
|
arr.push(String.fromCharCode(
|
||||||
@ -136,7 +136,7 @@ function bigString(length){// eslint-disable-line no-unused-vars
|
|||||||
return arr.join('');
|
return arr.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function fixedLengthString(megabytes){// eslint-disable-line no-unused-vars
|
function fixedLengthString (megabytes){// eslint-disable-line no-unused-vars
|
||||||
let maxlength = 1024 * 1024 * megabytes / 2;
|
let maxlength = 1024 * 1024 * megabytes / 2;
|
||||||
let uint = new Uint8Array(maxlength);
|
let uint = new Uint8Array(maxlength);
|
||||||
for (let i = 0; i < maxlength; i++){
|
for (let i = 0; i < maxlength; i++){
|
||||||
@ -148,7 +148,7 @@ function fixedLengthString(megabytes){// eslint-disable-line no-unused-vars
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (Pseudo-)Random Uint8Array, given size in Megabytes
|
// (Pseudo-)Random Uint8Array, given size in Megabytes
|
||||||
function bigUint8(megabytes){// eslint-disable-line no-unused-vars
|
function bigUint8 (megabytes){// eslint-disable-line no-unused-vars
|
||||||
let maxlength = 1024 * 1024 * megabytes;
|
let maxlength = 1024 * 1024 * megabytes;
|
||||||
let uint = new Uint8Array(maxlength);
|
let uint = new Uint8Array(maxlength);
|
||||||
for (let i= 0; i < maxlength; i++){
|
for (let i= 0; i < maxlength; i++){
|
||||||
@ -159,7 +159,7 @@ function bigUint8(megabytes){// eslint-disable-line no-unused-vars
|
|||||||
|
|
||||||
// (Pseudo-)Random string with very limited charset
|
// (Pseudo-)Random string with very limited charset
|
||||||
// (ascii only, no control chars)
|
// (ascii only, no control chars)
|
||||||
function bigBoringString(megabytes){// eslint-disable-line no-unused-vars
|
function bigBoringString (megabytes){// eslint-disable-line no-unused-vars
|
||||||
let maxlength = 1024 * 1024 * megabytes;
|
let maxlength = 1024 * 1024 * megabytes;
|
||||||
let string = [];
|
let string = [];
|
||||||
let chars =
|
let chars =
|
||||||
@ -173,7 +173,7 @@ function bigBoringString(megabytes){// eslint-disable-line no-unused-vars
|
|||||||
// Some String with simple chars, with different characteristics, but still
|
// Some String with simple chars, with different characteristics, but still
|
||||||
// expected to occur in an averag message
|
// expected to occur in an averag message
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
function slightlyLessBoringString(megabytes, set){
|
function slightlyLessBoringString (megabytes, set){
|
||||||
let maxlength = 1024 * 1024 * megabytes;
|
let maxlength = 1024 * 1024 * megabytes;
|
||||||
let string = [];
|
let string = [];
|
||||||
let chars = '';
|
let chars = '';
|
||||||
@ -291,13 +291,13 @@ const ImportablePublicKey = {// eslint-disable-line no-unused-vars
|
|||||||
* preserve) header/footer
|
* preserve) header/footer
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
function sabotageMsg(msg, rate = 0.01, p= [35,35]){
|
function sabotageMsg (msg, rate = 0.01, p= [35,35]){
|
||||||
const iterations = Math.floor(Math.random() * msg.length * rate) + 1;
|
const iterations = Math.floor(Math.random() * msg.length * rate) + 1;
|
||||||
const base64_set =
|
const base64_set =
|
||||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/';
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/';
|
||||||
for (let i=0; i < iterations; i++){
|
for (let i=0; i < iterations; i++){
|
||||||
let str0, str1, str2;
|
let str0, str1, str2;
|
||||||
const chosePosition = function(){
|
const chosePosition = function (){
|
||||||
let position =
|
let position =
|
||||||
Math.floor( Math.random() * (msg.length - p[0] + p[1]))
|
Math.floor( Math.random() * (msg.length - p[0] + p[1]))
|
||||||
+ p[0];
|
+ p[0];
|
||||||
@ -310,7 +310,7 @@ function sabotageMsg(msg, rate = 0.01, p= [35,35]){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
chosePosition();
|
chosePosition();
|
||||||
let new1 = function(){
|
let new1 = function (){
|
||||||
let n = base64_set[Math.floor(Math.random() * 64)];
|
let n = base64_set[Math.floor(Math.random() * 64)];
|
||||||
return (n === str1) ? new1() : n;
|
return (n === str1) ? new1() : n;
|
||||||
};
|
};
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
describe('Long running Encryption/Decryption', function () {
|
describe('Long running Encryption/Decryption', function () {
|
||||||
let context = null;
|
let context = null;
|
||||||
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -43,7 +43,7 @@ describe('Long running Encryption/Decryption', function () {
|
|||||||
expect(answer.data).to.be.a('string');
|
expect(answer.data).to.be.a('string');
|
||||||
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
expect(answer.data).to.include('BEGIN PGP MESSAGE');
|
||||||
expect(answer.data).to.include('END PGP MESSAGE');
|
expect(answer.data).to.include('END PGP MESSAGE');
|
||||||
context.decrypt(answer.data).then(function(result){
|
context.decrypt(answer.data).then(function (result){
|
||||||
expect(result).to.not.be.empty;
|
expect(result).to.not.be.empty;
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.data).to.equal(data);
|
expect(result.data).to.equal(data);
|
||||||
|
@ -28,9 +28,9 @@ describe('Signing', function () {
|
|||||||
let context = null;
|
let context = null;
|
||||||
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
const good_fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
|
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
|
|
||||||
/* global describe, it, expect, Gpgmejs, inputvalues */
|
/* global describe, it, expect, Gpgmejs, inputvalues */
|
||||||
|
|
||||||
describe('GPGME context', function(){
|
describe('GPGME context', function (){
|
||||||
it('Starting a GpgME instance', function(done){
|
it('Starting a GpgME instance', function (done){
|
||||||
let prm = Gpgmejs.init();
|
let prm = Gpgmejs.init();
|
||||||
const input = inputvalues.someInputParameter;
|
const input = inputvalues.someInputParameter;
|
||||||
prm.then(
|
prm.then(
|
||||||
function(context){
|
function (context){
|
||||||
expect(context).to.be.an('object');
|
expect(context).to.be.an('object');
|
||||||
expect(context.encrypt).to.be.a('function');
|
expect(context.encrypt).to.be.a('function');
|
||||||
expect(context.decrypt).to.be.a('function');
|
expect(context.decrypt).to.be.a('function');
|
||||||
|
@ -27,16 +27,16 @@
|
|||||||
|
|
||||||
describe('Verifying data', function () {
|
describe('Verifying data', function () {
|
||||||
let context = null;
|
let context = null;
|
||||||
before(function(done){
|
before(function (done){
|
||||||
const prm = Gpgmejs.init();
|
const prm = Gpgmejs.init();
|
||||||
prm.then(function(gpgmejs){
|
prm.then(function (gpgmejs){
|
||||||
context = gpgmejs;
|
context = gpgmejs;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Successful verify message', function (done) {
|
it('Successful verify message', function (done) {
|
||||||
const message = inputvalues.signedMessage.good;
|
const message = inputvalues.signedMessage.good;
|
||||||
context.verify(message).then(function(result){
|
context.verify(message).then(function (result){
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.all_valid).to.be.true;
|
expect(result.all_valid).to.be.true;
|
||||||
expect(result.count).to.equal(1);
|
expect(result.count).to.equal(1);
|
||||||
@ -50,7 +50,7 @@ describe('Verifying data', function () {
|
|||||||
|
|
||||||
it('Successfully recognize changed cleartext', function (done) {
|
it('Successfully recognize changed cleartext', function (done) {
|
||||||
const message = inputvalues.signedMessage.bad;
|
const message = inputvalues.signedMessage.bad;
|
||||||
context.verify(message).then(function(result){
|
context.verify(message).then(function (result){
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.all_valid).to.be.false;
|
expect(result.all_valid).to.be.false;
|
||||||
expect(result.count).to.equal(1);
|
expect(result.count).to.equal(1);
|
||||||
@ -65,9 +65,9 @@ describe('Verifying data', function () {
|
|||||||
it('Encrypt-Sign-Verify random message', function (done) {
|
it('Encrypt-Sign-Verify random message', function (done) {
|
||||||
const message = bigString(2000);
|
const message = bigString(2000);
|
||||||
let fpr = inputvalues.encrypt.good.fingerprint;
|
let fpr = inputvalues.encrypt.good.fingerprint;
|
||||||
context.encrypt(message, fpr).then(function(message_enc){
|
context.encrypt(message, fpr).then(function (message_enc){
|
||||||
context.sign(message_enc.data, fpr).then(function(message_encsign){
|
context.sign(message_enc.data, fpr).then(function (message_encsign){
|
||||||
context.verify(message_encsign.data).then(function(result){
|
context.verify(message_encsign.data).then(function (result){
|
||||||
expect(result.data).to.equal(message_enc.data);
|
expect(result.data).to.equal(message_enc.data);
|
||||||
expect(result.data).to.be.a('string');
|
expect(result.data).to.be.a('string');
|
||||||
expect(result.all_valid).to.be.true;
|
expect(result.all_valid).to.be.true;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/* global chrome */
|
/* global chrome */
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
chrome.tabs.create({
|
chrome.tabs.create({
|
||||||
url: './mainui.html'
|
url: './mainui.html'
|
||||||
});
|
});
|
||||||
|
@ -23,67 +23,67 @@
|
|||||||
|
|
||||||
/* global document, Gpgmejs */
|
/* global document, Gpgmejs */
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
Gpgmejs.init().then(function(gpgmejs){
|
Gpgmejs.init().then(function (gpgmejs){
|
||||||
document.getElementById('buttonencrypt').addEventListener('click',
|
document.getElementById('buttonencrypt').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
let data = document.getElementById('inputtext').value;
|
let data = document.getElementById('inputtext').value;
|
||||||
let keyId = document.getElementById('pubkey').value;
|
let keyId = document.getElementById('pubkey').value;
|
||||||
gpgmejs.encrypt(data, keyId).then(
|
gpgmejs.encrypt(data, keyId).then(
|
||||||
function(answer){
|
function (answer){
|
||||||
if (answer.data){
|
if (answer.data){
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
'answer').value = answer.data;
|
'answer').value = answer.data;
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert( errormsg.message);
|
alert( errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('buttondecrypt').addEventListener('click',
|
document.getElementById('buttondecrypt').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
let data = document.getElementById('inputtext').value;
|
let data = document.getElementById('inputtext').value;
|
||||||
gpgmejs.decrypt(data).then(
|
gpgmejs.decrypt(data).then(
|
||||||
function(answer){
|
function (answer){
|
||||||
if (answer.data){
|
if (answer.data){
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
'answer').value = answer.data;
|
'answer').value = answer.data;
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert(errormsg.message);
|
alert(errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('getdefaultkey').addEventListener('click',
|
document.getElementById('getdefaultkey').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
gpgmejs.Keyring.getDefaultKey().then(function(answer){
|
gpgmejs.Keyring.getDefaultKey().then(function (answer){
|
||||||
document.getElementById('pubkey').value =
|
document.getElementById('pubkey').value =
|
||||||
answer.fingerprint;
|
answer.fingerprint;
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert(errormsg.message);
|
alert(errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('signtext').addEventListener('click',
|
document.getElementById('signtext').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
let data = document.getElementById('inputtext').value;
|
let data = document.getElementById('inputtext').value;
|
||||||
let keyId = document.getElementById('pubkey').value;
|
let keyId = document.getElementById('pubkey').value;
|
||||||
gpgmejs.sign(data, keyId).then(
|
gpgmejs.sign(data, keyId).then(
|
||||||
function(answer){
|
function (answer){
|
||||||
if (answer.data){
|
if (answer.data){
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
'answer').value = answer.data;
|
'answer').value = answer.data;
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert( errormsg.message);
|
alert( errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('verifytext').addEventListener('click',
|
document.getElementById('verifytext').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
let data = document.getElementById('inputtext').value;
|
let data = document.getElementById('inputtext').value;
|
||||||
gpgmejs.verify(data).then(
|
gpgmejs.verify(data).then(
|
||||||
function(answer){
|
function (answer){
|
||||||
let vals = '';
|
let vals = '';
|
||||||
if (answer.all_valid === true){
|
if (answer.all_valid === true){
|
||||||
vals = 'Success! ';
|
vals = 'Success! ';
|
||||||
@ -94,14 +94,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
+ answer.count + ' signature(s) were successfully '
|
+ answer.count + ' signature(s) were successfully '
|
||||||
+ 'verified.\n\n' + answer.data;
|
+ 'verified.\n\n' + answer.data;
|
||||||
document.getElementById('answer').value = vals;
|
document.getElementById('answer').value = vals;
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert( errormsg.message);
|
alert( errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
document.getElementById('searchkey').addEventListener('click',
|
document.getElementById('searchkey').addEventListener('click',
|
||||||
function(){
|
function (){
|
||||||
let data = document.getElementById('inputtext').value;
|
let data = document.getElementById('inputtext').value;
|
||||||
gpgmejs.Keyring.getKeys(data, true, true).then(function(keys){
|
gpgmejs.Keyring.getKeys(data, true, true).then(function (keys){
|
||||||
if (keys.length === 1){
|
if (keys.length === 1){
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
'pubkey').value = keys[0].fingerprint;
|
'pubkey').value = keys[0].fingerprint;
|
||||||
@ -111,7 +111,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
} else {
|
} else {
|
||||||
alert('No keys found');
|
alert('No keys found');
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function (errormsg){
|
||||||
alert( errormsg.message);
|
alert( errormsg.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -38,14 +38,14 @@ import { decode } from './Helpers';
|
|||||||
*/
|
*/
|
||||||
export class Connection{
|
export class Connection{
|
||||||
|
|
||||||
constructor(){
|
constructor (){
|
||||||
this._connection = chrome.runtime.connectNative('gpgmejson');
|
this._connection = chrome.runtime.connectNative('gpgmejson');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immediately closes an open port.
|
* Immediately closes an open port.
|
||||||
*/
|
*/
|
||||||
disconnect() {
|
disconnect () {
|
||||||
if (this._connection){
|
if (this._connection){
|
||||||
this._connection.disconnect();
|
this._connection.disconnect();
|
||||||
this._connection = null;
|
this._connection = null;
|
||||||
@ -81,17 +81,17 @@ export class Connection{
|
|||||||
return this.post(msg);
|
return this.post(msg);
|
||||||
} else {
|
} else {
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function (resolve) {
|
||||||
Promise.race([
|
Promise.race([
|
||||||
me.post(msg),
|
me.post(msg),
|
||||||
new Promise(function(resolve, reject){
|
new Promise(function (resolve, reject){
|
||||||
setTimeout(function(){
|
setTimeout(function (){
|
||||||
reject(gpgme_error('CONN_TIMEOUT'));
|
reject(gpgme_error('CONN_TIMEOUT'));
|
||||||
}, 500);
|
}, 500);
|
||||||
})
|
})
|
||||||
]).then(function(){ // success
|
]).then(function (){ // success
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}, function(){ // failure
|
}, function (){ // failure
|
||||||
resolve(false);
|
resolve(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -107,7 +107,7 @@ export class Connection{
|
|||||||
* @returns {Promise<Object>} The collected answer
|
* @returns {Promise<Object>} The collected answer
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
post(message){
|
post (message){
|
||||||
if (!message || !(message instanceof GPGME_Message)){
|
if (!message || !(message instanceof GPGME_Message)){
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
return Promise.reject(gpgme_error(
|
return Promise.reject(gpgme_error(
|
||||||
@ -119,9 +119,9 @@ export class Connection{
|
|||||||
}
|
}
|
||||||
let chunksize = message.chunksize;
|
let chunksize = message.chunksize;
|
||||||
const me = this;
|
const me = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
let answer = new Answer(message);
|
let answer = new Answer(message);
|
||||||
let listener = function(msg) {
|
let listener = function (msg) {
|
||||||
if (!msg){
|
if (!msg){
|
||||||
me._connection.onMessage.removeListener(listener);
|
me._connection.onMessage.removeListener(listener);
|
||||||
me._connection.disconnect();
|
me._connection.disconnect();
|
||||||
@ -157,16 +157,16 @@ export class Connection{
|
|||||||
} else {
|
} else {
|
||||||
return Promise.race([
|
return Promise.race([
|
||||||
me._connection.postMessage(message.message),
|
me._connection.postMessage(message.message),
|
||||||
function(resolve, reject){
|
function (resolve, reject){
|
||||||
setTimeout(function(){
|
setTimeout(function (){
|
||||||
me._connection.disconnect();
|
me._connection.disconnect();
|
||||||
reject(gpgme_error('CONN_TIMEOUT'));
|
reject(gpgme_error('CONN_TIMEOUT'));
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
]).then(function(result){
|
]).then(function (result){
|
||||||
return result;
|
return result;
|
||||||
}, function(reject){
|
}, function (reject){
|
||||||
if(!(reject instanceof Error)) {
|
if (!(reject instanceof Error)) {
|
||||||
me._connection.disconnect();
|
me._connection.disconnect();
|
||||||
return gpgme_error('GNUPG_ERROR', reject);
|
return gpgme_error('GNUPG_ERROR', reject);
|
||||||
} else {
|
} else {
|
||||||
@ -189,7 +189,7 @@ class Answer{
|
|||||||
/**
|
/**
|
||||||
* @param {GPGME_Message} message
|
* @param {GPGME_Message} message
|
||||||
*/
|
*/
|
||||||
constructor(message){
|
constructor (message){
|
||||||
this._operation = message.operation;
|
this._operation = message.operation;
|
||||||
this._expected = message.expected;
|
this._expected = message.expected;
|
||||||
this._response_b64 = null;
|
this._response_b64 = null;
|
||||||
@ -211,7 +211,7 @@ class Answer{
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
collect (msg){
|
collect (msg){
|
||||||
if (typeof(msg) !== 'object' || !msg.hasOwnProperty('response')) {
|
if (typeof (msg) !== 'object' || !msg.hasOwnProperty('response')) {
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
if (!this._response_b64){
|
if (!this._response_b64){
|
||||||
@ -226,7 +226,7 @@ class Answer{
|
|||||||
* Returns the base64 encoded answer data with the content verified
|
* Returns the base64 encoded answer data with the content verified
|
||||||
* against {@link permittedOperations}.
|
* against {@link permittedOperations}.
|
||||||
*/
|
*/
|
||||||
getMessage(){
|
getMessage (){
|
||||||
if (this._response_b64 === null){
|
if (this._response_b64 === null){
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ class Answer{
|
|||||||
if (!poa.data.hasOwnProperty(key)){
|
if (!poa.data.hasOwnProperty(key)){
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
if( typeof(_decodedResponse[key]) !== poa.data[key] ){
|
if ( typeof (_decodedResponse[key]) !== poa.data[key] ){
|
||||||
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
return gpgme_error('CONN_UNEXPECTED_ANSWER');
|
||||||
}
|
}
|
||||||
if (_decodedResponse.base64 === true
|
if (_decodedResponse.base64 === true
|
||||||
@ -268,7 +268,7 @@ class Answer{
|
|||||||
){
|
){
|
||||||
_response[key] = decodeURIComponent(
|
_response[key] = decodeURIComponent(
|
||||||
atob(_decodedResponse[key]).split('').map(
|
atob(_decodedResponse[key]).split('').map(
|
||||||
function(c) {
|
function (c) {
|
||||||
return '%' +
|
return '%' +
|
||||||
('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
}).join(''));
|
}).join(''));
|
||||||
|
@ -120,7 +120,7 @@ const err_list = {
|
|||||||
* @param {*} info Error message passed through if code is 'GNUPG_ERROR'
|
* @param {*} info Error message passed through if code is 'GNUPG_ERROR'
|
||||||
* @returns {GPGME_Error}
|
* @returns {GPGME_Error}
|
||||||
*/
|
*/
|
||||||
export function gpgme_error(code = 'GENERIC_ERROR', info){
|
export function gpgme_error (code = 'GENERIC_ERROR', info){
|
||||||
if (err_list.hasOwnProperty(code)){
|
if (err_list.hasOwnProperty(code)){
|
||||||
if (err_list[code].type === 'error'){
|
if (err_list[code].type === 'error'){
|
||||||
return new GPGME_Error(code);
|
return new GPGME_Error(code);
|
||||||
@ -147,9 +147,9 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){
|
|||||||
* @extends Error
|
* @extends Error
|
||||||
*/
|
*/
|
||||||
class GPGME_Error extends Error{
|
class GPGME_Error extends Error{
|
||||||
constructor(code = 'GENERIC_ERROR', msg=''){
|
constructor (code = 'GENERIC_ERROR', msg=''){
|
||||||
|
|
||||||
if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){
|
if (code === 'GNUPG_ERROR' && typeof (msg) === 'string'){
|
||||||
super(msg);
|
super(msg);
|
||||||
} else if (err_list.hasOwnProperty(code)){
|
} else if (err_list.hasOwnProperty(code)){
|
||||||
if (msg){
|
if (msg){
|
||||||
@ -163,7 +163,7 @@ class GPGME_Error extends Error{
|
|||||||
this._code = code;
|
this._code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
get code(){
|
get code (){
|
||||||
return this._code;
|
return this._code;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ import { gpgme_error } from './Errors';
|
|||||||
* @param {Object | Array<Object> | String | Array<String>} input
|
* @param {Object | Array<Object> | String | Array<String>} input
|
||||||
* @returns {Array<String>} Array of fingerprints, or an empty array
|
* @returns {Array<String>} Array of fingerprints, or an empty array
|
||||||
*/
|
*/
|
||||||
export function toKeyIdArray(input){
|
export function toKeyIdArray (input){
|
||||||
if (!input){
|
if (!input){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ export function toKeyIdArray(input){
|
|||||||
}
|
}
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let i=0; i < input.length; i++){
|
for (let i=0; i < input.length; i++){
|
||||||
if (typeof(input[i]) === 'string'){
|
if (typeof (input[i]) === 'string'){
|
||||||
if (isFingerprint(input[i]) === true){
|
if (isFingerprint(input[i]) === true){
|
||||||
result.push(input[i]);
|
result.push(input[i]);
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +47,7 @@ export function toKeyIdArray(input){
|
|||||||
// in src/Errors.js
|
// in src/Errors.js
|
||||||
gpgme_error('MSG_NOT_A_FPR');
|
gpgme_error('MSG_NOT_A_FPR');
|
||||||
}
|
}
|
||||||
} else if (typeof(input[i]) === 'object'){
|
} else if (typeof (input[i]) === 'object'){
|
||||||
let fpr = '';
|
let fpr = '';
|
||||||
if (input[i].hasOwnProperty('fingerprint')){
|
if (input[i].hasOwnProperty('fingerprint')){
|
||||||
fpr = input[i].fingerprint;
|
fpr = input[i].fingerprint;
|
||||||
@ -78,8 +78,8 @@ export function toKeyIdArray(input){
|
|||||||
* @returns {Boolean} true if value passes test
|
* @returns {Boolean} true if value passes test
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function hextest(key, len){
|
function hextest (key, len){
|
||||||
if (!key || typeof(key) !== 'string'){
|
if (!key || typeof (key) !== 'string'){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (key.length !== len){
|
if (key.length !== len){
|
||||||
@ -95,7 +95,7 @@ function hextest(key, len){
|
|||||||
* @param {String} value to check
|
* @param {String} value to check
|
||||||
* @returns {Boolean} true if value passes test
|
* @returns {Boolean} true if value passes test
|
||||||
*/
|
*/
|
||||||
export function isFingerprint(value){
|
export function isFingerprint (value){
|
||||||
return hextest(value, 40);
|
return hextest(value, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ export function isFingerprint(value){
|
|||||||
* @param {String} value to check
|
* @param {String} value to check
|
||||||
* @returns {Boolean} true if value passes test
|
* @returns {Boolean} true if value passes test
|
||||||
*/
|
*/
|
||||||
export function isLongId(value){
|
export function isLongId (value){
|
||||||
return hextest(value, 16);
|
return hextest(value, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ export function isLongId(value){
|
|||||||
* Recursively decodes input (utf8) to output (utf-16; javascript) strings
|
* Recursively decodes input (utf8) to output (utf-16; javascript) strings
|
||||||
* @param {Object | Array | String} property
|
* @param {Object | Array | String} property
|
||||||
*/
|
*/
|
||||||
export function decode(property){
|
export function decode (property){
|
||||||
if (typeof property === 'string'){
|
if (typeof property === 'string'){
|
||||||
return decodeURIComponent(escape(property));
|
return decodeURIComponent(escape(property));
|
||||||
} else if (Array.isArray(property)){
|
} else if (Array.isArray(property)){
|
||||||
|
@ -35,8 +35,8 @@ import { createMessage } from './Message';
|
|||||||
* a full object as delivered by gpgme-json
|
* a full object as delivered by gpgme-json
|
||||||
* @returns {Object|GPGME_Error} The verified and updated data
|
* @returns {Object|GPGME_Error} The verified and updated data
|
||||||
*/
|
*/
|
||||||
export function createKey(fingerprint, async = false, data){
|
export function createKey (fingerprint, async = false, data){
|
||||||
if (!isFingerprint(fingerprint) || typeof(async) !== 'boolean'){
|
if (!isFingerprint(fingerprint) || typeof (async) !== 'boolean'){
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
}
|
}
|
||||||
if (data !== undefined){
|
if (data !== undefined){
|
||||||
@ -60,14 +60,14 @@ export function createKey(fingerprint, async = false, data){
|
|||||||
*/
|
*/
|
||||||
class GPGME_Key {
|
class GPGME_Key {
|
||||||
|
|
||||||
constructor(fingerprint, async, data){
|
constructor (fingerprint, async, data){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Boolean} If true, most answers will be asynchronous
|
* @property {Boolean} If true, most answers will be asynchronous
|
||||||
*/
|
*/
|
||||||
this._async = async;
|
this._async = async;
|
||||||
|
|
||||||
this._data = {fingerprint: fingerprint.toUpperCase()};
|
this._data = { fingerprint: fingerprint.toUpperCase() };
|
||||||
if (data !== undefined
|
if (data !== undefined
|
||||||
&& data.fingerprint.toUpperCase() === this._data.fingerprint
|
&& data.fingerprint.toUpperCase() === this._data.fingerprint
|
||||||
) {
|
) {
|
||||||
@ -84,7 +84,7 @@ class GPGME_Key {
|
|||||||
* async, the armored property is not available (it can still be
|
* async, the armored property is not available (it can still be
|
||||||
* retrieved asynchronously by {@link Key.getArmor})
|
* retrieved asynchronously by {@link Key.getArmor})
|
||||||
*/
|
*/
|
||||||
get(property) {
|
get (property) {
|
||||||
if (this._async === true) {
|
if (this._async === true) {
|
||||||
switch (property){
|
switch (property){
|
||||||
case 'armored':
|
case 'armored':
|
||||||
@ -98,6 +98,7 @@ class GPGME_Key {
|
|||||||
if (property === 'armored') {
|
if (property === 'armored') {
|
||||||
return gpgme_error('KEY_ASYNC_ONLY');
|
return gpgme_error('KEY_ASYNC_ONLY');
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
if (!validKeyProperties.hasOwnProperty(property)){
|
if (!validKeyProperties.hasOwnProperty(property)){
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
} else {
|
} else {
|
||||||
@ -114,16 +115,16 @@ class GPGME_Key {
|
|||||||
* @returns {Promise<GPGME_Key|GPGME_Error>}
|
* @returns {Promise<GPGME_Key|GPGME_Error>}
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
refreshKey() {
|
refreshKey () {
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (!me._data.fingerprint){
|
if (!me._data.fingerprint){
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
}
|
}
|
||||||
let msg = createMessage('keylist');
|
let msg = createMessage('keylist');
|
||||||
msg.setParameter('sigs', true);
|
msg.setParameter('sigs', true);
|
||||||
msg.setParameter('keys', me._data.fingerprint);
|
msg.setParameter('keys', me._data.fingerprint);
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
if (result.keys.length === 1){
|
if (result.keys.length === 1){
|
||||||
const newdata = validateKeyData(
|
const newdata = validateKeyData(
|
||||||
me._data.fingerprint, result.keys[0]);
|
me._data.fingerprint, result.keys[0]);
|
||||||
@ -131,13 +132,13 @@ class GPGME_Key {
|
|||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
} else {
|
} else {
|
||||||
me._data = newdata;
|
me._data = newdata;
|
||||||
me.getGnupgSecretState().then(function(){
|
me.getGnupgSecretState().then(function (){
|
||||||
me.getArmor().then(function(){
|
me.getArmor().then(function (){
|
||||||
resolve(me);
|
resolve(me);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -157,18 +158,18 @@ class GPGME_Key {
|
|||||||
* @returns {Promise<String|GPGME_Error>}
|
* @returns {Promise<String|GPGME_Error>}
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
getArmor() {
|
getArmor () {
|
||||||
const me = this;
|
const me = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (!me._data.fingerprint){
|
if (!me._data.fingerprint){
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
}
|
}
|
||||||
let msg = createMessage('export');
|
let msg = createMessage('export');
|
||||||
msg.setParameter('armor', true);
|
msg.setParameter('armor', true);
|
||||||
msg.setParameter('keys', me._data.fingerprint);
|
msg.setParameter('keys', me._data.fingerprint);
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
resolve(result.data);
|
resolve(result.data);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -186,14 +187,14 @@ class GPGME_Key {
|
|||||||
*/
|
*/
|
||||||
getGnupgSecretState (){
|
getGnupgSecretState (){
|
||||||
const me = this;
|
const me = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (!me._data.fingerprint){
|
if (!me._data.fingerprint){
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
} else {
|
} else {
|
||||||
let msg = createMessage('keylist');
|
let msg = createMessage('keylist');
|
||||||
msg.setParameter('keys', me._data.fingerprint);
|
msg.setParameter('keys', me._data.fingerprint);
|
||||||
msg.setParameter('secret', true);
|
msg.setParameter('secret', true);
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
me._data.hasSecret = null;
|
me._data.hasSecret = null;
|
||||||
if (
|
if (
|
||||||
result.keys &&
|
result.keys &&
|
||||||
@ -206,7 +207,7 @@ class GPGME_Key {
|
|||||||
me._data.hasSecret = false;
|
me._data.hasSecret = false;
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -219,17 +220,17 @@ class GPGME_Key {
|
|||||||
* @returns {Promise<Boolean|GPGME_Error>} Success if key was deleted,
|
* @returns {Promise<Boolean|GPGME_Error>} Success if key was deleted,
|
||||||
* rejects with a GPG error otherwise.
|
* rejects with a GPG error otherwise.
|
||||||
*/
|
*/
|
||||||
delete(){
|
delete (){
|
||||||
const me = this;
|
const me = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
if (!me._data.fingerprint){
|
if (!me._data.fingerprint){
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
}
|
}
|
||||||
let msg = createMessage('delete');
|
let msg = createMessage('delete');
|
||||||
msg.setParameter('key', me._data.fingerprint);
|
msg.setParameter('key', me._data.fingerprint);
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
resolve(result.success);
|
resolve(result.success);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -238,7 +239,7 @@ class GPGME_Key {
|
|||||||
/**
|
/**
|
||||||
* @returns {String} The fingerprint defining this Key. Convenience getter
|
* @returns {String} The fingerprint defining this Key. Convenience getter
|
||||||
*/
|
*/
|
||||||
get fingerprint(){
|
get fingerprint (){
|
||||||
return this._data.fingerprint;
|
return this._data.fingerprint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,7 +256,7 @@ class GPGME_Subkey {
|
|||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
constructor(data){
|
constructor (data){
|
||||||
this._data = {};
|
this._data = {};
|
||||||
let keys = Object.keys(data);
|
let keys = Object.keys(data);
|
||||||
const me = this;
|
const me = this;
|
||||||
@ -268,7 +269,9 @@ class GPGME_Subkey {
|
|||||||
* @param private
|
* @param private
|
||||||
*/
|
*/
|
||||||
const setProperty = function (property, value){
|
const setProperty = function (property, value){
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
if (validSubKeyProperties.hasOwnProperty(property)){
|
if (validSubKeyProperties.hasOwnProperty(property)){
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
if (validSubKeyProperties[property](value) === true) {
|
if (validSubKeyProperties[property](value) === true) {
|
||||||
if (property === 'timestamp' || property === 'expires'){
|
if (property === 'timestamp' || property === 'expires'){
|
||||||
me._data[property] = new Date(value * 1000);
|
me._data[property] = new Date(value * 1000);
|
||||||
@ -288,7 +291,7 @@ class GPGME_Subkey {
|
|||||||
* @param {String} property Information to request
|
* @param {String} property Information to request
|
||||||
* @returns {String | Number | Date}
|
* @returns {String | Number | Date}
|
||||||
*/
|
*/
|
||||||
get(property) {
|
get (property) {
|
||||||
if (this._data.hasOwnProperty(property)){
|
if (this._data.hasOwnProperty(property)){
|
||||||
return (this._data[property]);
|
return (this._data[property]);
|
||||||
}
|
}
|
||||||
@ -308,12 +311,14 @@ class GPGME_UserId {
|
|||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
constructor(data){
|
constructor (data){
|
||||||
this._data = {};
|
this._data = {};
|
||||||
const me = this;
|
const me = this;
|
||||||
let keys = Object.keys(data);
|
let keys = Object.keys(data);
|
||||||
const setProperty = function(property, value){
|
const setProperty = function (property, value){
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
if (validUserIdProperties.hasOwnProperty(property)){
|
if (validUserIdProperties.hasOwnProperty(property)){
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
if (validUserIdProperties[property](value) === true) {
|
if (validUserIdProperties[property](value) === true) {
|
||||||
if (property === 'last_update'){
|
if (property === 'last_update'){
|
||||||
me._data[property] = new Date(value*1000);
|
me._data[property] = new Date(value*1000);
|
||||||
@ -333,7 +338,7 @@ class GPGME_UserId {
|
|||||||
* @param {String} property Information to request
|
* @param {String} property Information to request
|
||||||
* @returns {String | Number}
|
* @returns {String | Number}
|
||||||
*/
|
*/
|
||||||
get(property) {
|
get (property) {
|
||||||
if (this._data.hasOwnProperty(property)){
|
if (this._data.hasOwnProperty(property)){
|
||||||
return (this._data[property]);
|
return (this._data[property]);
|
||||||
}
|
}
|
||||||
@ -349,52 +354,52 @@ class GPGME_UserId {
|
|||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
const validUserIdProperties = {
|
const validUserIdProperties = {
|
||||||
'revoked': function(value){
|
'revoked': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'invalid': function(value){
|
'invalid': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'uid': function(value){
|
'uid': function (value){
|
||||||
if (typeof(value) === 'string' || value === ''){
|
if (typeof (value) === 'string' || value === ''){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'validity': function(value){
|
'validity': function (value){
|
||||||
if (typeof(value) === 'string'){
|
if (typeof (value) === 'string'){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'name': function(value){
|
'name': function (value){
|
||||||
if (typeof(value) === 'string' || value === ''){
|
if (typeof (value) === 'string' || value === ''){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'email': function(value){
|
'email': function (value){
|
||||||
if (typeof(value) === 'string' || value === ''){
|
if (typeof (value) === 'string' || value === ''){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'address': function(value){
|
'address': function (value){
|
||||||
if (typeof(value) === 'string' || value === ''){
|
if (typeof (value) === 'string' || value === ''){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'comment': function(value){
|
'comment': function (value){
|
||||||
if (typeof(value) === 'string' || value === ''){
|
if (typeof (value) === 'string' || value === ''){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
'origin': function(value){
|
'origin': function (value){
|
||||||
return Number.isInteger(value);
|
return Number.isInteger(value);
|
||||||
},
|
},
|
||||||
'last_update': function(value){
|
'last_update': function (value){
|
||||||
return Number.isInteger(value);
|
return Number.isInteger(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -406,54 +411,54 @@ const validUserIdProperties = {
|
|||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
const validSubKeyProperties = {
|
const validSubKeyProperties = {
|
||||||
'invalid': function(value){
|
'invalid': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_encrypt': function(value){
|
'can_encrypt': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_sign': function(value){
|
'can_sign': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_certify': function(value){
|
'can_certify': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_authenticate': function(value){
|
'can_authenticate': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'secret': function(value){
|
'secret': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'is_qualified': function(value){
|
'is_qualified': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'is_cardkey': function(value){
|
'is_cardkey': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'is_de_vs': function(value){
|
'is_de_vs': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'pubkey_algo_name': function(value){
|
'pubkey_algo_name': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
// TODO: check against list of known?['']
|
// TODO: check against list of known?['']
|
||||||
},
|
},
|
||||||
'pubkey_algo_string': function(value){
|
'pubkey_algo_string': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
// TODO: check against list of known?['']
|
// TODO: check against list of known?['']
|
||||||
},
|
},
|
||||||
'keyid': function(value){
|
'keyid': function (value){
|
||||||
return isLongId(value);
|
return isLongId(value);
|
||||||
},
|
},
|
||||||
'pubkey_algo': function(value) {
|
'pubkey_algo': function (value) {
|
||||||
return (Number.isInteger(value) && value >= 0);
|
return (Number.isInteger(value) && value >= 0);
|
||||||
},
|
},
|
||||||
'length': function(value){
|
'length': function (value){
|
||||||
return (Number.isInteger(value) && value > 0);
|
return (Number.isInteger(value) && value > 0);
|
||||||
},
|
},
|
||||||
'timestamp': function(value){
|
'timestamp': function (value){
|
||||||
return (Number.isInteger(value) && value > 0);
|
return (Number.isInteger(value) && value > 0);
|
||||||
},
|
},
|
||||||
'expires': function(value){
|
'expires': function (value){
|
||||||
return (Number.isInteger(value) && value > 0);
|
return (Number.isInteger(value) && value > 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -489,73 +494,73 @@ const validSubKeyProperties = {
|
|||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
const validKeyProperties = {
|
const validKeyProperties = {
|
||||||
'fingerprint': function(value){
|
'fingerprint': function (value){
|
||||||
return isFingerprint(value);
|
return isFingerprint(value);
|
||||||
},
|
},
|
||||||
'revoked': function(value){
|
'revoked': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'expired': function(value){
|
'expired': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'disabled': function(value){
|
'disabled': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'invalid': function(value){
|
'invalid': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_encrypt': function(value){
|
'can_encrypt': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_sign': function(value){
|
'can_sign': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_certify': function(value){
|
'can_certify': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'can_authenticate': function(value){
|
'can_authenticate': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'secret': function(value){
|
'secret': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'is_qualified': function(value){
|
'is_qualified': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
},
|
},
|
||||||
'protocol': function(value){
|
'protocol': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
//TODO check for implemented ones
|
// TODO check for implemented ones
|
||||||
},
|
},
|
||||||
'issuer_serial': function(value){
|
'issuer_serial': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
},
|
},
|
||||||
'issuer_name': function(value){
|
'issuer_name': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
},
|
},
|
||||||
'chain_id': function(value){
|
'chain_id': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
},
|
},
|
||||||
'owner_trust': function(value){
|
'owner_trust': function (value){
|
||||||
return typeof(value) === 'string';
|
return typeof (value) === 'string';
|
||||||
},
|
},
|
||||||
'last_update': function(value){
|
'last_update': function (value){
|
||||||
return (Number.isInteger(value));
|
return (Number.isInteger(value));
|
||||||
//TODO undefined/null possible?
|
// TODO undefined/null possible?
|
||||||
},
|
},
|
||||||
'origin': function(value){
|
'origin': function (value){
|
||||||
return (Number.isInteger(value));
|
return (Number.isInteger(value));
|
||||||
},
|
},
|
||||||
'subkeys': function(value){
|
'subkeys': function (value){
|
||||||
return (Array.isArray(value));
|
return (Array.isArray(value));
|
||||||
},
|
},
|
||||||
'userids': function(value){
|
'userids': function (value){
|
||||||
return (Array.isArray(value));
|
return (Array.isArray(value));
|
||||||
},
|
},
|
||||||
'tofu': function(value){
|
'tofu': function (value){
|
||||||
return (Array.isArray(value));
|
return (Array.isArray(value));
|
||||||
},
|
},
|
||||||
'hasSecret': function(value){
|
'hasSecret': function (value){
|
||||||
return typeof(value) === 'boolean';
|
return typeof (value) === 'boolean';
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -570,9 +575,9 @@ const validKeyProperties = {
|
|||||||
* an error if something went wrong.
|
* an error if something went wrong.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function validateKeyData(fingerprint, data){
|
function validateKeyData (fingerprint, data){
|
||||||
const key = {};
|
const key = {};
|
||||||
if (!fingerprint || typeof(data) !== 'object' || !data.fingerprint
|
if (!fingerprint || typeof (data) !== 'object' || !data.fingerprint
|
||||||
|| fingerprint !== data.fingerprint.toUpperCase()
|
|| fingerprint !== data.fingerprint.toUpperCase()
|
||||||
){
|
){
|
||||||
return gpgme_error('KEY_INVALID');
|
return gpgme_error('KEY_INVALID');
|
||||||
@ -619,13 +624,13 @@ function validateKeyData(fingerprint, data){
|
|||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
function getGnupgState (fingerprint, property){
|
function getGnupgState (fingerprint, property){
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (!isFingerprint(fingerprint)) {
|
if (!isFingerprint(fingerprint)) {
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
} else {
|
} else {
|
||||||
let msg = createMessage('keylist');
|
let msg = createMessage('keylist');
|
||||||
msg.setParameter('keys', fingerprint);
|
msg.setParameter('keys', fingerprint);
|
||||||
msg.post().then(function(res){
|
msg.post().then(function (res){
|
||||||
if (!res.keys || res.keys.length !== 1){
|
if (!res.keys || res.keys.length !== 1){
|
||||||
reject(gpgme_error('KEY_INVALID'));
|
reject(gpgme_error('KEY_INVALID'));
|
||||||
} else {
|
} else {
|
||||||
@ -675,7 +680,7 @@ function getGnupgState (fingerprint, property){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(gpgme_error(error));
|
reject(gpgme_error(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import {createMessage} from './Message';
|
import { createMessage } from './Message';
|
||||||
import {createKey} from './Key';
|
import { createKey } from './Key';
|
||||||
import { isFingerprint } from './Helpers';
|
import { isFingerprint } from './Helpers';
|
||||||
import { gpgme_error } from './Errors';
|
import { gpgme_error } from './Errors';
|
||||||
|
|
||||||
@ -31,8 +31,6 @@ import { gpgme_error } from './Errors';
|
|||||||
* This class offers access to the gnupg keyring
|
* This class offers access to the gnupg keyring
|
||||||
*/
|
*/
|
||||||
export class GPGME_Keyring {
|
export class GPGME_Keyring {
|
||||||
constructor(){
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries Keys (all Keys or a subset) from gnupg.
|
* Queries Keys (all Keys or a subset) from gnupg.
|
||||||
@ -51,7 +49,7 @@ export class GPGME_Keyring {
|
|||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
getKeys (pattern, prepare_sync=false, search=false){
|
getKeys (pattern, prepare_sync=false, search=false){
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
let msg = createMessage('keylist');
|
let msg = createMessage('keylist');
|
||||||
if (pattern !== undefined && pattern !== null){
|
if (pattern !== undefined && pattern !== null){
|
||||||
msg.setParameter('keys', pattern);
|
msg.setParameter('keys', pattern);
|
||||||
@ -60,25 +58,25 @@ export class GPGME_Keyring {
|
|||||||
if (search === true){
|
if (search === true){
|
||||||
msg.setParameter('locate', true);
|
msg.setParameter('locate', true);
|
||||||
}
|
}
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
let resultset = [];
|
let resultset = [];
|
||||||
if (result.keys.length === 0){
|
if (result.keys.length === 0){
|
||||||
resolve([]);
|
resolve([]);
|
||||||
} else {
|
} else {
|
||||||
let secondrequest;
|
let secondrequest;
|
||||||
if (prepare_sync === true) {
|
if (prepare_sync === true) {
|
||||||
secondrequest = function() {
|
secondrequest = function () {
|
||||||
let msg2 = createMessage('keylist');
|
let msg2 = createMessage('keylist');
|
||||||
msg2.setParameter('keys', pattern);
|
msg2.setParameter('keys', pattern);
|
||||||
msg2.setParameter('secret', true);
|
msg2.setParameter('secret', true);
|
||||||
return msg2.post();
|
return msg2.post();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
secondrequest = function() {
|
secondrequest = function () {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
secondrequest().then(function(answer) {
|
secondrequest().then(function (answer) {
|
||||||
for (let i=0; i < result.keys.length; i++){
|
for (let i=0; i < result.keys.length; i++){
|
||||||
if (prepare_sync === true){
|
if (prepare_sync === true){
|
||||||
if (answer && answer.keys) {
|
if (answer && answer.keys) {
|
||||||
@ -104,7 +102,7 @@ export class GPGME_Keyring {
|
|||||||
resultset.push(k);
|
resultset.push(k);
|
||||||
}
|
}
|
||||||
resolve(resultset);
|
resolve(resultset);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -136,7 +134,7 @@ export class GPGME_Keyring {
|
|||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
getKeysArmored (pattern, with_secret_fpr) {
|
getKeysArmored (pattern, with_secret_fpr) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
let msg = createMessage('export');
|
let msg = createMessage('export');
|
||||||
msg.setParameter('armor', true);
|
msg.setParameter('armor', true);
|
||||||
if (with_secret_fpr === true) {
|
if (with_secret_fpr === true) {
|
||||||
@ -145,15 +143,15 @@ export class GPGME_Keyring {
|
|||||||
if (pattern !== undefined && pattern !== null){
|
if (pattern !== undefined && pattern !== null){
|
||||||
msg.setParameter('keys', pattern);
|
msg.setParameter('keys', pattern);
|
||||||
}
|
}
|
||||||
msg.post().then(function(answer){
|
msg.post().then(function (answer){
|
||||||
const result = {armored: answer.data};
|
const result = { armored: answer.data };
|
||||||
if (with_secret_fpr === true
|
if (with_secret_fpr === true
|
||||||
&& answer.hasOwnProperty('sec-fprs')
|
&& answer.hasOwnProperty('sec-fprs')
|
||||||
) {
|
) {
|
||||||
result.secret_fprs = answer['sec-fprs'];
|
result.secret_fprs = answer['sec-fprs'];
|
||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -169,32 +167,32 @@ export class GPGME_Keyring {
|
|||||||
* @async
|
* @async
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
getDefaultKey(prepare_sync = false) {
|
getDefaultKey (prepare_sync = false) {
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
let msg = createMessage('config_opt');
|
let msg = createMessage('config_opt');
|
||||||
msg.setParameter('component', 'gpg');
|
msg.setParameter('component', 'gpg');
|
||||||
msg.setParameter('option', 'default-key');
|
msg.setParameter('option', 'default-key');
|
||||||
msg.post().then(function(resp){
|
msg.post().then(function (resp){
|
||||||
if (resp.option !== undefined
|
if (resp.option !== undefined
|
||||||
&& resp.option.hasOwnProperty('value')
|
&& resp.option.hasOwnProperty('value')
|
||||||
&& resp.option.value.length === 1
|
&& resp.option.value.length === 1
|
||||||
&& resp.option.value[0].hasOwnProperty('string')
|
&& resp.option.value[0].hasOwnProperty('string')
|
||||||
&& typeof(resp.option.value[0].string) === 'string'){
|
&& typeof (resp.option.value[0].string) === 'string'){
|
||||||
me.getKeys(resp.option.value[0].string, true).then(
|
me.getKeys(resp.option.value[0].string, true).then(
|
||||||
function(keys){
|
function (keys){
|
||||||
if(keys.length === 1){
|
if (keys.length === 1){
|
||||||
resolve(keys[0]);
|
resolve(keys[0]);
|
||||||
} else {
|
} else {
|
||||||
reject(gpgme_error('KEY_NO_DEFAULT'));
|
reject(gpgme_error('KEY_NO_DEFAULT'));
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let msg = createMessage('keylist');
|
let msg = createMessage('keylist');
|
||||||
msg.setParameter('secret', true);
|
msg.setParameter('secret', true);
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
if (result.keys.length === 0){
|
if (result.keys.length === 0){
|
||||||
reject(gpgme_error('KEY_NO_DEFAULT'));
|
reject(gpgme_error('KEY_NO_DEFAULT'));
|
||||||
} else {
|
} else {
|
||||||
@ -211,11 +209,11 @@ export class GPGME_Keyring {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -264,14 +262,14 @@ export class GPGME_Keyring {
|
|||||||
'new_signatures', 'new_revocations', 'secret_read',
|
'new_signatures', 'new_revocations', 'secret_read',
|
||||||
'secret_imported', 'secret_unchanged', 'skipped_new_keys',
|
'secret_imported', 'secret_unchanged', 'skipped_new_keys',
|
||||||
'not_imported', 'skipped_v3_keys'];
|
'not_imported', 'skipped_v3_keys'];
|
||||||
if (!armored || typeof(armored) !== 'string'){
|
if (!armored || typeof (armored) !== 'string'){
|
||||||
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
||||||
}
|
}
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
let msg = createMessage('import');
|
let msg = createMessage('import');
|
||||||
msg.setParameter('data', armored);
|
msg.setParameter('data', armored);
|
||||||
msg.post().then(function(response){
|
msg.post().then(function (response){
|
||||||
let infos = {};
|
let infos = {};
|
||||||
let fprs = [];
|
let fprs = [];
|
||||||
let summary = {};
|
let summary = {};
|
||||||
@ -282,7 +280,7 @@ export class GPGME_Keyring {
|
|||||||
if (!response.result.hasOwnProperty('imports') ||
|
if (!response.result.hasOwnProperty('imports') ||
|
||||||
response.result.imports.length === 0
|
response.result.imports.length === 0
|
||||||
){
|
){
|
||||||
resolve({Keys:[],summary: summary});
|
resolve({ Keys:[],summary: summary });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let res=0; res<response.result.imports.length; res++){
|
for (let res=0; res<response.result.imports.length; res++){
|
||||||
@ -299,7 +297,7 @@ export class GPGME_Keyring {
|
|||||||
changes.userId = (result.status & 2) === 2;
|
changes.userId = (result.status & 2) === 2;
|
||||||
changes.signature = (result.status & 4) === 4;
|
changes.signature = (result.status & 4) === 4;
|
||||||
changes.subkey = (result.status & 8) === 8;
|
changes.subkey = (result.status & 8) === 8;
|
||||||
//16 new secret key: not implemented
|
// 16 new secret key: not implemented
|
||||||
|
|
||||||
fprs.push(result.fingerprint);
|
fprs.push(result.fingerprint);
|
||||||
infos[result.fingerprint] = {
|
infos[result.fingerprint] = {
|
||||||
@ -309,7 +307,7 @@ export class GPGME_Keyring {
|
|||||||
}
|
}
|
||||||
let resultset = [];
|
let resultset = [];
|
||||||
if (prepare_sync === true){
|
if (prepare_sync === true){
|
||||||
me.getKeys(fprs, true).then(function(result){
|
me.getKeys(fprs, true).then(function (result){
|
||||||
for (let i=0; i < result.length; i++) {
|
for (let i=0; i < result.length; i++) {
|
||||||
resultset.push({
|
resultset.push({
|
||||||
key: result[i],
|
key: result[i],
|
||||||
@ -318,8 +316,8 @@ export class GPGME_Keyring {
|
|||||||
status: infos[result[i].fingerprint].status
|
status: infos[result[i].fingerprint].status
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resolve({Keys:resultset,summary: summary});
|
resolve({ Keys:resultset,summary: summary });
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -330,10 +328,10 @@ export class GPGME_Keyring {
|
|||||||
status: infos[fprs[i]].status
|
status: infos[fprs[i]].status
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resolve({Keys:resultset,summary:summary});
|
resolve({ Keys:resultset,summary:summary });
|
||||||
}
|
}
|
||||||
|
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -351,7 +349,7 @@ export class GPGME_Keyring {
|
|||||||
* @async
|
* @async
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
deleteKey(fingerprint){
|
deleteKey (fingerprint){
|
||||||
if (isFingerprint(fingerprint) === true) {
|
if (isFingerprint(fingerprint) === true) {
|
||||||
let key = createKey(fingerprint);
|
let key = createKey(fingerprint);
|
||||||
return key.delete();
|
return key.delete();
|
||||||
@ -375,16 +373,17 @@ export class GPGME_Keyring {
|
|||||||
* @return {Promise<Key|GPGME_Error>}
|
* @return {Promise<Key|GPGME_Error>}
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
generateKey(userId, algo = 'default', expires){
|
generateKey (userId, algo = 'default', expires){
|
||||||
if (
|
if (
|
||||||
typeof(userId) !== 'string' ||
|
typeof (userId) !== 'string' ||
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
supportedKeyAlgos.indexOf(algo) < 0 ||
|
supportedKeyAlgos.indexOf(algo) < 0 ||
|
||||||
(expires && !(expires instanceof Date))
|
(expires && !(expires instanceof Date))
|
||||||
){
|
){
|
||||||
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
||||||
}
|
}
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
let msg = createMessage('createkey');
|
let msg = createMessage('createkey');
|
||||||
msg.setParameter('userid', userId);
|
msg.setParameter('userid', userId);
|
||||||
msg.setParameter('algo', algo );
|
msg.setParameter('algo', algo );
|
||||||
@ -394,15 +393,15 @@ export class GPGME_Keyring {
|
|||||||
} else {
|
} else {
|
||||||
msg.setParameter('expires', 0);
|
msg.setParameter('expires', 0);
|
||||||
}
|
}
|
||||||
msg.post().then(function(response){
|
msg.post().then(function (response){
|
||||||
me.getKeys(response.fingerprint, true).then(
|
me.getKeys(response.fingerprint, true).then(
|
||||||
// TODO prepare_sync?
|
// TODO prepare_sync?
|
||||||
function(result){
|
function (result){
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}, function(error) {
|
}, function (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,8 +31,8 @@ import { Connection } from './Connection';
|
|||||||
* @param {String} operation
|
* @param {String} operation
|
||||||
* @returns {GPGME_Message|GPGME_Error} The Message object
|
* @returns {GPGME_Message|GPGME_Error} The Message object
|
||||||
*/
|
*/
|
||||||
export function createMessage(operation){
|
export function createMessage (operation){
|
||||||
if (typeof(operation) !== 'string'){
|
if (typeof (operation) !== 'string'){
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
}
|
}
|
||||||
if (permittedOperations.hasOwnProperty(operation)){
|
if (permittedOperations.hasOwnProperty(operation)){
|
||||||
@ -51,7 +51,7 @@ export function createMessage(operation){
|
|||||||
*/
|
*/
|
||||||
export class GPGME_Message {
|
export class GPGME_Message {
|
||||||
|
|
||||||
constructor(operation){
|
constructor (operation){
|
||||||
this._msg = {
|
this._msg = {
|
||||||
op: operation,
|
op: operation,
|
||||||
chunksize: 1023* 1024
|
chunksize: 1023* 1024
|
||||||
@ -59,7 +59,7 @@ export class GPGME_Message {
|
|||||||
this._expected = null;
|
this._expected = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get operation(){
|
get operation (){
|
||||||
return this._msg.op;
|
return this._msg.op;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ export class GPGME_Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get expected() {
|
get expected () {
|
||||||
return this._expected;
|
return this._expected;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -81,7 +81,7 @@ export class GPGME_Message {
|
|||||||
* will not encounter problems, larger messages will be received in
|
* will not encounter problems, larger messages will be received in
|
||||||
* chunks. If the value is not explicitly specified, 1023 KB is used.
|
* chunks. If the value is not explicitly specified, 1023 KB is used.
|
||||||
*/
|
*/
|
||||||
set chunksize(value){
|
set chunksize (value){
|
||||||
if (
|
if (
|
||||||
Number.isInteger(value) &&
|
Number.isInteger(value) &&
|
||||||
value > 10 * 1024 &&
|
value > 10 * 1024 &&
|
||||||
@ -91,7 +91,7 @@ export class GPGME_Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get chunksize(){
|
get chunksize (){
|
||||||
return this._msg.chunksize;
|
return this._msg.chunksize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ export class GPGME_Message {
|
|||||||
* @returns {Object|null} Object to be posted to gnupg, or null if
|
* @returns {Object|null} Object to be posted to gnupg, or null if
|
||||||
* incomplete
|
* incomplete
|
||||||
*/
|
*/
|
||||||
get message() {
|
get message () {
|
||||||
if (this.isComplete() === true){
|
if (this.isComplete() === true){
|
||||||
return this._msg;
|
return this._msg;
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +116,7 @@ export class GPGME_Message {
|
|||||||
* @returns {Boolean} If the parameter was set successfully
|
* @returns {Boolean} If the parameter was set successfully
|
||||||
*/
|
*/
|
||||||
setParameter ( param,value ){
|
setParameter ( param,value ){
|
||||||
if (!param || typeof(param) !== 'string'){
|
if (!param || typeof (param) !== 'string'){
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
}
|
}
|
||||||
let po = permittedOperations[this._msg.op];
|
let po = permittedOperations[this._msg.op];
|
||||||
@ -132,10 +132,10 @@ export class GPGME_Message {
|
|||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
}
|
}
|
||||||
// check incoming value for correctness
|
// check incoming value for correctness
|
||||||
let checktype = function(val){
|
let checktype = function (val){
|
||||||
switch(typeof(val)){
|
switch (typeof (val)){
|
||||||
case 'string':
|
case 'string':
|
||||||
if (poparam.allowed.indexOf(typeof(val)) >= 0
|
if (poparam.allowed.indexOf(typeof (val)) >= 0
|
||||||
&& val.length > 0) {
|
&& val.length > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ export class GPGME_Message {
|
|||||||
* all 'required' parameters according to {@link permittedOperations}.
|
* all 'required' parameters according to {@link permittedOperations}.
|
||||||
* @returns {Boolean} true if message is complete.
|
* @returns {Boolean} true if message is complete.
|
||||||
*/
|
*/
|
||||||
isComplete(){
|
isComplete (){
|
||||||
if (!this._msg.op){
|
if (!this._msg.op){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -220,13 +220,13 @@ export class GPGME_Message {
|
|||||||
*/
|
*/
|
||||||
post (){
|
post (){
|
||||||
let me = this;
|
let me = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (me.isComplete() === true) {
|
if (me.isComplete() === true) {
|
||||||
|
|
||||||
let conn = new Connection;
|
let conn = new Connection;
|
||||||
conn.post(me).then(function(response) {
|
conn.post(me).then(function (response) {
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}, function(reason) {
|
}, function (reason) {
|
||||||
reject(reason);
|
reject(reason);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,25 +30,27 @@ import { gpgme_error } from './Errors';
|
|||||||
* {@link expNote}.
|
* {@link expNote}.
|
||||||
* @returns {GPGME_Signature|GPGME_Error} Signature Object
|
* @returns {GPGME_Signature|GPGME_Error} Signature Object
|
||||||
*/
|
*/
|
||||||
export function createSignature(sigObject){
|
export function createSignature (sigObject){
|
||||||
if (
|
if (
|
||||||
typeof(sigObject) !=='object' ||
|
typeof (sigObject) !=='object' ||
|
||||||
!sigObject.hasOwnProperty('summary') ||
|
!sigObject.hasOwnProperty('summary') ||
|
||||||
!sigObject.hasOwnProperty('fingerprint') ||
|
!sigObject.hasOwnProperty('fingerprint') ||
|
||||||
!sigObject.hasOwnProperty('timestamp')
|
!sigObject.hasOwnProperty('timestamp')
|
||||||
//TODO check if timestamp is mandatory in specification
|
// TODO check if timestamp is mandatory in specification
|
||||||
){
|
){
|
||||||
return gpgme_error('SIG_WRONG');
|
return gpgme_error('SIG_WRONG');
|
||||||
}
|
}
|
||||||
let keys = Object.keys(sigObject);
|
let keys = Object.keys(sigObject);
|
||||||
for (let i=0; i< keys.length; i++){
|
for (let i=0; i< keys.length; i++){
|
||||||
if ( typeof(sigObject[keys[i]]) !== expKeys[keys[i]] ){
|
// eslint-disable-next-line no-use-before-define
|
||||||
|
if ( typeof (sigObject[keys[i]]) !== expKeys[keys[i]] ){
|
||||||
return gpgme_error('SIG_WRONG');
|
return gpgme_error('SIG_WRONG');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sumkeys = Object.keys(sigObject.summary);
|
let sumkeys = Object.keys(sigObject.summary);
|
||||||
for (let i=0; i< sumkeys.length; i++){
|
for (let i=0; i< sumkeys.length; i++){
|
||||||
if ( typeof(sigObject.summary[sumkeys[i]]) !== expSum[sumkeys[i]] ){
|
// eslint-disable-next-line no-use-before-define
|
||||||
|
if ( typeof (sigObject.summary[sumkeys[i]]) !== expSum[sumkeys[i]] ){
|
||||||
return gpgme_error('SIG_WRONG');
|
return gpgme_error('SIG_WRONG');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +62,8 @@ export function createSignature(sigObject){
|
|||||||
let notation = sigObject.notations[i];
|
let notation = sigObject.notations[i];
|
||||||
let notekeys = Object.keys(notation);
|
let notekeys = Object.keys(notation);
|
||||||
for (let j=0; j < notekeys.length; j++){
|
for (let j=0; j < notekeys.length; j++){
|
||||||
if ( typeof(notation[notekeys[j]]) !== expNote[notekeys[j]] ){
|
// eslint-disable-next-line no-use-before-define
|
||||||
|
if ( typeof (notation[notekeys[j]]) !== expNote[notekeys[j]] ){
|
||||||
return gpgme_error('SIG_WRONG');
|
return gpgme_error('SIG_WRONG');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,10 +84,10 @@ export function createSignature(sigObject){
|
|||||||
*/
|
*/
|
||||||
class GPGME_Signature {
|
class GPGME_Signature {
|
||||||
|
|
||||||
constructor(sigObject){
|
constructor (sigObject){
|
||||||
this._rawSigObject = sigObject;
|
this._rawSigObject = sigObject;
|
||||||
}
|
}
|
||||||
get fingerprint(){
|
get fingerprint (){
|
||||||
if (!this._rawSigObject.fingerprint){
|
if (!this._rawSigObject.fingerprint){
|
||||||
return gpgme_error('SIG_WRONG');
|
return gpgme_error('SIG_WRONG');
|
||||||
} else {
|
} else {
|
||||||
@ -97,7 +100,7 @@ class GPGME_Signature {
|
|||||||
* signature does not expire
|
* signature does not expire
|
||||||
* @returns {Date | null}
|
* @returns {Date | null}
|
||||||
*/
|
*/
|
||||||
get expiration(){
|
get expiration (){
|
||||||
if (!this._rawSigObject.exp_timestamp){
|
if (!this._rawSigObject.exp_timestamp){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -130,7 +133,7 @@ class GPGME_Signature {
|
|||||||
* for details on the values.
|
* for details on the values.
|
||||||
* @returns {Object} Object with boolean properties
|
* @returns {Object} Object with boolean properties
|
||||||
*/
|
*/
|
||||||
get errorDetails(){
|
get errorDetails (){
|
||||||
let properties = ['revoked', 'key-expired', 'sig-expired',
|
let properties = ['revoked', 'key-expired', 'sig-expired',
|
||||||
'key-missing', 'crl-missing', 'crl-too-old', 'bad-policy',
|
'key-missing', 'crl-missing', 'crl-too-old', 'bad-policy',
|
||||||
'sys-error'];
|
'sys-error'];
|
||||||
|
@ -84,7 +84,7 @@ import { createSignature } from './Signature';
|
|||||||
*/
|
*/
|
||||||
export class GpgME {
|
export class GpgME {
|
||||||
|
|
||||||
constructor(){
|
constructor (){
|
||||||
this._Keyring = null;
|
this._Keyring = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ export class GpgME {
|
|||||||
* setter for {@link setKeyring}.
|
* setter for {@link setKeyring}.
|
||||||
* @param {GPGME_Keyring} keyring A Keyring to use
|
* @param {GPGME_Keyring} keyring A Keyring to use
|
||||||
*/
|
*/
|
||||||
set Keyring(keyring){
|
set Keyring (keyring){
|
||||||
if (keyring && keyring instanceof GPGME_Keyring){
|
if (keyring && keyring instanceof GPGME_Keyring){
|
||||||
this._Keyring = keyring;
|
this._Keyring = keyring;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ export class GpgME {
|
|||||||
/**
|
/**
|
||||||
* Accesses the {@link GPGME_Keyring}.
|
* Accesses the {@link GPGME_Keyring}.
|
||||||
*/
|
*/
|
||||||
get Keyring(){
|
get Keyring (){
|
||||||
if (!this._Keyring){
|
if (!this._Keyring){
|
||||||
this._Keyring = new GPGME_Keyring;
|
this._Keyring = new GPGME_Keyring;
|
||||||
}
|
}
|
||||||
@ -188,9 +188,9 @@ export class GpgME {
|
|||||||
if (base64 === true){
|
if (base64 === true){
|
||||||
msg.setParameter('base64', true);
|
msg.setParameter('base64', true);
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
msg.post().then(function(result){
|
msg.post().then(function (result){
|
||||||
let _result = {data: result.data};
|
let _result = { data: result.data };
|
||||||
_result.base64 = result.base64 ? true: false;
|
_result.base64 = result.base64 ? true: false;
|
||||||
_result.is_mime = result.is_mime ? true: false;
|
_result.is_mime = result.is_mime ? true: false;
|
||||||
if (result.file_name){
|
if (result.file_name){
|
||||||
@ -206,7 +206,7 @@ export class GpgME {
|
|||||||
result.signatures);
|
result.signatures);
|
||||||
}
|
}
|
||||||
resolve(_result);
|
resolve(_result);
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -240,14 +240,14 @@ export class GpgME {
|
|||||||
}
|
}
|
||||||
msg.setParameter('mode', mode);
|
msg.setParameter('mode', mode);
|
||||||
putData(msg, data);
|
putData(msg, data);
|
||||||
return new Promise(function(resolve,reject) {
|
return new Promise(function (resolve,reject) {
|
||||||
if (mode ==='detached'){
|
if (mode ==='detached'){
|
||||||
msg.expected ='base64';
|
msg.expected ='base64';
|
||||||
}
|
}
|
||||||
msg.post().then( function(message) {
|
msg.post().then( function (message) {
|
||||||
if (mode === 'clearsign'){
|
if (mode === 'clearsign'){
|
||||||
resolve({
|
resolve({
|
||||||
data: message.data}
|
data: message.data }
|
||||||
);
|
);
|
||||||
} else if (mode === 'detached') {
|
} else if (mode === 'detached') {
|
||||||
resolve({
|
resolve({
|
||||||
@ -255,7 +255,7 @@ export class GpgME {
|
|||||||
signature: message.data
|
signature: message.data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -278,7 +278,7 @@ export class GpgME {
|
|||||||
return Promise.reject(dt);
|
return Promise.reject(dt);
|
||||||
}
|
}
|
||||||
if (signature){
|
if (signature){
|
||||||
if (typeof(signature)!== 'string'){
|
if (typeof (signature)!== 'string'){
|
||||||
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
return Promise.reject(gpgme_error('PARAM_WRONG'));
|
||||||
} else {
|
} else {
|
||||||
msg.setParameter('signature', signature);
|
msg.setParameter('signature', signature);
|
||||||
@ -287,7 +287,7 @@ export class GpgME {
|
|||||||
if (base64 === true){
|
if (base64 === true){
|
||||||
msg.setParameter('base64', true);
|
msg.setParameter('base64', true);
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
msg.post().then(function (message){
|
msg.post().then(function (message){
|
||||||
if (!message.info || !message.info.signatures){
|
if (!message.info || !message.info.signatures){
|
||||||
reject(gpgme_error('SIG_NO_SIGS'));
|
reject(gpgme_error('SIG_NO_SIGS'));
|
||||||
@ -301,7 +301,7 @@ export class GpgME {
|
|||||||
_result.data = message.data;
|
_result.data = message.data;
|
||||||
resolve(_result);
|
resolve(_result);
|
||||||
}
|
}
|
||||||
}, function(error){
|
}, function (error){
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -316,20 +316,20 @@ export class GpgME {
|
|||||||
* @returns {undefined| GPGME_Error} Error if not successful, nothing otherwise
|
* @returns {undefined| GPGME_Error} Error if not successful, nothing otherwise
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function putData(message, data){
|
function putData (message, data){
|
||||||
if (!message || !(message instanceof GPGME_Message)) {
|
if (!message || !(message instanceof GPGME_Message)) {
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
}
|
}
|
||||||
if (!data){
|
if (!data){
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
} else if (typeof(data) === 'string') {
|
} else if (typeof (data) === 'string') {
|
||||||
message.setParameter('data', data);
|
message.setParameter('data', data);
|
||||||
} else if (
|
} else if (
|
||||||
typeof(data) === 'object' &&
|
typeof (data) === 'object' &&
|
||||||
typeof(data.getText) === 'function'
|
typeof (data.getText) === 'function'
|
||||||
){
|
){
|
||||||
let txt = data.getText();
|
let txt = data.getText();
|
||||||
if (typeof(txt) === 'string'){
|
if (typeof (txt) === 'string'){
|
||||||
message.setParameter('data', txt);
|
message.setParameter('data', txt);
|
||||||
} else {
|
} else {
|
||||||
return gpgme_error('PARAM_WRONG');
|
return gpgme_error('PARAM_WRONG');
|
||||||
@ -345,7 +345,7 @@ function putData(message, data){
|
|||||||
* @param {Array<Object>} sigs
|
* @param {Array<Object>} sigs
|
||||||
* @returns {signatureDetails} Details about the signatures
|
* @returns {signatureDetails} Details about the signatures
|
||||||
*/
|
*/
|
||||||
function collectSignatures(sigs){
|
function collectSignatures (sigs){
|
||||||
if (!Array.isArray(sigs)){
|
if (!Array.isArray(sigs)){
|
||||||
return gpgme_error('SIG_NO_SIGS');
|
return gpgme_error('SIG_NO_SIGS');
|
||||||
}
|
}
|
||||||
|
@ -32,21 +32,21 @@ import { Connection } from './Connection';
|
|||||||
*
|
*
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
function init(){
|
function init (){
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject){
|
||||||
const connection = new Connection;
|
const connection = new Connection;
|
||||||
connection.checkConnection(false).then(
|
connection.checkConnection(false).then(
|
||||||
function(result){
|
function (result){
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
resolve(new GpgME());
|
resolve(new GpgME());
|
||||||
} else {
|
} else {
|
||||||
reject(gpgme_error('CONN_NO_CONNECT'));
|
reject(gpgme_error('CONN_NO_CONNECT'));
|
||||||
}
|
}
|
||||||
}, function(){ //unspecific connection error. Should not happen
|
}, function (){ // unspecific connection error. Should not happen
|
||||||
reject(gpgme_error('CONN_NO_CONNECT'));
|
reject(gpgme_error('CONN_NO_CONNECT'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportvalue = {init:init};
|
const exportvalue = { init:init };
|
||||||
export default exportvalue;
|
export default exportvalue;
|
@ -48,7 +48,7 @@
|
|||||||
*/
|
*/
|
||||||
export const permittedOperations = {
|
export const permittedOperations = {
|
||||||
encrypt: {
|
encrypt: {
|
||||||
pinentry: true, //TODO only with signing_keys
|
pinentry: true, // TODO only with signing_keys
|
||||||
required: {
|
required: {
|
||||||
'keys': {
|
'keys': {
|
||||||
allowed: ['string'],
|
allowed: ['string'],
|
||||||
@ -137,7 +137,7 @@ export const permittedOperations = {
|
|||||||
pinentry: true,
|
pinentry: true,
|
||||||
required: {
|
required: {
|
||||||
'data': {
|
'data': {
|
||||||
allowed: ['string']},
|
allowed: ['string'] },
|
||||||
'keys': {
|
'keys': {
|
||||||
allowed: ['string'],
|
allowed: ['string'],
|
||||||
array_allowed: true
|
array_allowed: true
|
||||||
@ -337,7 +337,7 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
answer: {
|
answer: {
|
||||||
type: [''],
|
type: [''],
|
||||||
data: {'fingerprint': 'string'}
|
data: { 'fingerprint': 'string' }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -365,9 +365,9 @@ export const permittedOperations = {
|
|||||||
data: 'string',
|
data: 'string',
|
||||||
base64:'boolean',
|
base64:'boolean',
|
||||||
info: 'object'
|
info: 'object'
|
||||||
// file_name: Optional string of the plaintext file name.
|
// info.file_name: Optional string of the plaintext file name.
|
||||||
// is_mime: Boolean if the messages claims it is MIME.
|
// info.is_mime: Boolean if the messages claims it is MIME.
|
||||||
// signatures: Array of signatures
|
// info.signatures: Array of signatures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {createKey} from './src/Key';
|
import { createKey } from './src/Key';
|
||||||
|
|
||||||
export const helper_params = {
|
export const helper_params = {
|
||||||
validLongId: '0A0A0A0A0A0A0A0A',
|
validLongId: '0A0A0A0A0A0A0A0A',
|
||||||
@ -9,8 +9,8 @@ export const helper_params = {
|
|||||||
validFingerprints: ['9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A',
|
validFingerprints: ['9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A9A9A7A7A8A',
|
||||||
'9AAE7A338A9A9A7A7A8A9A9A7A7A8A9A9A7A7DDA'],
|
'9AAE7A338A9A9A7A7A8A9A9A7A7A8A9A9A7A7DDA'],
|
||||||
invalidLongId: '9A9A7A7A8A9A9A7A7A8A',
|
invalidLongId: '9A9A7A7A8A9A9A7A7A8A',
|
||||||
invalidFingerprints: [{hello:'World'}, ['kekekeke'], new Uint32Array(40)],
|
invalidFingerprints: [{ hello:'World' }, ['kekekeke'], new Uint32Array(40)],
|
||||||
invalidKeyArray: {curiosity:'uncat'},
|
invalidKeyArray: { curiosity:'uncat' },
|
||||||
invalidKeyArray_OneBad: [
|
invalidKeyArray_OneBad: [
|
||||||
createKey('D41735B91236FDB882048C5A2301635EEFF0CB05'),
|
createKey('D41735B91236FDB882048C5A2301635EEFF0CB05'),
|
||||||
'E1D18E6E994FA9FE9360Bx0E687B940FEFEB095A',
|
'E1D18E6E994FA9FE9360Bx0E687B940FEFEB095A',
|
||||||
@ -18,7 +18,7 @@ export const helper_params = {
|
|||||||
invalidErrorCode: 'Please type in all your passwords.',
|
invalidErrorCode: 'Please type in all your passwords.',
|
||||||
validGPGME_Key: createKey('D41735B91236FDB882048C5A2301635EEFF0CB05', true),
|
validGPGME_Key: createKey('D41735B91236FDB882048C5A2301635EEFF0CB05', true),
|
||||||
valid_openpgplike: { primaryKey: {
|
valid_openpgplike: { primaryKey: {
|
||||||
getFingerprint: function(){
|
getFingerprint: function (){
|
||||||
return '85DE2A8BA5A5AB3A8A7BE2000B8AED24D7534BC2';}
|
return '85DE2A8BA5A5AB3A8A7BE2000B8AED24D7534BC2';}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
* SPDX-License-Identifier: LGPL-2.1+
|
* SPDX-License-Identifier: LGPL-2.1+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import './node_modules/mocha/mocha'; /*global mocha, it, describe*/
|
import './node_modules/mocha/mocha'; /* global mocha, it, describe*/
|
||||||
import './node_modules/chai/chai';/*global chai*/
|
import './node_modules/chai/chai';/* global chai*/
|
||||||
import { helper_params as hp } from './unittest_inputvalues';
|
import { helper_params as hp } from './unittest_inputvalues';
|
||||||
import { message_params as mp } from './unittest_inputvalues';
|
import { message_params as mp } from './unittest_inputvalues';
|
||||||
import { whatever_params as wp } from './unittest_inputvalues';
|
import { whatever_params as wp } from './unittest_inputvalues';
|
||||||
@ -29,18 +29,18 @@ import { gpgme_error } from './src/Errors';
|
|||||||
import { toKeyIdArray , isFingerprint } from './src/Helpers';
|
import { toKeyIdArray , isFingerprint } from './src/Helpers';
|
||||||
import { createKey } from './src/Key';
|
import { createKey } from './src/Key';
|
||||||
import { GPGME_Keyring } from './src/Keyring';
|
import { GPGME_Keyring } from './src/Keyring';
|
||||||
import {GPGME_Message, createMessage} from './src/Message';
|
import { GPGME_Message, createMessage } from './src/Message';
|
||||||
|
|
||||||
mocha.setup('bdd');
|
mocha.setup('bdd');
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
chai.config.includeStack = true;
|
chai.config.includeStack = true;
|
||||||
|
|
||||||
function unittests (){
|
function unittests (){
|
||||||
describe('Connection testing', function(){
|
describe('Connection testing', function (){
|
||||||
|
|
||||||
it('Connecting', function(done) {
|
it('Connecting', function (done) {
|
||||||
let conn0 = new Connection;
|
let conn0 = new Connection;
|
||||||
conn0.checkConnection().then(function(answer) {
|
conn0.checkConnection().then(function (answer) {
|
||||||
expect(answer).to.not.be.empty;
|
expect(answer).to.not.be.empty;
|
||||||
expect(answer.gpgme).to.not.be.undefined;
|
expect(answer.gpgme).to.not.be.undefined;
|
||||||
expect(answer.gpgme).to.be.a('string');
|
expect(answer.gpgme).to.be.a('string');
|
||||||
@ -52,12 +52,12 @@ function unittests (){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Disconnecting', function(done) {
|
it('Disconnecting', function (done) {
|
||||||
let conn0 = new Connection;
|
let conn0 = new Connection;
|
||||||
conn0.checkConnection(false).then(function(answer) {
|
conn0.checkConnection(false).then(function (answer) {
|
||||||
expect(answer).to.be.true;
|
expect(answer).to.be.true;
|
||||||
conn0.disconnect();
|
conn0.disconnect();
|
||||||
conn0.checkConnection(false).then(function(result) {
|
conn0.checkConnection(false).then(function (result) {
|
||||||
expect(result).to.be.false;
|
expect(result).to.be.false;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -65,9 +65,9 @@ function unittests (){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Error Object handling', function(){
|
describe('Error Object handling', function (){
|
||||||
// TODO: new GPGME_Error codes
|
// TODO: new GPGME_Error codes
|
||||||
it('check the Timeout error', function(){
|
it('check the Timeout error', function (){
|
||||||
let test0 = gpgme_error('CONN_TIMEOUT');
|
let test0 = gpgme_error('CONN_TIMEOUT');
|
||||||
|
|
||||||
expect(test0).to.be.an.instanceof(Error);
|
expect(test0).to.be.an.instanceof(Error);
|
||||||
@ -75,7 +75,7 @@ function unittests (){
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Error Object returns generic code if code is not listed',
|
it('Error Object returns generic code if code is not listed',
|
||||||
function(){
|
function (){
|
||||||
let test0 = gpgme_error(hp.invalidErrorCode);
|
let test0 = gpgme_error(hp.invalidErrorCode);
|
||||||
|
|
||||||
expect(test0).to.be.an.instanceof(Error);
|
expect(test0).to.be.an.instanceof(Error);
|
||||||
@ -83,22 +83,22 @@ function unittests (){
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Warnings like PARAM_IGNORED should not return errors', function(){
|
it('Warnings like PARAM_IGNORED should not return errors', function (){
|
||||||
let test0 = gpgme_error('PARAM_IGNORED');
|
let test0 = gpgme_error('PARAM_IGNORED');
|
||||||
|
|
||||||
expect(test0).to.be.null;
|
expect(test0).to.be.null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Fingerprint checking', function(){
|
describe('Fingerprint checking', function (){
|
||||||
|
|
||||||
it('isFingerprint(): valid Fingerprint', function(){
|
it('isFingerprint(): valid Fingerprint', function (){
|
||||||
let test0 = isFingerprint(hp.validFingerprint);
|
let test0 = isFingerprint(hp.validFingerprint);
|
||||||
|
|
||||||
expect(test0).to.be.true;
|
expect(test0).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('isFingerprint(): invalid Fingerprints', function(){
|
it('isFingerprint(): invalid Fingerprints', function (){
|
||||||
for (let i=0; i < hp.invalidFingerprints.length; i++){
|
for (let i=0; i < hp.invalidFingerprints.length; i++){
|
||||||
let test0 = isFingerprint(hp.invalidFingerprints[i]);
|
let test0 = isFingerprint(hp.invalidFingerprints[i]);
|
||||||
|
|
||||||
@ -107,16 +107,16 @@ function unittests (){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toKeyIdArray() (converting input to fingerprint)', function(){
|
describe('toKeyIdArray() (converting input to fingerprint)', function (){
|
||||||
|
|
||||||
it('Correct fingerprint string', function(){
|
it('Correct fingerprint string', function (){
|
||||||
let test0 = toKeyIdArray(hp.validFingerprint);
|
let test0 = toKeyIdArray(hp.validFingerprint);
|
||||||
|
|
||||||
expect(test0).to.be.an('array');
|
expect(test0).to.be.an('array');
|
||||||
expect(test0).to.include(hp.validFingerprint);
|
expect(test0).to.include(hp.validFingerprint);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('openpgpjs-like object', function(){
|
it('openpgpjs-like object', function (){
|
||||||
let test0 = toKeyIdArray(hp.valid_openpgplike);
|
let test0 = toKeyIdArray(hp.valid_openpgplike);
|
||||||
|
|
||||||
expect(test0).to.be.an('array').with.lengthOf(1);
|
expect(test0).to.be.an('array').with.lengthOf(1);
|
||||||
@ -124,33 +124,33 @@ function unittests (){
|
|||||||
hp.valid_openpgplike.primaryKey.getFingerprint());
|
hp.valid_openpgplike.primaryKey.getFingerprint());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Array of valid inputs', function(){
|
it('Array of valid inputs', function (){
|
||||||
let test0 = toKeyIdArray(hp.validKeys);
|
let test0 = toKeyIdArray(hp.validKeys);
|
||||||
expect(test0).to.be.an('array');
|
expect(test0).to.be.an('array');
|
||||||
expect(test0).to.have.lengthOf(hp.validKeys.length);
|
expect(test0).to.have.lengthOf(hp.validKeys.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Incorrect inputs', function(){
|
it('Incorrect inputs', function (){
|
||||||
|
|
||||||
it('valid Long ID', function(){
|
it('valid Long ID', function (){
|
||||||
let test0 = toKeyIdArray(hp.validLongId);
|
let test0 = toKeyIdArray(hp.validLongId);
|
||||||
|
|
||||||
expect(test0).to.be.empty;
|
expect(test0).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalidFingerprint', function(){
|
it('invalidFingerprint', function (){
|
||||||
let test0 = toKeyIdArray(hp.invalidFingerprint);
|
let test0 = toKeyIdArray(hp.invalidFingerprint);
|
||||||
|
|
||||||
expect(test0).to.be.empty;
|
expect(test0).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invalidKeyArray', function(){
|
it('invalidKeyArray', function (){
|
||||||
let test0 = toKeyIdArray(hp.invalidKeyArray);
|
let test0 = toKeyIdArray(hp.invalidKeyArray);
|
||||||
|
|
||||||
expect(test0).to.be.empty;
|
expect(test0).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Partially invalid array', function(){
|
it('Partially invalid array', function (){
|
||||||
let test0 = toKeyIdArray(hp.invalidKeyArray_OneBad);
|
let test0 = toKeyIdArray(hp.invalidKeyArray_OneBad);
|
||||||
|
|
||||||
expect(test0).to.be.an('array');
|
expect(test0).to.be.an('array');
|
||||||
@ -160,10 +160,10 @@ function unittests (){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('GPGME_Key', function(){
|
describe('GPGME_Key', function (){
|
||||||
it('Key has data after a first refresh', function(done) {
|
it('Key has data after a first refresh', function (done) {
|
||||||
let key = createKey(kp.validKeyFingerprint);
|
let key = createKey(kp.validKeyFingerprint);
|
||||||
key.refreshKey().then(function(key2){
|
key.refreshKey().then(function (key2){
|
||||||
expect(key2.get).to.be.a('function');
|
expect(key2.get).to.be.a('function');
|
||||||
for (let i=0; i < kp.validKeyProperties.length; i++) {
|
for (let i=0; i < kp.validKeyProperties.length; i++) {
|
||||||
let prop = key2.get(kp.validKeyProperties[i]);
|
let prop = key2.get(kp.validKeyProperties[i]);
|
||||||
@ -181,7 +181,7 @@ function unittests (){
|
|||||||
|
|
||||||
it('Non-cached key async data retrieval', function (done){
|
it('Non-cached key async data retrieval', function (done){
|
||||||
let key = createKey(kp.validKeyFingerprint, true);
|
let key = createKey(kp.validKeyFingerprint, true);
|
||||||
key.get('can_authenticate').then(function(result){
|
key.get('can_authenticate').then(function (result){
|
||||||
expect(result).to.be.a('boolean');
|
expect(result).to.be.a('boolean');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -189,7 +189,7 @@ function unittests (){
|
|||||||
|
|
||||||
it('Non-cached key async armored Key', function (done){
|
it('Non-cached key async armored Key', function (done){
|
||||||
let key = createKey(kp.validKeyFingerprint, true);
|
let key = createKey(kp.validKeyFingerprint, true);
|
||||||
key.get('armored').then(function(result){
|
key.get('armored').then(function (result){
|
||||||
expect(result).to.be.a('string');
|
expect(result).to.be.a('string');
|
||||||
expect(result).to.include('KEY BLOCK-----');
|
expect(result).to.include('KEY BLOCK-----');
|
||||||
done();
|
done();
|
||||||
@ -198,7 +198,7 @@ function unittests (){
|
|||||||
|
|
||||||
it('Non-cached key async hasSecret', function (done){
|
it('Non-cached key async hasSecret', function (done){
|
||||||
let key = createKey(kp.validKeyFingerprint, true);
|
let key = createKey(kp.validKeyFingerprint, true);
|
||||||
key.get('hasSecret').then(function(result){
|
key.get('hasSecret').then(function (result){
|
||||||
expect(result).to.be.a('boolean');
|
expect(result).to.be.a('boolean');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -206,24 +206,24 @@ function unittests (){
|
|||||||
|
|
||||||
it('Non-cached key async hasSecret (no secret in Key)', function (done){
|
it('Non-cached key async hasSecret (no secret in Key)', function (done){
|
||||||
let key = createKey(kp.validFingerprintNoSecret, true);
|
let key = createKey(kp.validFingerprintNoSecret, true);
|
||||||
key.get('hasSecret').then(function(result){
|
key.get('hasSecret').then(function (result){
|
||||||
expect(result).to.be.a('boolean');
|
expect(result).to.be.a('boolean');
|
||||||
expect(result).to.equal(false);
|
expect(result).to.equal(false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Querying non-existing Key returns an error', function(done) {
|
it('Querying non-existing Key returns an error', function (done) {
|
||||||
let key = createKey(kp.invalidKeyFingerprint);
|
let key = createKey(kp.invalidKeyFingerprint);
|
||||||
key.refreshKey().then(function(){},
|
key.refreshKey().then(function (){},
|
||||||
function(error){
|
function (error){
|
||||||
expect(error).to.be.an.instanceof(Error);
|
expect(error).to.be.an.instanceof(Error);
|
||||||
expect(error.code).to.equal('KEY_NOKEY');
|
expect(error.code).to.equal('KEY_NOKEY');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('createKey returns error if parameters are wrong', function(){
|
it('createKey returns error if parameters are wrong', function (){
|
||||||
for (let i=0; i< 4; i++){
|
for (let i=0; i< 4; i++){
|
||||||
let key0 = createKey(wp.four_invalid_params[i]);
|
let key0 = createKey(wp.four_invalid_params[i]);
|
||||||
expect(key0).to.be.an.instanceof(Error);
|
expect(key0).to.be.an.instanceof(Error);
|
||||||
@ -248,18 +248,18 @@ function unittests (){
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('GPGME_Keyring', function(){
|
describe('GPGME_Keyring', function (){
|
||||||
|
|
||||||
it('correct Keyring initialization', function(){
|
it('correct Keyring initialization', function (){
|
||||||
let keyring = new GPGME_Keyring;
|
let keyring = new GPGME_Keyring;
|
||||||
expect(keyring).to.be.an.instanceof(GPGME_Keyring);
|
expect(keyring).to.be.an.instanceof(GPGME_Keyring);
|
||||||
expect(keyring.getKeys).to.be.a('function');
|
expect(keyring.getKeys).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Loading Keys from Keyring, to be used synchronously',
|
it('Loading Keys from Keyring, to be used synchronously',
|
||||||
function(done){
|
function (done){
|
||||||
let keyring = new GPGME_Keyring;
|
let keyring = new GPGME_Keyring;
|
||||||
keyring.getKeys(null, true).then(function(result){
|
keyring.getKeys(null, true).then(function (result){
|
||||||
expect(result).to.be.an('array');
|
expect(result).to.be.an('array');
|
||||||
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
||||||
done();
|
done();
|
||||||
@ -268,10 +268,10 @@ function unittests (){
|
|||||||
);
|
);
|
||||||
|
|
||||||
it('Loading specific Key from Keyring, to be used synchronously',
|
it('Loading specific Key from Keyring, to be used synchronously',
|
||||||
function(done){
|
function (done){
|
||||||
let keyring = new GPGME_Keyring;
|
let keyring = new GPGME_Keyring;
|
||||||
keyring.getKeys(kp.validKeyFingerprint, true).then(
|
keyring.getKeys(kp.validKeyFingerprint, true).then(
|
||||||
function(result){
|
function (result){
|
||||||
expect(result).to.be.an('array');
|
expect(result).to.be.an('array');
|
||||||
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
expect(result[0].get('hasSecret')).to.be.a('boolean');
|
||||||
done();
|
done();
|
||||||
@ -280,10 +280,10 @@ function unittests (){
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Querying non-existing Key from Keyring', function(done){
|
it('Querying non-existing Key from Keyring', function (done){
|
||||||
let keyring = new GPGME_Keyring;
|
let keyring = new GPGME_Keyring;
|
||||||
keyring.getKeys(kp.invalidKeyFingerprint, true).then(
|
keyring.getKeys(kp.invalidKeyFingerprint, true).then(
|
||||||
function(result){
|
function (result){
|
||||||
expect(result).to.be.an('array');
|
expect(result).to.be.an('array');
|
||||||
expect(result.length).to.equal(0);
|
expect(result.length).to.equal(0);
|
||||||
done();
|
done();
|
||||||
@ -293,16 +293,16 @@ function unittests (){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('GPGME_Message', function(){
|
describe('GPGME_Message', function (){
|
||||||
|
|
||||||
it('creating encrypt Message', function(){
|
it('creating encrypt Message', function (){
|
||||||
let test0 = createMessage('encrypt');
|
let test0 = createMessage('encrypt');
|
||||||
|
|
||||||
expect(test0).to.be.an.instanceof(GPGME_Message);
|
expect(test0).to.be.an.instanceof(GPGME_Message);
|
||||||
expect(test0.isComplete()).to.be.false;
|
expect(test0.isComplete()).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Message is complete after setting mandatory data', function(){
|
it('Message is complete after setting mandatory data', function (){
|
||||||
let test0 = createMessage('encrypt');
|
let test0 = createMessage('encrypt');
|
||||||
test0.setParameter('data', mp.valid_encrypt_data);
|
test0.setParameter('data', mp.valid_encrypt_data);
|
||||||
test0.setParameter('keys', hp.validFingerprints);
|
test0.setParameter('keys', hp.validFingerprints);
|
||||||
@ -310,14 +310,14 @@ function unittests (){
|
|||||||
expect(test0.isComplete()).to.be.true;
|
expect(test0.isComplete()).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Message is not complete after mandatory data is empty', function(){
|
it('Message is not complete after mandatory data is empty', function (){
|
||||||
let test0 = createMessage('encrypt');
|
let test0 = createMessage('encrypt');
|
||||||
test0.setParameter('data', '');
|
test0.setParameter('data', '');
|
||||||
test0.setParameter('keys', hp.validFingerprints);
|
test0.setParameter('keys', hp.validFingerprints);
|
||||||
expect(test0.isComplete()).to.be.false;
|
expect(test0.isComplete()).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Complete Message contains the data that was set', function(){
|
it('Complete Message contains the data that was set', function (){
|
||||||
let test0 = createMessage('encrypt');
|
let test0 = createMessage('encrypt');
|
||||||
test0.setParameter('data', mp.valid_encrypt_data);
|
test0.setParameter('data', mp.valid_encrypt_data);
|
||||||
test0.setParameter('keys', hp.validFingerprints);
|
test0.setParameter('keys', hp.validFingerprints);
|
||||||
@ -330,20 +330,20 @@ function unittests (){
|
|||||||
mp.valid_encrypt_data);
|
mp.valid_encrypt_data);
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('Not accepting non-allowed operation', function(){
|
it ('Not accepting non-allowed operation', function (){
|
||||||
let test0 = createMessage(mp.invalid_op_action);
|
let test0 = createMessage(mp.invalid_op_action);
|
||||||
|
|
||||||
expect(test0).to.be.an.instanceof(Error);
|
expect(test0).to.be.an.instanceof(Error);
|
||||||
expect(test0.code).to.equal('MSG_WRONG_OP');
|
expect(test0.code).to.equal('MSG_WRONG_OP');
|
||||||
});
|
});
|
||||||
it('Not accepting wrong parameter type', function(){
|
it('Not accepting wrong parameter type', function (){
|
||||||
let test0 = createMessage(mp.invalid_op_type);
|
let test0 = createMessage(mp.invalid_op_type);
|
||||||
|
|
||||||
expect(test0).to.be.an.instanceof(Error);
|
expect(test0).to.be.an.instanceof(Error);
|
||||||
expect(test0.code).to.equal('PARAM_WRONG');
|
expect(test0.code).to.equal('PARAM_WRONG');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Not accepting wrong parameter name', function(){
|
it('Not accepting wrong parameter name', function (){
|
||||||
let test0 = createMessage(mp.invalid_param_test.valid_op);
|
let test0 = createMessage(mp.invalid_param_test.valid_op);
|
||||||
for (let i=0;
|
for (let i=0;
|
||||||
i < mp.invalid_param_test.invalid_param_names.length; i++){
|
i < mp.invalid_param_test.invalid_param_names.length; i++){
|
||||||
@ -356,7 +356,7 @@ function unittests (){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Not accepting wrong parameter value', function(){
|
it('Not accepting wrong parameter value', function (){
|
||||||
let test0 = createMessage(mp.invalid_param_test.valid_op);
|
let test0 = createMessage(mp.invalid_param_test.valid_op);
|
||||||
for (let j=0;
|
for (let j=0;
|
||||||
j < mp.invalid_param_test.invalid_values_0.length; j++){
|
j < mp.invalid_param_test.invalid_values_0.length; j++){
|
||||||
@ -372,4 +372,4 @@ function unittests (){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {unittests};
|
export default { unittests };
|
Loading…
Reference in New Issue
Block a user