Merge pull request #232 from msjoinder/single_public_key
API accepts a single public key or an array
This commit is contained in:
commit
68a5739354
|
@ -1,23 +1,23 @@
|
||||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||||
// Copyright (C) 2011 Recurity Labs GmbH
|
// Copyright (C) 2011 Recurity Labs GmbH
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or
|
// This library is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
// License as published by the Free Software Foundation; either
|
// License as published by the Free Software Foundation; either
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This library is distributed in the hope that it will be useful,
|
// This library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// Lesser General Public License for more details.
|
// Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview The openpgp base module should provide all of the functionality
|
* @fileoverview The openpgp base module should provide all of the functionality
|
||||||
* to consume the openpgp.js library. All additional classes are documented
|
* to consume the openpgp.js library. All additional classes are documented
|
||||||
* for extending and developing on top of the base library.
|
* for extending and developing on top of the base library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -52,13 +52,17 @@ function initWorker(path) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypts message text with keys
|
* Encrypts message text with keys
|
||||||
* @param {Array<module:key~Key>} keys array of keys, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
||||||
* @param {String} text message as native JavaScript string
|
* @param {String} text message as native JavaScript string
|
||||||
* @param {function} callback (optional) callback(error, result) for async style
|
* @param {function} callback (optional) callback(error, result) for async style
|
||||||
* @return {String} encrypted ASCII armored message
|
* @return {String} encrypted ASCII armored message
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function encryptMessage(keys, text, callback) {
|
function encryptMessage(keys, text, callback) {
|
||||||
|
if (!keys.length) {
|
||||||
|
keys = [keys];
|
||||||
|
}
|
||||||
|
|
||||||
if (useWorker(callback)) {
|
if (useWorker(callback)) {
|
||||||
asyncProxy.encryptMessage(keys, text, callback);
|
asyncProxy.encryptMessage(keys, text, callback);
|
||||||
return;
|
return;
|
||||||
|
@ -75,7 +79,7 @@ function encryptMessage(keys, text, callback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs message text and encrypts it
|
* Signs message text and encrypts it
|
||||||
* @param {Array<module:key~Key>} publicKeys array of keys, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key, used to encrypt the message
|
||||||
* @param {module:key~Key} privateKey private key with decrypted secret key data for signing
|
* @param {module:key~Key} privateKey private key with decrypted secret key data for signing
|
||||||
* @param {String} text message as native JavaScript string
|
* @param {String} text message as native JavaScript string
|
||||||
* @param {function} callback (optional) callback(error, result) for async style
|
* @param {function} callback (optional) callback(error, result) for async style
|
||||||
|
@ -83,6 +87,10 @@ function encryptMessage(keys, text, callback) {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function signAndEncryptMessage(publicKeys, privateKey, text, callback) {
|
function signAndEncryptMessage(publicKeys, privateKey, text, callback) {
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
|
|
||||||
if (useWorker(callback)) {
|
if (useWorker(callback)) {
|
||||||
asyncProxy.signAndEncryptMessage(publicKeys, privateKey, text, callback);
|
asyncProxy.signAndEncryptMessage(publicKeys, privateKey, text, callback);
|
||||||
return;
|
return;
|
||||||
|
@ -122,7 +130,7 @@ function decryptMessage(privateKey, msg, callback) {
|
||||||
/**
|
/**
|
||||||
* Decrypts message and verifies signatures
|
* Decrypts message and verifies signatures
|
||||||
* @param {module:key~Key} privateKey private key with decrypted secret key data
|
* @param {module:key~Key} privateKey private key with decrypted secret key data
|
||||||
* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key, to verify signatures
|
||||||
* @param {module:message~Message} msg the message object with signed and encrypted data
|
* @param {module:message~Message} msg the message object with signed and encrypted data
|
||||||
* @param {function} callback (optional) callback(error, result) for async style
|
* @param {function} callback (optional) callback(error, result) for async style
|
||||||
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}
|
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}
|
||||||
|
@ -131,6 +139,10 @@ function decryptMessage(privateKey, msg, callback) {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function decryptAndVerifyMessage(privateKey, publicKeys, msg, callback) {
|
function decryptAndVerifyMessage(privateKey, publicKeys, msg, callback) {
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
|
|
||||||
if (useWorker(callback)) {
|
if (useWorker(callback)) {
|
||||||
asyncProxy.decryptAndVerifyMessage(privateKey, publicKeys, msg, callback);
|
asyncProxy.decryptAndVerifyMessage(privateKey, publicKeys, msg, callback);
|
||||||
return;
|
return;
|
||||||
|
@ -150,13 +162,17 @@ function decryptAndVerifyMessage(privateKey, publicKeys, msg, callback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs a cleartext message
|
* Signs a cleartext message
|
||||||
* @param {Array<module:key~Key>} privateKeys private key with decrypted secret key data to sign cleartext
|
* @param {(Array<module:key~Key>|module:key~Key)} privateKeys array of keys or single key with decrypted secret key data to sign cleartext
|
||||||
* @param {String} text cleartext
|
* @param {String} text cleartext
|
||||||
* @param {function} callback (optional) callback(error, result) for async style
|
* @param {function} callback (optional) callback(error, result) for async style
|
||||||
* @return {String} ASCII armored message
|
* @return {String} ASCII armored message
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function signClearMessage(privateKeys, text, callback) {
|
function signClearMessage(privateKeys, text, callback) {
|
||||||
|
if (!privateKeys.length) {
|
||||||
|
privateKeys = [privateKeys];
|
||||||
|
}
|
||||||
|
|
||||||
if (useWorker(callback)) {
|
if (useWorker(callback)) {
|
||||||
asyncProxy.signClearMessage(privateKeys, text, callback);
|
asyncProxy.signClearMessage(privateKeys, text, callback);
|
||||||
return;
|
return;
|
||||||
|
@ -171,7 +187,7 @@ function signClearMessage(privateKeys, text, callback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies signatures of cleartext signed message
|
* Verifies signatures of cleartext signed message
|
||||||
* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key, to verify signatures
|
||||||
* @param {module:cleartext~CleartextMessage} msg cleartext message object with signatures
|
* @param {module:cleartext~CleartextMessage} msg cleartext message object with signatures
|
||||||
* @param {function} callback (optional) callback(error, result) for async style
|
* @param {function} callback (optional) callback(error, result) for async style
|
||||||
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}
|
* @return {{text: String, signatures: Array<{keyid: module:type/keyid, valid: Boolean}>}}
|
||||||
|
@ -179,6 +195,10 @@ function signClearMessage(privateKeys, text, callback) {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function verifyClearSignedMessage(publicKeys, msg, callback) {
|
function verifyClearSignedMessage(publicKeys, msg, callback) {
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
|
|
||||||
if (useWorker(callback)) {
|
if (useWorker(callback)) {
|
||||||
asyncProxy.verifyClearSignedMessage(publicKeys, msg, callback);
|
asyncProxy.verifyClearSignedMessage(publicKeys, msg, callback);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
// GPG4Browsers - An OpenPGP implementation in javascript
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
||||||
// Copyright (C) 2011 Recurity Labs GmbH
|
// Copyright (C) 2011 Recurity Labs GmbH
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or
|
// This library is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
// License as published by the Free Software Foundation; either
|
// License as published by the Free Software Foundation; either
|
||||||
// version 2.1 of the License, or (at your option) any later version.
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This library is distributed in the hope that it will be useful,
|
// This library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// Lesser General Public License for more details.
|
// Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
@ -53,7 +53,7 @@ function AsyncProxy(path) {
|
||||||
* Message handling
|
* Message handling
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.onMessage = function(event) {
|
AsyncProxy.prototype.onMessage = function(event) {
|
||||||
var msg = event.data;
|
var msg = event.data;
|
||||||
switch (msg.event) {
|
switch (msg.event) {
|
||||||
case 'method-return':
|
case 'method-return':
|
||||||
this.tasks.shift()(msg.err ? new Error(msg.err) : null, msg.data);
|
this.tasks.shift()(msg.err ? new Error(msg.err) : null, msg.data);
|
||||||
|
@ -96,16 +96,19 @@ AsyncProxy.prototype.terminate = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypts message text with keys
|
* Encrypts message text with keys
|
||||||
* @param {Array<module:key~Key>} keys array of keys, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} keys array of keys or single key, used to encrypt the message
|
||||||
* @param {String} text message as native JavaScript string
|
* @param {String} text message as native JavaScript string
|
||||||
* @param {Function} callback receives encrypted ASCII armored message
|
* @param {Function} callback receives encrypted ASCII armored message
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.encryptMessage = function(keys, text, callback) {
|
AsyncProxy.prototype.encryptMessage = function(keys, text, callback) {
|
||||||
|
if (!keys.length) {
|
||||||
|
keys = [keys];
|
||||||
|
}
|
||||||
keys = keys.map(function(key) {
|
keys = keys.map(function(key) {
|
||||||
return key.toPacketlist();
|
return key.toPacketlist();
|
||||||
});
|
});
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'encrypt-message',
|
event: 'encrypt-message',
|
||||||
keys: keys,
|
keys: keys,
|
||||||
text: text
|
text: text
|
||||||
});
|
});
|
||||||
|
@ -114,18 +117,21 @@ AsyncProxy.prototype.encryptMessage = function(keys, text, callback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs message text and encrypts it
|
* Signs message text and encrypts it
|
||||||
* @param {Array<module:key~Key>} publicKeys array of keys, used to encrypt the message
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key, used to encrypt the message
|
||||||
* @param {module:key~Key} privateKey private key with decrypted secret key data for signing
|
* @param {module:key~Key} privateKey private key with decrypted secret key data for signing
|
||||||
* @param {String} text message as native JavaScript string
|
* @param {String} text message as native JavaScript string
|
||||||
* @param {Function} callback receives encrypted ASCII armored message
|
* @param {Function} callback receives encrypted ASCII armored message
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.signAndEncryptMessage = function(publicKeys, privateKey, text, callback) {
|
AsyncProxy.prototype.signAndEncryptMessage = function(publicKeys, privateKey, text, callback) {
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
publicKeys = publicKeys.map(function(key) {
|
publicKeys = publicKeys.map(function(key) {
|
||||||
return key.toPacketlist();
|
return key.toPacketlist();
|
||||||
});
|
});
|
||||||
privateKey = privateKey.toPacketlist();
|
privateKey = privateKey.toPacketlist();
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'sign-and-encrypt-message',
|
event: 'sign-and-encrypt-message',
|
||||||
publicKeys: publicKeys,
|
publicKeys: publicKeys,
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
text: text
|
text: text
|
||||||
|
@ -143,7 +149,7 @@ AsyncProxy.prototype.signAndEncryptMessage = function(publicKeys, privateKey, te
|
||||||
AsyncProxy.prototype.decryptMessage = function(privateKey, message, callback) {
|
AsyncProxy.prototype.decryptMessage = function(privateKey, message, callback) {
|
||||||
privateKey = privateKey.toPacketlist();
|
privateKey = privateKey.toPacketlist();
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'decrypt-message',
|
event: 'decrypt-message',
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
|
@ -153,18 +159,21 @@ AsyncProxy.prototype.decryptMessage = function(privateKey, message, callback) {
|
||||||
/**
|
/**
|
||||||
* Decrypts message and verifies signatures
|
* Decrypts message and verifies signatures
|
||||||
* @param {module:key~Key} privateKey private key with decrypted secret key data
|
* @param {module:key~Key} privateKey private key with decrypted secret key data
|
||||||
* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key to verify signatures
|
||||||
* @param {module:message~Message} message the message object with signed and encrypted data
|
* @param {module:message~Message} message the message object with signed and encrypted data
|
||||||
* @param {Function} callback receives decrypted message as as native JavaScript string
|
* @param {Function} callback receives decrypted message as as native JavaScript string
|
||||||
* with verified signatures or null if no literal data found
|
* with verified signatures or null if no literal data found
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.decryptAndVerifyMessage = function(privateKey, publicKeys, message, callback) {
|
AsyncProxy.prototype.decryptAndVerifyMessage = function(privateKey, publicKeys, message, callback) {
|
||||||
privateKey = privateKey.toPacketlist();
|
privateKey = privateKey.toPacketlist();
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
publicKeys = publicKeys.map(function(key) {
|
publicKeys = publicKeys.map(function(key) {
|
||||||
return key.toPacketlist();
|
return key.toPacketlist();
|
||||||
});
|
});
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'decrypt-and-verify-message',
|
event: 'decrypt-and-verify-message',
|
||||||
privateKey: privateKey,
|
privateKey: privateKey,
|
||||||
publicKeys: publicKeys,
|
publicKeys: publicKeys,
|
||||||
message: message
|
message: message
|
||||||
|
@ -182,16 +191,19 @@ AsyncProxy.prototype.decryptAndVerifyMessage = function(privateKey, publicKeys,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs a cleartext message
|
* Signs a cleartext message
|
||||||
* @param {Array<module:key~Key>} privateKeys private key with decrypted secret key data to sign cleartext
|
* @param {(Array<module:key~Key>|module:key~Key)} privateKeys array of keys or single key, with decrypted secret key data to sign cleartext
|
||||||
* @param {String} text cleartext
|
* @param {String} text cleartext
|
||||||
* @param {Function} callback receives ASCII armored message
|
* @param {Function} callback receives ASCII armored message
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.signClearMessage = function(privateKeys, text, callback) {
|
AsyncProxy.prototype.signClearMessage = function(privateKeys, text, callback) {
|
||||||
|
if (!privateKeys.length) {
|
||||||
|
privateKeys = [privateKeys];
|
||||||
|
}
|
||||||
privateKeys = privateKeys.map(function(key) {
|
privateKeys = privateKeys.map(function(key) {
|
||||||
return key.toPacketlist();
|
return key.toPacketlist();
|
||||||
});
|
});
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'sign-clear-message',
|
event: 'sign-clear-message',
|
||||||
privateKeys: privateKeys,
|
privateKeys: privateKeys,
|
||||||
text: text
|
text: text
|
||||||
});
|
});
|
||||||
|
@ -200,16 +212,19 @@ AsyncProxy.prototype.signClearMessage = function(privateKeys, text, callback) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies signatures of cleartext signed message
|
* Verifies signatures of cleartext signed message
|
||||||
* @param {Array<module:key~Key>} publicKeys public keys to verify signatures
|
* @param {(Array<module:key~Key>|module:key~Key)} publicKeys array of keys or single key, to verify signatures
|
||||||
* @param {module:cleartext~CleartextMessage} message cleartext message object with signatures
|
* @param {module:cleartext~CleartextMessage} message cleartext message object with signatures
|
||||||
* @param {Function} callback receives cleartext with status of verified signatures
|
* @param {Function} callback receives cleartext with status of verified signatures
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.verifyClearSignedMessage = function(publicKeys, message, callback) {
|
AsyncProxy.prototype.verifyClearSignedMessage = function(publicKeys, message, callback) {
|
||||||
|
if (!publicKeys.length) {
|
||||||
|
publicKeys = [publicKeys];
|
||||||
|
}
|
||||||
publicKeys = publicKeys.map(function(key) {
|
publicKeys = publicKeys.map(function(key) {
|
||||||
return key.toPacketlist();
|
return key.toPacketlist();
|
||||||
});
|
});
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'verify-clear-signed-message',
|
event: 'verify-clear-signed-message',
|
||||||
publicKeys: publicKeys,
|
publicKeys: publicKeys,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
|
@ -236,7 +251,7 @@ AsyncProxy.prototype.verifyClearSignedMessage = function(publicKeys, message, ca
|
||||||
*/
|
*/
|
||||||
AsyncProxy.prototype.generateKeyPair = function(options, callback) {
|
AsyncProxy.prototype.generateKeyPair = function(options, callback) {
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
event: 'generate-key-pair',
|
event: 'generate-key-pair',
|
||||||
options: options
|
options: options
|
||||||
});
|
});
|
||||||
this.tasks.push(function(err, data) {
|
this.tasks.push(function(err, data) {
|
||||||
|
|
|
@ -38,6 +38,9 @@ onmessage = function (event) {
|
||||||
break;
|
break;
|
||||||
case 'encrypt-message':
|
case 'encrypt-message':
|
||||||
try {
|
try {
|
||||||
|
if (!msg.keys.length) {
|
||||||
|
msg.keys = [msg.keys];
|
||||||
|
}
|
||||||
msg.keys = msg.keys.map(packetlistCloneToKey);
|
msg.keys = msg.keys.map(packetlistCloneToKey);
|
||||||
data = window.openpgp.encryptMessage(msg.keys, msg.text);
|
data = window.openpgp.encryptMessage(msg.keys, msg.text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -47,6 +50,9 @@ onmessage = function (event) {
|
||||||
break;
|
break;
|
||||||
case 'sign-and-encrypt-message':
|
case 'sign-and-encrypt-message':
|
||||||
try {
|
try {
|
||||||
|
if (!msg.publicKeys.length) {
|
||||||
|
msg.publicKeys = [msg.publicKeys];
|
||||||
|
}
|
||||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||||
data = window.openpgp.signAndEncryptMessage(msg.publicKeys, msg.privateKey, msg.text);
|
data = window.openpgp.signAndEncryptMessage(msg.publicKeys, msg.privateKey, msg.text);
|
||||||
|
@ -68,6 +74,9 @@ onmessage = function (event) {
|
||||||
case 'decrypt-and-verify-message':
|
case 'decrypt-and-verify-message':
|
||||||
try {
|
try {
|
||||||
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
msg.privateKey = packetlistCloneToKey(msg.privateKey);
|
||||||
|
if (!msg.publicKeys.length) {
|
||||||
|
msg.publicKeys = [msg.publicKeys];
|
||||||
|
}
|
||||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||||
msg.message = packetlistCloneToMessage(msg.message.packets);
|
msg.message = packetlistCloneToMessage(msg.message.packets);
|
||||||
data = window.openpgp.decryptAndVerifyMessage(msg.privateKey, msg.publicKeys, msg.message);
|
data = window.openpgp.decryptAndVerifyMessage(msg.privateKey, msg.publicKeys, msg.message);
|
||||||
|
@ -87,6 +96,9 @@ onmessage = function (event) {
|
||||||
break;
|
break;
|
||||||
case 'verify-clear-signed-message':
|
case 'verify-clear-signed-message':
|
||||||
try {
|
try {
|
||||||
|
if (!msg.publicKeys.length) {
|
||||||
|
msg.publicKeys = [msg.publicKeys];
|
||||||
|
}
|
||||||
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
msg.publicKeys = msg.publicKeys.map(packetlistCloneToKey);
|
||||||
var packetlist = window.openpgp.packet.List.fromStructuredClone(msg.message.packets);
|
var packetlist = window.openpgp.packet.List.fromStructuredClone(msg.message.packets);
|
||||||
msg.message = new window.openpgp.cleartext.CleartextMessage(msg.message.text, packetlist);
|
msg.message = new window.openpgp.cleartext.CleartextMessage(msg.message.text, packetlist);
|
||||||
|
|
|
@ -194,6 +194,17 @@ describe('High level API', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('RSA: encryptMessage one key async', function (done) {
|
||||||
|
openpgp.encryptMessage(pubKeyRSA, plaintext, function(err, data) {
|
||||||
|
expect(err).to.not.exist;
|
||||||
|
expect(data).to.exist;
|
||||||
|
expect(data).to.match(/^-----BEGIN PGP MESSAGE/);
|
||||||
|
var msg = openpgp.message.readArmored(data);
|
||||||
|
expect(msg).to.be.an.instanceof(openpgp.message.Message);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('RSA: encryptMessage sync', function () {
|
it('RSA: encryptMessage sync', function () {
|
||||||
var msg = openpgp.encryptMessage([pubKeyRSA], plaintext);
|
var msg = openpgp.encryptMessage([pubKeyRSA], plaintext);
|
||||||
expect(msg).to.exist;
|
expect(msg).to.exist;
|
||||||
|
@ -202,6 +213,14 @@ describe('High level API', function() {
|
||||||
expect(msg).to.be.an.instanceof(openpgp.message.Message);
|
expect(msg).to.be.an.instanceof(openpgp.message.Message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('RSA: encryptMessage one key sync', function () {
|
||||||
|
var msg = openpgp.encryptMessage(pubKeyRSA, plaintext);
|
||||||
|
expect(msg).to.exist;
|
||||||
|
expect(msg).to.match(/^-----BEGIN PGP MESSAGE/);
|
||||||
|
msg = openpgp.message.readArmored(msg);
|
||||||
|
expect(msg).to.be.an.instanceof(openpgp.message.Message);
|
||||||
|
});
|
||||||
|
|
||||||
it('ELG: encryptMessage async', function (done) {
|
it('ELG: encryptMessage async', function (done) {
|
||||||
openpgp.encryptMessage([pubKeyDE], plaintext, function(err, data) {
|
openpgp.encryptMessage([pubKeyDE], plaintext, function(err, data) {
|
||||||
expect(err).to.not.exist;
|
expect(err).to.not.exist;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user