Skip to content

Commit

Permalink
Fix failing tests on Rubinius
Browse files Browse the repository at this point in the history
  • Loading branch information
stouset committed Jul 31, 2013
1 parent 9a80d7b commit 0ee9cc0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/cryptography/serializable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def from_hash(hash)

def from_sodium_buffer(buffer)
self.from_protocol_buffer self.serializer.parse(buffer.to_s)
rescue
# ProtocolBuffers::Message#parse doesn't gracefully handle
# errors. It just kind of throws whatever exception seemed
# convenient at the time. So we just always convert it to an
# ArgumentError (the string was an Argument, and it was
# errorful, so... it's not any worse than what it was).
raise ArgumentError.new($!.message).tap {|e|
e.set_backtrace($!.backtrace)
}
end

def from_protocol_buffer(buffer)
Expand Down
10 changes: 7 additions & 3 deletions test/cryptography/symmetric/authenticated_message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
subject { self.klass.new(self.key, self.plaintext) }
let(:klass) { Cryptography::Symmetric::AuthenticatedMessage }
let(:key) { self.klass.key }
let(:plaintext) { Sodium::Buffer.new('message') }

def plaintext
Sodium::Buffer.new 'message'.tr('', '')
end

def self.protocol_buffer_authenticated_message_test_vector(plaintext, key, bytes)
it "must never break backwards compatibility with the serialization format" do
Expand Down Expand Up @@ -65,8 +68,9 @@ def self.protocol_buffer_authenticated_message_test_vector(plaintext, key, bytes
it '#contents must not reveal the message if it has been altered' do
# we have to jump through hoops here because it *shouldn't* be
# easy to modify these strings!
tampered = self.subject.to_s.to_str.dup.tap {|s| s[-1] = s[-1].succ }
hmac = self.klass.from_s(tampered)
plaintext = self.plaintext.to_s.to_str
tampered = self.subject.to_s.to_str.dup.tap {|s| s[plaintext] = plaintext.succ }
hmac = self.klass.from_s(tampered)

lambda do
hmac.contents(self.key)
Expand Down

0 comments on commit 0ee9cc0

Please sign in to comment.