Merge pull request #105 from dcposch/master
Fixed ASCII armor decoding bug
This commit is contained in:
commit
14e50a4661
|
@ -32,29 +32,42 @@ function openpgp_encoding_deArmor(text) {
|
||||||
|
|
||||||
if (type != 2) {
|
if (type != 2) {
|
||||||
var splittedtext = text.split('-----');
|
var splittedtext = text.split('-----');
|
||||||
|
// splittedtext[0] - should be the empty string
|
||||||
|
// splittedtext[1] - should be BEGIN...
|
||||||
|
// splittedtext[2] - the message and checksum
|
||||||
|
// splittedtest[3] - should be END...
|
||||||
|
|
||||||
|
// chunks separated by blank lines
|
||||||
|
var splittedChunks = splittedtext[2]
|
||||||
|
.split('\n\n');
|
||||||
|
var messageAndChecksum = splittedtext[2]
|
||||||
|
.split('\n\n')[1]
|
||||||
|
.split('\n=');
|
||||||
|
|
||||||
|
var message = messageAndChecksum[0]
|
||||||
|
.replace(/\n- /g,"\n");
|
||||||
|
// sometimes, there's a blank line between message and checksum
|
||||||
|
var checksum;
|
||||||
|
if(messageAndChecksum.length == 1){
|
||||||
|
// blank line
|
||||||
|
checksum = splittedtext[2]
|
||||||
|
.replace(/[\n=]/g, "");
|
||||||
|
} else {
|
||||||
|
// no blank line
|
||||||
|
checksum = messageAndChecksum[1]
|
||||||
|
.split('\n')[0];
|
||||||
|
}
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
openpgp: openpgp_encoding_base64_decode(
|
openpgp: openpgp_encoding_base64_decode(message)
|
||||||
splittedtext[2]
|
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[0]
|
|
||||||
.replace(/\n- /g,"\n")),
|
|
||||||
type: type
|
type: type
|
||||||
};
|
};
|
||||||
|
|
||||||
if (verifyCheckSum(data.openpgp,
|
if (verifyCheckSum(data.openpgp, checksum)) {
|
||||||
splittedtext[2]
|
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[1]
|
|
||||||
.split('\n')[0]))
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
else {
|
} else {
|
||||||
util.print_error("Ascii armor integrity check on message failed: '"
|
util.print_error("Ascii armor integrity check on message failed: '"
|
||||||
+ splittedtext[2]
|
+ checksum
|
||||||
.split('\n\n')[1]
|
|
||||||
.split("\n=")[1]
|
|
||||||
.split('\n')[0]
|
|
||||||
+ "' should be '"
|
+ "' should be '"
|
||||||
+ getCheckSum(data)) + "'";
|
+ getCheckSum(data)) + "'";
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user