Don't cache literal.getBytes() when signing with textMode=false

This partially reverts bcfb9c0.
This commit is contained in:
Daniel Huigens 2018-05-31 18:18:41 +02:00
parent 5be838f9bb
commit 9302fdcc56
3 changed files with 11 additions and 10 deletions

View File

@ -86,17 +86,15 @@ Literal.prototype.setBytes = function(bytes, format) {
* Get the byte sequence representing the literal packet data * Get the byte sequence representing the literal packet data
* @returns {Uint8Array} A sequence of bytes * @returns {Uint8Array} A sequence of bytes
*/ */
Literal.prototype.getBytes = function(textMode=false) { Literal.prototype.getBytes = function() {
if (this.data !== null) { if (this.data !== null) {
return this.data; return this.data;
} }
if (textMode) { // normalize EOL to \r\n
// normalize EOL to \r\n and UTF-8 encode const text = util.canonicalizeEOL(this.text);
this.data = util.str_to_Uint8Array(util.encode_utf8(util.canonicalizeEOL(this.text))); // encode UTF8
} else { this.data = util.str_to_Uint8Array(util.encode_utf8(text));
this.data = util.str_to_Uint8Array(this.text);
}
return this.data; return this.data;
}; };
@ -150,7 +148,7 @@ Literal.prototype.write = function() {
const format = new Uint8Array([enums.write(enums.literal, this.format)]); const format = new Uint8Array([enums.write(enums.literal, this.format)]);
const date = util.writeDate(this.date); const date = util.writeDate(this.date);
const data = this.getBytes(format !== 'binary'); const data = this.getBytes();
return util.concatUint8Array([format, filename_length, filename, date, data]); return util.concatUint8Array([format, filename_length, filename, date, data]);
}; };

View File

@ -574,6 +574,9 @@ Signature.prototype.toSign = function (type, data) {
switch (type) { switch (type) {
case t.binary: case t.binary:
if (data.text !== null) {
return util.str_to_Uint8Array(data.getText());
}
return data.getBytes(); return data.getBytes();
case t.text: { case t.text: {

View File

@ -813,9 +813,9 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu
signature.hashAlgorithm = 'sha256'; signature.hashAlgorithm = 'sha256';
signature.publicKeyAlgorithm = 'rsa_sign'; signature.publicKeyAlgorithm = 'rsa_sign';
signature.signatureType = 'binary'; signature.signatureType = 'text';
signature.sign(key, literal).then(async () => { return signature.sign(key, literal).then(async () => {
signed.push(literal); signed.push(literal);
signed.push(signature); signed.push(signature);