What I was thinking is: 

Standardize method names for message, CleartextMessage and literalData 
setText 
assumes UTF-16 and normalizes CR/LF to just LF 
setBytes takes enum describing encoding of input 
for binary leaves it alone 
for text data decodes UTF-8 if specified and normalizes CR/LF to just LF 
getText 
returns UTF-16 with LF 
getBytes 
For binary data returns the data 
For text data returns UTF-8 with CR/LF 

How does that sound? 

----- Original Message -----

| From: "Thomas Oberndörfer" <notifications@github.com>
| To: "openpgpjs/openpgpjs" <openpgpjs@noreply.github.com>
| Cc: "Robert Nelson" <robertn@the-nelsons.org>
| Sent: Saturday, December 7, 2013 1:33:42 PM
| Subject: Re: [openpgpjs] Merge signature changes from master (#137)

| In src/packet/literal.js:
| >    /**
| >     * Get the byte sequence representing the literal packet data
| >     * @returns {String} A sequence of bytes
| >     */
| >    this.getBytes = function() {
| > -    var bytes = this.data;
| > -    switch (this.format) {
| > -      case 'utf8':
| > -        bytes = bytes.replace(/\n/g, '\r\n');
| > -        bytes = util.encode_utf8(bytes);
| > -        break;
| > -      case 'text':
| > -        bytes = bytes.replace(/\n/g, '\r\n');
| > -        break;
| > -    }
| > -    return bytes;
| > +    return this.format == 'utf8' ? util.encode_utf8(this.data) :
| > this.data;
| >    }
| >

| | Okay I reread the RFC yet again :-) Literal Data packets of type
| | text/unicode
| | ('t' and 'u') have CR/LF EOLs not the ORIGINAL
| 
| | as I thought so I surrender and will change to just LF. I will submit
| | another
| | PR to fix master and change my pending PR for devel.
| 
| Of course you should not surrender ;-) Great to see the devel branch is
| making progress.
| Where to do this change to LF? Just in Message.getText and
| CleartextMessage.getText?
| | However in looking at the implementation of literalDataPacket and its usage
| | I
| | believe there are issues with incorrect encoding
| 
| | and decoding of UTF-8. I don't believe the current implementation will
| | correctly handle encryption and decryption of binary data.
| 
| | I will submit a PR for review that cleans up the encoding / decoding
| | issues.
| 
| I agree the literalDataPacket is somehow broken. If you call setBytes with
| UTF you decode, only to encode again when calling
| getBytes? On the other hand 'text' could be also UTF8 but is not decoded
| there, the same for 'binary' this could be also UTF8.
| We could move the decoding for example also to the Message.getText and
| CleartextMessage.getText methods maybe.

| —
| Reply to this email directly or view it on GitHub .