Accept armor header with trailing whitespace

This commit is contained in:
Thomas Oberndörfer 2014-04-04 16:00:26 +02:00
parent 86537fb48c
commit ced145865e
2 changed files with 30 additions and 3 deletions

View File

@ -278,7 +278,8 @@ function splitChecksum(text) {
function dearmor(text) {
var reSplit = /^-----[^-]+-----$\n/m;
text = text.replace(/\r/g, '');
// remove trailing whitespace at end of line
text = text.replace(/[\t\r ]+\n/g, '\n');
var type = getType(text);
@ -307,8 +308,8 @@ function dearmor(text) {
checksum = msg_sum.checksum;
} else {
// Reverse dash-escaping for msg and remove trailing whitespace (0x20) and tabs (0x09) at end of line
msg = splitHeaders(splittext[indexBase].replace(/^- /mg, '').replace(/[\t ]+\n/g, "\n"));
// Reverse dash-escaping for msg
msg = splitHeaders(splittext[indexBase].replace(/^- /mg, ''));
var sig = splitHeaders(splittext[indexBase + 1].replace(/^- /mg, ''));
verifyHeaders(sig.headers);
var sig_sum = splitChecksum(sig.body);

View File

@ -157,6 +157,32 @@ describe("ASCII armor", function() {
expect(result.err[0].message).to.match(/Ascii armor integrity check on message failed/);
});
it('Accept header with trailing whitespace', function () {
var privKey =
['-----BEGIN PGP PRIVATE KEY BLOCK-----\t \r',
'Version: OpenPGP.js v0.3.0',
'Comment: http://openpgpjs.org',
'',
'xbYEUubX7gEBANDWhzoP+Tr/IyRSv++vl5jBesQIPTYGQBdzF4YDnGEBABEB',
'AAH+CQMIfzdw4/PKNl5gVXdtfDFdSIN8yJT2rbeg3+SsWexXZNNdRaONWaiB',
'Z5cG9Q6+BoXKsEshIdcYOgwsAgRxlPpRA34Vvmg2QBk7PhdrkbK7aqENsJ1w',
'dIlLD6p9GmLE20yVff58/fMiUtPRgsD83SpKTAX6EM1ulpkuQQNjmrVc5qc8',
'7AMdF80JdW5kZWZpbmVkwj8EEAEIABMFAlLm1+4JEBD8MASZrpALAhsDAAAs',
'QgD8CUrwv7Hrp/INR0/UvAvzS52VztREQwQWTJMrgTNHBGjHtgRS5tfuAQEA',
'nys9SaSgR+l6iZc/M8hGIUmbuahE2/+mtw+/l0RO+WcAEQEAAf4JAwjr39Yi',
'FzjxImDN1IoYVsonA9M+BtIIJHafuQUHjyEr1paJJK5xS6KlyGgpMTXTD6y/',
'qxS3ZSPPzHGRrs2CmkVEiPmurn9Ed05tb0y9OnJkWtuh3z9VVq9d8zHzuENa',
'bUfli+P/v+dRaZ+1rSOxUFbFYbFB5XK/A9b/OPFrv+mb4KrtLxugwj8EGAEI',
'ABMFAlLm1+4JEBD8MASZrpALAhsMAAC3IgD8DnLGbMnpLtrX72RCkPW1ffLq',
'71vlXMJNXvoCeuejiRw=',
'=wJNM',
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
var result = openpgp.key.readArmored(privKey);
expect(result.err).to.not.exist;
expect(result.keys[0]).to.be.an.instanceof(openpgp.key.Key);
});
});