mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 22:17:03 +03:00
Pre release fixes and improvements
This commit is contained in:
parent
67c5e31e58
commit
abddb3d828
61 changed files with 378 additions and 57 deletions
107
dev/Stores/User/Pgp.js
Normal file
107
dev/Stores/User/Pgp.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
// var
|
||||
// window = require('window')
|
||||
// ;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function PgpUserStore()
|
||||
{
|
||||
this.openpgp = null;
|
||||
this.keyring = [];
|
||||
}
|
||||
|
||||
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}
|
||||
*/
|
||||
PgpUserStore.prototype.isSupported = function ()
|
||||
{
|
||||
return !!this.openpgp;
|
||||
};
|
||||
|
||||
module.exports = new PgpUserStore();
|
||||
|
||||
}());
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue