Skip to content

Commit

Permalink
Merge pull request #45 from cryptosphere/fix_hash
Browse files Browse the repository at this point in the history
Allow strings of arbitrary bytes to be hashed
  • Loading branch information
tarcieri committed Mar 13, 2013
2 parents 0340428 + 307ae37 commit 9be368b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rbnacl/nacl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def self.#{name}(*args)
SHA256BYTES = 32
wrap_nacl_function :crypto_hash_sha256,
:crypto_hash_sha256_ref,
[:pointer, :string, :long_long]
[:pointer, :pointer, :long_long]

SHA512BYTES = 64
wrap_nacl_function :crypto_hash_sha512,
:crypto_hash_sha512_ref,
[:pointer, :string, :long_long]
[:pointer, :pointer, :long_long]

PUBLICKEYBYTES = 32
SECRETKEYBYTES = 32
Expand Down
8 changes: 8 additions & 0 deletions spec/rbnacl/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
it "calculates the correct hash for an empty string and returns it in hex" do
Crypto::Hash.sha256("", :hex).should eq empty_string_hash_hex
end

it "doesn't raise on a null byte" do
expect { Crypto::Hash.sha256("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
end
end

context "sha512" do
Expand All @@ -48,5 +52,9 @@
it "calculates the correct hash for an empty string and returns it in hex" do
Crypto::Hash.sha512("", :hex).should eq empty_string_hash_hex
end

it "doesn't raise on a null byte" do
expect { Crypto::Hash.sha512("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
end
end
end

0 comments on commit 9be368b

Please sign in to comment.