Using OpenPGP gem and getting "out of range error"

I’ve been handed someone else’s code to debug, but am getting no
further than he did… perhaps someone can help.

We’re using the OpenPGP gem (http://openpgp.rubyforge.org/) to PGP-
encrypt an XML file for submission to a third-party for processing.

The prob is that when encrypting, we get errors like the following:

RangeError: 1502 out of char range
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/buffer.rb:138:in chr' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/buffer.rb:138:inwrite_byte’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:129
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:126:in each' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:126 from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/buffer.rb:18:incall’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/buffer.rb:18:in initialize' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/buffer.rb:9:innew’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/buffer.rb:9:in write' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:125:into_s’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:78:in write' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:28 from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/packet.rb:105:incall’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/packet.rb:105:in initialize' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/packet.rb:346:ininitialize’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:27:in new' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:27 from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:86:incall’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:86:in initialize' from /Users/szagerman/.rvm/gems/[email protected]/gems/ openpgp-0.0.3/lib/openpgp/message.rb:25:innew’
from /Users/szagerman/.rvm/gems/[email protected]/gems/
openpgp-0.0.3/lib/openpgp/message.rb:25:in `encrypt’

If the XML being encrypted grows larger (more elements included), that
RangeError number value becomes a larger number.

Looking at that trace and digging into the src for OpenPGP to where
the error is occurring finds this line at from /Users/szagerman/.rvm/
gems/[email protected]/gems/openpgp-0.0.3/lib/openpgp/
message.rb:129:

buffer.write_byte(body.size)

So, I’m wondering if the body.size is greater than 255 if this causes
a prob writing it as a byte (the call being write_byte)…?

And if so, whether one is supposed to break up the payload into small
chunks somehow? That doesnt seem right and I think from more reading
of the OpenPGP code that it is packetizing the original data in some
way.

Any thoughts?

one more bit of info…

if the data being encrypted is 250 chars or longer, the RangeError
occurs; if it’s 249 chars long, no error

strange

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs