Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add nonce constant and more tests

  • Loading branch information...
commit d0569363265450ba2f9b65baaef13956f6efa985 1 parent a54391a
@mogest mogest authored
View
1  ext/nacl/nacl.c
@@ -167,6 +167,7 @@ void Init_nacl() {
rb_define_module_function(NaCl, "crypto_box_keypair", method_crypto_box_keypair, 0);
rb_define_module_function(NaCl, "crypto_box", method_crypto_box, 4);
rb_define_module_function(NaCl, "crypto_box_open", method_crypto_box_open, 4);
+ rb_define_const(NaCl, "BOX_NONCE_LENGTH", INT2FIX(crypto_box_NONCEBYTES));
rb_define_module_function(NaCl, "crypto_sign_keypair", method_crypto_sign_keypair, 0);
rb_define_module_function(NaCl, "crypto_sign", method_crypto_sign, 2);
View
6 test/test_nacl_crypto_box.rb
@@ -56,7 +56,11 @@ def test_open_with_changed_ciphertext
mangled = "#{crypted[0..13]}#{char}#{crypted[15..-1]}"
assert_not_equal crypted, mangled
assert_raise(NaCl::OpenError) do
- p NaCl.crypto_box_open(mangled, @nonce, @pub_a, @sec_b)
+ NaCl.crypto_box_open(mangled, @nonce, @pub_a, @sec_b)
end
end
+
+ def test_constants
+ assert_equal 24, NaCl::BOX_NONCE_LENGTH
+ end
end
View
30 test/test_nacl_crypto_sign.rb
@@ -18,5 +18,35 @@ def test_with_normal_message
crypted = NaCl.crypto_sign(message, @sec)
assert_equal message, NaCl.crypto_sign_open(crypted, @pub)
end
+
+ def test_with_empty_message
+ message = ""
+ crypted = NaCl.crypto_sign(message, @sec)
+ assert_equal message, NaCl.crypto_sign_open(crypted, @pub)
+ end
+
+ def test_with_invalid_arguments
+ assert_raise(ArgumentError) do
+ NaCl.crypto_sign("message", "invalid seckey")
+ end
+ assert_raise(ArgumentError) do
+ NaCl.crypto_sign_open("message", "invalid pubkey")
+ end
+ end
+
+ def test_open_with_empty_message
+ assert_raise(NaCl::OpenError) do
+ NaCl.crypto_sign_open("", @pub)
+ end
+ end
+
+ def test_open_with_changed_signedtext
+ signed = NaCl.crypto_sign("This is a test message", @sec)
+ mangled = signed.gsub("test message", "best message")
+ assert_not_equal signed, mangled
+ assert_raise(NaCl::OpenError) do
+ NaCl.crypto_sign_open(mangled, @pub)
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.