Code refactoring

This commit is contained in:
RainLoop Team 2015-02-03 03:58:58 +04:00
parent 79233ad83c
commit 286ab567af
53 changed files with 618 additions and 581 deletions

View file

@ -2,96 +2,108 @@
'use strict';
// var
// window = require('window')
// ;
var
ko = require('ko')
;
/**
* @constructor
*/
function PgpUserStore()
{
this.capaOpenPGP = ko.observable(false);
this.openpgp = null;
this.keyring = [];
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
this.openpgpkeysPublic = this.openpgpkeys.filter(function (oItem) {
return !!(oItem && !oItem.isPrivate);
});
this.openpgpkeysPrivate = this.openpgpkeys.filter(function (oItem) {
return !!(oItem && oItem.isPrivate);
});
}
PgpUserStore.prototype.sign = function (sText, oPrivateKey)
{
try
{
return this.openpgp.signClearMessage([oPrivateKey], sText);
}
catch (oExc) {}
return sText;
};
PgpUserStore.prototype.encrypt = function (sText, aPublicKeys)
{
try
{
return this.openpgp.encryptMessage(aPublicKeys, sText);
}
catch (oExc) {}
return sText;
};
PgpUserStore.prototype.signAndEncrypt = function (sText, aPublicKeys, oPrivateKey)
{
try
{
return this.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, sText);
}
catch (oExc) {}
return sText;
};
/**/
PgpUserStore.prototype.verify = function (sText, aPublicKeys)
{
var
mPgpMessage = null
;
try
{
mPgpMessage = this.openpgp.cleartext.readArmored(sText);
if (mPgpMessage && mPgpMessage.getText)
{
mPgpMessage.verify(aPublicKeys);
}
}
catch (oExc) {}
return false;
};
PgpUserStore.prototype.decryptAndVerify = function (sEnctyptedText, aPublicKeys, oPivateKey)
{
var
mPgpMessageDecrypted = null,
mPgpMessage = null
;
try
{
mPgpMessage = this.openpgp.message.readArmored(sEnctyptedText);
if (mPgpMessage && oPivateKey && mPgpMessage.decrypt)
{
mPgpMessageDecrypted = mPgpMessage.decrypt(oPivateKey);
if (mPgpMessageDecrypted)
{
mPgpMessageDecrypted.verify(aPublicKeys);
}
}
}
catch (oExc) {}
return false;
};
// PgpUserStore.prototype.sign = function (sText, oPrivateKey)
// {
// try
// {
// return this.openpgp.signClearMessage([oPrivateKey], sText);
// }
// catch (oExc) {}
//
// return sText;
// };
//
// PgpUserStore.prototype.encrypt = function (sText, aPublicKeys)
// {
// try
// {
// return this.openpgp.encryptMessage(aPublicKeys, sText);
// }
// catch (oExc) {}
//
// return sText;
// };
//
// PgpUserStore.prototype.signAndEncrypt = function (sText, aPublicKeys, oPrivateKey)
// {
// try
// {
// return this.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, sText);
// }
// catch (oExc) {}
//
// return sText;
// };
//
// /**/
//
// PgpUserStore.prototype.verify = function (sText, aPublicKeys)
// {
// var
// mPgpMessage = null
// ;
//
// try
// {
// mPgpMessage = this.openpgp.cleartext.readArmored(sText);
// if (mPgpMessage && mPgpMessage.getText)
// {
// mPgpMessage.verify(aPublicKeys);
// }
// }
// catch (oExc) {}
//
// return false;
// };
//
// PgpUserStore.prototype.decryptAndVerify = function (sEnctyptedText, aPublicKeys, oPivateKey)
// {
// var
// mPgpMessageDecrypted = null,
// mPgpMessage = null
// ;
//
// try
// {
// mPgpMessage = this.openpgp.message.readArmored(sEnctyptedText);
// if (mPgpMessage && oPivateKey && mPgpMessage.decrypt)
// {
// mPgpMessageDecrypted = mPgpMessage.decrypt(oPivateKey);
// if (mPgpMessageDecrypted)
// {
// mPgpMessageDecrypted.verify(aPublicKeys);
// }
// }
// }
// catch (oExc) {}
//
// return false;
// };
/**
* @return {boolean}