rbnacl 1.1.0 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -5
  3. data/CHANGES.md +15 -0
  4. data/Gemfile +4 -1
  5. data/Guardfile +8 -0
  6. data/README.md +52 -3
  7. data/lib/rbnacl.rb +65 -29
  8. data/lib/rbnacl/auth.rb +14 -18
  9. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb +185 -0
  10. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/private_key.rb +26 -23
  11. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key.rb +13 -12
  12. data/lib/rbnacl/group_elements/curve25519.rb +81 -0
  13. data/lib/rbnacl/hash.rb +30 -14
  14. data/lib/rbnacl/hash/blake2b.rb +57 -0
  15. data/lib/rbnacl/hash/sha256.rb +15 -0
  16. data/lib/rbnacl/hash/sha512.rb +15 -0
  17. data/lib/rbnacl/hmac/sha256.rb +19 -17
  18. data/lib/rbnacl/hmac/sha512256.rb +18 -19
  19. data/lib/rbnacl/init.rb +10 -0
  20. data/lib/rbnacl/{keys/key_comparator.rb → key_comparator.rb} +1 -1
  21. data/lib/rbnacl/{auth/one_time.rb → one_time_auths/poly1305.rb} +21 -19
  22. data/lib/rbnacl/rake_tasks.rb +7 -6
  23. data/lib/rbnacl/random.rb +8 -3
  24. data/lib/rbnacl/random_nonce_box.rb +9 -14
  25. data/lib/rbnacl/secret_boxes/xsalsa20poly1305.rb +125 -0
  26. data/lib/rbnacl/self_test.rb +59 -40
  27. data/lib/rbnacl/serializable.rb +4 -12
  28. data/lib/rbnacl/signatures/ed25519.rb +15 -0
  29. data/lib/rbnacl/signatures/ed25519/signing_key.rb +104 -0
  30. data/lib/rbnacl/signatures/ed25519/verify_key.rb +91 -0
  31. data/lib/rbnacl/sodium.rb +43 -0
  32. data/lib/rbnacl/test_vectors.rb +34 -1
  33. data/lib/rbnacl/util.rb +52 -7
  34. data/lib/rbnacl/version.rb +2 -2
  35. data/rbnacl.gemspec +3 -6
  36. data/spec/rbnacl/{auth/one_time_spec.rb → authenticators/poly1305_spec.rb} +2 -2
  37. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb +65 -0
  38. data/spec/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key_spec.rb +10 -13
  39. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb +39 -0
  40. data/spec/rbnacl/{point_spec.rb → group_element_spec.rb} +6 -8
  41. data/spec/rbnacl/hash/blake2b_spec.rb +26 -0
  42. data/spec/rbnacl/hash_spec.rb +13 -33
  43. data/spec/rbnacl/hmac/sha256_spec.rb +2 -2
  44. data/spec/rbnacl/hmac/sha512256_spec.rb +2 -2
  45. data/spec/rbnacl/random_nonce_box_spec.rb +21 -26
  46. data/spec/rbnacl/random_spec.rb +3 -3
  47. data/spec/rbnacl/secret_box_spec.rb +6 -6
  48. data/spec/rbnacl/signatures/ed25519/signing_key_spec.rb +30 -0
  49. data/spec/rbnacl/signatures/ed25519/verify_key_spec.rb +39 -0
  50. data/spec/rbnacl/util_spec.rb +67 -53
  51. data/spec/shared/authenticator.rb +36 -54
  52. data/spec/shared/box.rb +10 -10
  53. data/spec/shared/key_equality.rb +3 -3
  54. data/spec/shared/serializable.rb +17 -0
  55. data/spec/spec_helper.rb +14 -16
  56. data/tasks/rspec.rake +1 -0
  57. metadata +42 -67
  58. checksums.yaml.gz.sig +0 -0
  59. data.tar.gz.sig +0 -3
  60. data/lib/rbnacl/box.rb +0 -171
  61. data/lib/rbnacl/encoder.rb +0 -44
  62. data/lib/rbnacl/encoders/base32.rb +0 -33
  63. data/lib/rbnacl/encoders/base64.rb +0 -30
  64. data/lib/rbnacl/encoders/hex.rb +0 -30
  65. data/lib/rbnacl/encoders/raw.rb +0 -12
  66. data/lib/rbnacl/keys/signing_key.rb +0 -95
  67. data/lib/rbnacl/keys/verify_key.rb +0 -96
  68. data/lib/rbnacl/nacl.rb +0 -146
  69. data/lib/rbnacl/point.rb +0 -70
  70. data/lib/rbnacl/secret_box.rb +0 -119
  71. data/spec/rbnacl/box_spec.rb +0 -42
  72. data/spec/rbnacl/encoder_spec.rb +0 -14
  73. data/spec/rbnacl/encoders/base32_spec.rb +0 -16
  74. data/spec/rbnacl/encoders/base64_spec.rb +0 -15
  75. data/spec/rbnacl/encoders/hex_spec.rb +0 -15
  76. data/spec/rbnacl/keys/private_key_spec.rb +0 -68
  77. data/spec/rbnacl/keys/signing_key_spec.rb +0 -39
  78. data/spec/rbnacl/keys/verify_key_spec.rb +0 -51
  79. metadata.gz.sig +0 -2
@@ -5,7 +5,7 @@ require 'rbnacl/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "rbnacl"
8
- gem.version = Crypto::VERSION
8
+ gem.version = RbNaCl::VERSION
9
9
  gem.authors = ["Tony Arcieri", "Jonathan Stott"]
10
10
  gem.email = ["tony.arcieri@gmail.com", "jonathan.stott@gmail.com"]
11
11
  gem.description = "Ruby binding to the Networking and Cryptography (NaCl) library"
@@ -21,11 +21,8 @@ Gem::Specification.new do |gem|
21
21
  gem.platform = "jruby"
22
22
  end
23
23
 
24
- gem.add_runtime_dependency 'ffi'
24
+ gem.add_runtime_dependency "ffi"
25
25
 
26
26
  gem.add_development_dependency "rake"
27
- gem.add_development_dependency "rspec"
28
-
29
- gem.signing_key = "/home/tony/.sekretz/gem-private_key.pem"
30
- gem.cert_chain = ["/home/tony/.sekretz/gem-public_cert.pem"]
27
+ gem.add_development_dependency "rspec", ">= 2.14"
31
28
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::Auth::OneTime do
5
- let(:hex_tag) { hex_vector :auth_onetime }
4
+ describe RbNaCl::OneTimeAuth do
5
+ let(:tag) { vector :auth_onetime }
6
6
 
7
7
  include_examples "authenticator"
8
8
  end
@@ -0,0 +1,65 @@
1
+ # encoding: binary
2
+ require 'spec_helper'
3
+
4
+ describe RbNaCl::PrivateKey do
5
+ let(:bobsk) { vector :bob_private }
6
+ let(:bobpk) { vector :bob_public }
7
+
8
+ subject { RbNaCl::PrivateKey.new(bobsk) }
9
+
10
+ context "generate" do
11
+ let(:secret_key) { RbNaCl::PrivateKey.generate }
12
+
13
+ it "returns a secret key" do
14
+ secret_key.should be_a RbNaCl::PrivateKey
15
+ end
16
+
17
+ it "has the public key also set" do
18
+ secret_key.public_key.should be_a RbNaCl::PublicKey
19
+ end
20
+ end
21
+
22
+ context "new" do
23
+ it "accepts a valid key" do
24
+ expect { RbNaCl::PrivateKey.new(bobsk) }.not_to raise_error
25
+ end
26
+
27
+ it "raises TypeError when given a nil key" do
28
+ expect { RbNaCl::PrivateKey.new(nil) }.to raise_error(TypeError)
29
+ end
30
+
31
+ it "raises ArgumentError when given a short key" do
32
+ expect { RbNaCl::PrivateKey.new("short") }.to raise_error(ArgumentError)
33
+ end
34
+ end
35
+
36
+ context "public_key" do
37
+ it "returns a public key" do
38
+ subject.public_key.should be_a RbNaCl::PublicKey
39
+ end
40
+
41
+ it "returns the correct public key" do
42
+ subject.public_key.to_s.should eql bobpk
43
+ end
44
+ end
45
+
46
+ context "#to_bytes" do
47
+ it "returns the bytes of the key" do
48
+ subject.to_s.should eq bobsk
49
+ end
50
+ end
51
+
52
+ context "#to_s" do
53
+ it "returns the raw bytes of the key" do
54
+ subject.to_bytes.should eq bobsk
55
+ end
56
+ end
57
+
58
+ include_examples "key equality" do
59
+ let(:key) { subject }
60
+ let(:key_bytes) { subject.to_bytes }
61
+ let(:other_key) { described_class.new(bobpk) }
62
+ end
63
+
64
+ include_examples "serializable"
65
+ end
@@ -1,24 +1,22 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::PublicKey do
5
- let(:alicepk) { test_vector :alice_public }
6
- let(:alicepk_hex) { bytes2hex alicepk }
4
+ describe RbNaCl::PublicKey do
5
+ let(:alicepk) { vector :alice_public }
7
6
 
8
- subject { Crypto::PublicKey.new(alicepk) }
7
+ subject { RbNaCl::PublicKey.new(alicepk) }
9
8
 
10
9
  context "new" do
11
10
  it "accepts a valid key" do
12
- expect { Crypto::PublicKey.new(alicepk) }.not_to raise_error
13
- end
14
- it "accepts a valid key in hex" do
15
- expect { Crypto::PublicKey.new(alicepk_hex, :hex) }.not_to raise_error
11
+ expect { RbNaCl::PublicKey.new(alicepk) }.not_to raise_error
16
12
  end
13
+
17
14
  it "rejects a nil key" do
18
- expect { Crypto::PublicKey.new(nil) }.to raise_error(ArgumentError)
15
+ expect { RbNaCl::PublicKey.new(nil) }.to raise_error(TypeError)
19
16
  end
17
+
20
18
  it "rejects a short key" do
21
- expect { Crypto::PublicKey.new("short") }.to raise_error(ArgumentError)
19
+ expect { RbNaCl::PublicKey.new("short") }.to raise_error(ArgumentError)
22
20
  end
23
21
  end
24
22
 
@@ -32,9 +30,6 @@ describe Crypto::PublicKey do
32
30
  it "returns the bytes of the key" do
33
31
  subject.to_s.should eq alicepk
34
32
  end
35
- it "returns the bytes of the key hex encoded" do
36
- subject.to_s(:hex).should eq alicepk_hex
37
- end
38
33
  end
39
34
 
40
35
  include_examples "key equality" do
@@ -42,4 +37,6 @@ describe Crypto::PublicKey do
42
37
  let(:key_bytes) { subject.to_bytes }
43
38
  let(:other_key) { described_class.new(alicepk.succ) }
44
39
  end
40
+
41
+ include_examples "serializable"
45
42
  end
@@ -0,0 +1,39 @@
1
+ # encoding: binary
2
+ require 'spec_helper'
3
+
4
+ describe RbNaCl::Box do
5
+ let(:alicepk) { vector :alice_public }
6
+ let(:bobsk) { vector :bob_private }
7
+ let(:alice_key) { RbNaCl::PublicKey.new(alicepk) }
8
+ let(:bob_key) { RbNaCl::PrivateKey.new(bobsk) }
9
+
10
+ context "new" do
11
+ it "accepts strings" do
12
+ expect { RbNaCl::Box.new(alicepk, bobsk) }.to_not raise_error(Exception)
13
+ end
14
+
15
+ it "accepts KeyPairs" do
16
+ expect { RbNaCl::Box.new(alice_key, bob_key) }.to_not raise_error(Exception)
17
+ end
18
+
19
+ it "raises TypeError on a nil public key" do
20
+ expect { RbNaCl::Box.new(nil, bobsk) }.to raise_error(TypeError)
21
+ end
22
+
23
+ it "raises RbNaCl::LengthError on an invalid public key" do
24
+ expect { RbNaCl::Box.new("hello", bobsk) }.to raise_error(RbNaCl::LengthError, /Public key was 5 bytes \(Expected 32\)/)
25
+ end
26
+
27
+ it "raises TypeError on a nil secret key" do
28
+ expect { RbNaCl::Box.new(alicepk, nil) }.to raise_error(TypeError)
29
+ end
30
+
31
+ it "raises RbNaCl::LengthError on an invalid secret key" do
32
+ expect { RbNaCl::Box.new(alicepk, "hello") }.to raise_error(RbNaCl::LengthError, /Private key was 5 bytes \(Expected 32\)/)
33
+ end
34
+ end
35
+
36
+ include_examples 'box' do
37
+ let(:box) { RbNaCl::Box.new(alicepk, bobsk) }
38
+ end
39
+ end
@@ -1,13 +1,13 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::Point do
5
- let(:alice_private) { test_vector :alice_private }
6
- let(:alice_public) { test_vector :alice_public }
4
+ describe RbNaCl::GroupElement do
5
+ let(:alice_private) { vector :alice_private }
6
+ let(:alice_public) { vector :alice_public }
7
7
 
8
- let(:bob_public) { test_vector :bob_public }
8
+ let(:bob_public) { vector :bob_public }
9
9
 
10
- let(:alice_mult_bob) { test_vector :alice_mult_bob }
10
+ let(:alice_mult_bob) { vector :alice_mult_bob }
11
11
 
12
12
  subject { described_class.new(bob_public) }
13
13
 
@@ -23,7 +23,5 @@ describe Crypto::Point do
23
23
  subject.to_bytes.should eq bob_public
24
24
  end
25
25
 
26
- it "serializes to hex" do
27
- subject.to_s(:hex).should eq bytes2hex bob_public
28
- end
26
+ include_examples "serializable"
29
27
  end
@@ -0,0 +1,26 @@
1
+ # encoding: binary
2
+ require 'spec_helper'
3
+
4
+ describe RbNaCl::Hash::Blake2b do
5
+ let(:reference_string) { vector :blake2b_message }
6
+ let(:reference_string_hash) { vector :blake2b_digest }
7
+ let(:empty_string_hash) { vector :blake2b_empty }
8
+
9
+ it "calculates the correct hash for a reference string" do
10
+ RbNaCl::Hash.blake2b(reference_string).should eq reference_string_hash
11
+ end
12
+
13
+ it "calculates the correct hash for an empty string" do
14
+ RbNaCl::Hash.blake2b("").should eq empty_string_hash
15
+ end
16
+
17
+ context "keyed" do
18
+ let(:reference_string) { vector :blake2b_keyed_message }
19
+ let(:reference_key) { vector :blake2b_key }
20
+ let(:reference_string_hash) { vector :blake2b_keyed_digest }
21
+
22
+ it "calculates keyed hashes correctly" do
23
+ RbNaCl::Hash.blake2b(reference_string, :key => reference_key).should eq reference_string_hash
24
+ end
25
+ end
26
+ end
@@ -1,60 +1,40 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::Hash do
4
+ describe RbNaCl::Hash do
5
5
  context "sha256" do
6
- let(:reference_string) { test_vector :sha256_message }
7
- let(:reference_string_hash) { test_vector :sha256_digest }
8
- let(:empty_string_hash) { "\xE3\xB0\xC4B\x98\xFC\x1C\x14\x9A\xFB\xF4\xC8\x99o\xB9$'\xAEA\xE4d\x9B\x93L\xA4\x95\x99\exR\xB8U" }
9
- let(:reference_string_hash_hex) { reference_string_hash.unpack('H*').first }
10
- let(:empty_string_hash_hex) { empty_string_hash.unpack('H*').first }
6
+ let(:reference_string) { vector :sha256_message }
7
+ let(:reference_string_hash) { vector :sha256_digest }
8
+ let(:empty_string_hash) { vector :sha256_empty }
11
9
 
12
10
  it "calculates the correct hash for a reference string" do
13
- Crypto::Hash.sha256(reference_string).should eq reference_string_hash
11
+ RbNaCl::Hash.sha256(reference_string).should eq reference_string_hash
14
12
  end
15
13
 
16
14
  it "calculates the correct hash for an empty string" do
17
- Crypto::Hash.sha256("").should eq empty_string_hash
18
- end
19
-
20
- it "calculates the correct hash for a reference string and returns it in hex" do
21
- Crypto::Hash.sha256(reference_string, :hex).should eq reference_string_hash_hex
22
- end
23
-
24
- it "calculates the correct hash for an empty string and returns it in hex" do
25
- Crypto::Hash.sha256("", :hex).should eq empty_string_hash_hex
15
+ RbNaCl::Hash.sha256("").should eq empty_string_hash
26
16
  end
27
17
 
28
18
  it "doesn't raise on a null byte" do
29
- expect { Crypto::Hash.sha256("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
19
+ expect { RbNaCl::Hash.sha256("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
30
20
  end
31
21
  end
32
22
 
33
23
  context "sha512" do
34
- let(:reference_string) { "The quick brown fox jumps over the lazy dog." }
35
- let(:reference_string_hash) { "\x91\xEA\x12E\xF2\rF\xAE\x9A\x03z\x98\x9FT\xF1\xF7\x90\xF0\xA4v\a\xEE\xB8\xA1M\x12\x89\f\xEAw\xA1\xBB\xC6\xC7\xED\x9C\xF2\x05\xE6{\x7F+\x8F\xD4\xC7\xDF\xD3\xA7\xA8a~E\xF3\xC4c\xD4\x81\xC7\xE5\x86\xC3\x9A\xC1\xED" }
36
- let(:empty_string_hash) { "\xCF\x83\xE15~\xEF\xB8\xBD\xF1T(P\xD6m\x80\a\xD6 \xE4\x05\vW\x15\xDC\x83\xF4\xA9!\xD3l\xE9\xCEG\xD0\xD1<]\x85\xF2\xB0\xFF\x83\x18\xD2\x87~\xEC/c\xB91\xBDGAz\x81\xA582z\xF9'\xDA>" }
37
- let(:reference_string_hash_hex) { reference_string_hash.unpack('H*').first }
38
- let(:empty_string_hash_hex) { empty_string_hash.unpack('H*').first }
24
+ let(:reference_string) { vector :sha512_message }
25
+ let(:reference_string_hash) { vector :sha512_digest }
26
+ let(:empty_string_hash) { vector :sha512_empty }
39
27
 
40
28
  it "calculates the correct hash for a reference string" do
41
- Crypto::Hash.sha512(reference_string).should eq reference_string_hash
29
+ RbNaCl::Hash.sha512(reference_string).should eq reference_string_hash
42
30
  end
43
31
 
44
32
  it "calculates the correct hash for an empty string" do
45
- Crypto::Hash.sha512("").should eq empty_string_hash
46
- end
47
-
48
- it "calculates the correct hash for a reference string and returns it in hex" do
49
- Crypto::Hash.sha512(reference_string, :hex).should eq reference_string_hash_hex
50
- end
51
-
52
- it "calculates the correct hash for an empty string and returns it in hex" do
53
- Crypto::Hash.sha512("", :hex).should eq empty_string_hash_hex
33
+ RbNaCl::Hash.sha512("").should eq empty_string_hash
54
34
  end
55
35
 
56
36
  it "doesn't raise on a null byte" do
57
- expect { Crypto::Hash.sha512("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
37
+ expect { RbNaCl::Hash.sha512("\0") }.to_not raise_error(/ArgumentError: string contains null byte/)
58
38
  end
59
39
  end
60
40
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::HMAC::SHA256 do
5
- let(:hex_tag) { hex_vector :auth_hmacsha256 }
4
+ describe RbNaCl::HMAC::SHA256 do
5
+ let(:tag) { vector :auth_hmacsha256 }
6
6
 
7
7
  include_examples "authenticator"
8
8
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::HMAC::SHA512256 do
5
- let(:hex_tag) { hex_vector :auth_hmacsha512256 }
4
+ describe RbNaCl::HMAC::SHA512256 do
5
+ let(:tag) { vector :auth_hmacsha512256 }
6
6
 
7
7
  include_examples "authenticator"
8
8
  end
@@ -1,40 +1,42 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::RandomNonceBox do
5
- let (:secret_key) { test_vector :secret_key }
6
- let(:secret_box) { Crypto::SecretBox.new(secret_key) }
7
- let (:alicepk) { test_vector :alice_public }
8
- let (:bobsk) { test_vector :bob_private }
4
+ describe RbNaCl::RandomNonceBox do
5
+ let(:secret_key) { vector :secret_key }
6
+ let(:secret_box) { RbNaCl::SecretBox.new(secret_key) }
7
+ let(:alicepk) { vector :alice_public }
8
+ let(:bobsk) { vector :bob_private }
9
9
 
10
10
  context "instantiation" do
11
11
  it "can be instantiated from an already existing box" do
12
- expect { Crypto::RandomNonceBox.new(secret_box) }.not_to raise_error
12
+ expect { RbNaCl::RandomNonceBox.new(secret_box) }.not_to raise_error
13
13
  end
14
14
 
15
15
  it "can be instantiated from a secret key" do
16
- Crypto::RandomNonceBox.from_secret_key(secret_key).should be_a Crypto::RandomNonceBox
16
+ RbNaCl::RandomNonceBox.from_secret_key(secret_key).should be_a RbNaCl::RandomNonceBox
17
17
  end
18
- it "complains on an inappropriate secret key" do
19
- expect { Crypto::RandomNonceBox.from_secret_key(nil) }.to raise_error(ArgumentError)
18
+
19
+ it "raises TypeError when given a nil secret key" do
20
+ expect { RbNaCl::RandomNonceBox.from_secret_key(nil) }.to raise_error(TypeError)
20
21
  end
22
+
21
23
  it "can be instantiated from a key-pair" do
22
- Crypto::RandomNonceBox.from_keypair(alicepk, bobsk).should be_a Crypto::RandomNonceBox
24
+ RbNaCl::RandomNonceBox.from_keypair(alicepk, bobsk).should be_a RbNaCl::RandomNonceBox
23
25
  end
24
- it "complains on an inappropriate key in the pair" do
25
- expect { Crypto::RandomNonceBox.from_keypair(nil, bobsk) }.to raise_error(ArgumentError)
26
+
27
+ it "raises TypeError when given nil secret keys in the pair" do
28
+ expect { RbNaCl::RandomNonceBox.from_keypair(nil, bobsk) }.to raise_error(TypeError)
29
+ expect { RbNaCl::RandomNonceBox.from_keypair(alicepk, nil) }.to raise_error(TypeError)
26
30
  end
27
31
  end
28
32
 
29
-
30
-
31
33
  context "cryptography" do
32
- let(:nonce) { test_vector :box_nonce }
33
- let(:message) { test_vector :box_message }
34
- let(:ciphertext) { test_vector :box_ciphertext }
35
- let(:random_box) { Crypto::RandomNonceBox.from_keypair(alicepk, bobsk) }
34
+ let(:nonce) { vector :box_nonce }
35
+ let(:message) { vector :box_message }
36
+ let(:ciphertext) { vector :box_ciphertext }
37
+ let(:random_box) { RbNaCl::RandomNonceBox.from_keypair(alicepk, bobsk) }
36
38
  let(:enciphered_message) { random_box.box(message) }
37
- let(:enciphered_message_hex) { random_box.box(message, :hex) }
39
+ let(:enciphered_message_hex) { random_box.box(message) }
38
40
 
39
41
  it "descrypts a message with a 'random' nonce" do
40
42
  random_box.open(nonce+ciphertext).should eql message
@@ -43,12 +45,5 @@ describe Crypto::RandomNonceBox do
43
45
  it "can successfully round-trip a message" do
44
46
  random_box.open(enciphered_message).should eql message
45
47
  end
46
-
47
- it "can encode a ciphertext as hex" do
48
- enciphered_message_hex.should match /\A[0-9a-f]+\z/
49
- end
50
- it "can roundtrip a message as hex" do
51
- random_box.open(enciphered_message_hex, :hex).should eql message
52
- end
53
48
  end
54
49
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: binary
2
- describe Crypto::Random do
2
+ describe RbNaCl::Random do
3
3
  it "produces random bytes" do
4
- Crypto::Random.random_bytes(16).bytesize.should == 16
4
+ RbNaCl::Random.random_bytes(16).bytesize.should == 16
5
5
  end
6
6
  it "produces different random bytes" do
7
- Crypto::Random.random_bytes(16).should_not == Crypto::Random.random_bytes(16)
7
+ RbNaCl::Random.random_bytes(16).should_not == RbNaCl::Random.random_bytes(16)
8
8
  end
9
9
  end
@@ -1,24 +1,24 @@
1
1
  # encoding: binary
2
2
  require 'spec_helper'
3
3
 
4
- describe Crypto::SecretBox do
5
- let (:key) { test_vector :secret_key }
4
+ describe RbNaCl::SecretBox do
5
+ let (:key) { vector :secret_key }
6
6
 
7
7
  context "new" do
8
8
  it "accepts strings" do
9
- expect { Crypto::SecretBox.new(key) }.to_not raise_error(Exception)
9
+ expect { RbNaCl::SecretBox.new(key) }.to_not raise_error(Exception)
10
10
  end
11
11
 
12
12
  it "raises on a nil key" do
13
- expect { Crypto::SecretBox.new(nil) }.to raise_error(Crypto::LengthError, "Secret key was nil \(Expected #{Crypto::NaCl::SECRETKEYBYTES}\)")
13
+ expect { RbNaCl::SecretBox.new(nil) }.to raise_error(TypeError)
14
14
  end
15
15
 
16
16
  it "raises on a short key" do
17
- expect { Crypto::SecretBox.new("hello") }.to raise_error(Crypto::LengthError, "Secret key was 5 bytes \(Expected #{Crypto::NaCl::SECRETKEYBYTES}\)")
17
+ expect { RbNaCl::SecretBox.new("hello") }.to raise_error(RbNaCl::LengthError, "Secret key was 5 bytes \(Expected #{RbNaCl::SecretBox::KEYBYTES}\)")
18
18
  end
19
19
  end
20
20
 
21
21
  include_examples "box" do
22
- let(:box) { Crypto::SecretBox.new(key) }
22
+ let(:box) { RbNaCl::SecretBox.new(key) }
23
23
  end
24
24
  end