diff --git a/src/packet/literal.js b/src/packet/literal.js index b6b4e126..87c5cd1e 100644 --- a/src/packet/literal.js +++ b/src/packet/literal.js @@ -86,17 +86,15 @@ 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(textMode=false) { +Literal.prototype.getBytes = function() { if (this.data !== null) { return this.data; } - 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); - } + // normalize EOL to \r\n + const text = util.canonicalizeEOL(this.text); + // encode UTF8 + this.data = util.str_to_Uint8Array(util.encode_utf8(text)); return this.data; }; @@ -150,7 +148,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(format !== 'binary'); + const data = this.getBytes(); return util.concatUint8Array([format, filename_length, filename, date, data]); }; diff --git a/src/packet/signature.js b/src/packet/signature.js index 6208f2fc..7c0aeb32 100644 --- a/src/packet/signature.js +++ b/src/packet/signature.js @@ -574,6 +574,9 @@ Signature.prototype.toSign = function (type, data) { switch (type) { case t.binary: + if (data.text !== null) { + return util.str_to_Uint8Array(data.getText()); + } return data.getBytes(); case t.text: { diff --git a/test/general/packet.js b/test/general/packet.js index fbb2001f..193e40c2 100644 --- a/test/general/packet.js +++ b/test/general/packet.js @@ -813,9 +813,9 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu signature.hashAlgorithm = 'sha256'; 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(signature);