commit
80aab5d94f
|
@ -86,15 +86,17 @@ Literal.prototype.setBytes = function(bytes, format) {
|
|||
* Get the byte sequence representing the literal packet data
|
||||
* @returns {Uint8Array} A sequence of bytes
|
||||
*/
|
||||
Literal.prototype.getBytes = function() {
|
||||
Literal.prototype.getBytes = function(textMode=false) {
|
||||
if (this.data !== null) {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
// normalize EOL to \r\n
|
||||
const text = util.canonicalizeEOL(this.text);
|
||||
// encode UTF8
|
||||
this.data = util.str_to_Uint8Array(util.encode_utf8(text));
|
||||
if (textMode) {
|
||||
// normalize EOL to \r\n and UTF-8 encode
|
||||
this.data = util.str_to_Uint8Array(util.encode_utf8(util.canonicalizeEOL(this.text)));
|
||||
} else {
|
||||
this.data = util.str_to_Uint8Array(this.text);
|
||||
}
|
||||
return this.data;
|
||||
};
|
||||
|
||||
|
@ -148,7 +150,7 @@ Literal.prototype.write = function() {
|
|||
|
||||
const format = new Uint8Array([enums.write(enums.literal, this.format)]);
|
||||
const date = util.writeDate(this.date);
|
||||
const data = this.getBytes();
|
||||
const data = this.getBytes(format !== 'binary');
|
||||
|
||||
return util.concatUint8Array([format, filename_length, filename, date, data]);
|
||||
};
|
||||
|
|
|
@ -765,6 +765,23 @@ yYDnCgA=
|
|||
});
|
||||
});
|
||||
|
||||
it('Should verify cleartext message correctly when using a detached binary signature and text literal data', async function () {
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
const plaintextArray = openpgp.util.str_to_Uint8Array(plaintext);
|
||||
const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||
const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0];
|
||||
await privKey.decrypt('hello world');
|
||||
return openpgp.sign({ privateKeys:[privKey], data:plaintextArray, detached: true}).then(function(signed) {
|
||||
const signature = openpgp.signature.readArmored(signed.signature);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromText(plaintext), signature: signature });
|
||||
}).then(function(cleartextSig) {
|
||||
expect(cleartextSig).to.exist;
|
||||
expect(cleartextSig.signatures).to.have.length(1);
|
||||
expect(cleartextSig.signatures[0].valid).to.be.true;
|
||||
expect(cleartextSig.signatures[0].signature.packets.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should verify encrypted cleartext message correctly when encrypting binary literal data with a canonical text signature', async function () {
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0];
|
||||
|
|
Loading…
Reference in New Issue
Block a user