rbnacl 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.travis.yml +1 -5
  4. data/CHANGES.md +27 -0
  5. data/Gemfile +4 -1
  6. data/Guardfile +8 -0
  7. data/README.md +52 -3
  8. data/lib/rbnacl/auth.rb +22 -19
  9. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/private_key.rb +26 -23
  10. data/lib/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key.rb +13 -12
  11. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb +185 -0
  12. data/lib/rbnacl/group_elements/curve25519.rb +81 -0
  13. data/lib/rbnacl/hash/blake2b.rb +64 -0
  14. data/lib/rbnacl/hash/sha256.rb +15 -0
  15. data/lib/rbnacl/hash/sha512.rb +15 -0
  16. data/lib/rbnacl/hash.rb +30 -14
  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 +12 -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 +67 -43
  27. data/lib/rbnacl/serializable.rb +4 -12
  28. data/lib/rbnacl/signatures/ed25519/signing_key.rb +104 -0
  29. data/lib/rbnacl/signatures/ed25519/verify_key.rb +78 -0
  30. data/lib/rbnacl/signatures/ed25519.rb +15 -0
  31. data/lib/rbnacl/sodium/version.rb +23 -0
  32. data/lib/rbnacl/sodium.rb +43 -0
  33. data/lib/rbnacl/test_vectors.rb +34 -1
  34. data/lib/rbnacl/util.rb +50 -7
  35. data/lib/rbnacl/version.rb +2 -2
  36. data/lib/rbnacl.rb +64 -29
  37. data/rbnacl.gemspec +6 -5
  38. data/spec/rbnacl/{auth/one_time_spec.rb → authenticators/poly1305_spec.rb} +2 -2
  39. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb +65 -0
  40. data/spec/rbnacl/{keys → boxes/curve25519xsalsa20poly1305}/public_key_spec.rb +10 -13
  41. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb +39 -0
  42. data/spec/rbnacl/{point_spec.rb → group_element_spec.rb} +6 -8
  43. data/spec/rbnacl/hash/blake2b_spec.rb +30 -0
  44. data/spec/rbnacl/hash_spec.rb +13 -33
  45. data/spec/rbnacl/hmac/sha256_spec.rb +2 -2
  46. data/spec/rbnacl/hmac/sha512256_spec.rb +2 -2
  47. data/spec/rbnacl/random_nonce_box_spec.rb +21 -26
  48. data/spec/rbnacl/random_spec.rb +3 -3
  49. data/spec/rbnacl/secret_box_spec.rb +6 -6
  50. data/spec/rbnacl/signatures/ed25519/signing_key_spec.rb +30 -0
  51. data/spec/rbnacl/signatures/ed25519/verify_key_spec.rb +39 -0
  52. data/spec/rbnacl/util_spec.rb +67 -53
  53. data/spec/shared/authenticator.rb +36 -55
  54. data/spec/shared/box.rb +10 -10
  55. data/spec/shared/key_equality.rb +3 -3
  56. data/spec/shared/serializable.rb +17 -0
  57. data/spec/spec_helper.rb +15 -16
  58. data/tasks/rspec.rake +1 -0
  59. data.tar.gz.sig +2 -3
  60. metadata +41 -42
  61. metadata.gz.sig +2 -2
  62. data/lib/rbnacl/box.rb +0 -171
  63. data/lib/rbnacl/encoder.rb +0 -44
  64. data/lib/rbnacl/encoders/base32.rb +0 -33
  65. data/lib/rbnacl/encoders/base64.rb +0 -30
  66. data/lib/rbnacl/encoders/hex.rb +0 -30
  67. data/lib/rbnacl/encoders/raw.rb +0 -12
  68. data/lib/rbnacl/keys/signing_key.rb +0 -95
  69. data/lib/rbnacl/keys/verify_key.rb +0 -96
  70. data/lib/rbnacl/nacl.rb +0 -146
  71. data/lib/rbnacl/point.rb +0 -70
  72. data/lib/rbnacl/secret_box.rb +0 -119
  73. data/spec/rbnacl/box_spec.rb +0 -42
  74. data/spec/rbnacl/encoder_spec.rb +0 -14
  75. data/spec/rbnacl/encoders/base32_spec.rb +0 -16
  76. data/spec/rbnacl/encoders/base64_spec.rb +0 -15
  77. data/spec/rbnacl/encoders/hex_spec.rb +0 -15
  78. data/spec/rbnacl/keys/private_key_spec.rb +0 -68
  79. data/spec/rbnacl/keys/signing_key_spec.rb +0 -39
  80. data/spec/rbnacl/keys/verify_key_spec.rb +0 -51
@@ -1,119 +1,133 @@
1
1
  # encoding: binary
2
- describe Crypto::Util do
2
+ describe RbNaCl::Util do
3
3
  context ".verify32!" do
4
- let (:msg) { Crypto::Util.zeros(32) }
5
- let (:identical_msg) { Crypto::Util.zeros(32) }
6
- let (:other_msg) { Crypto::Util.zeros(31) + "\001" }
7
- let (:short_msg) { Crypto::Util.zeros(31) }
8
- let (:long_msg) { Crypto::Util.zeros(33) }
4
+ let (:msg) { RbNaCl::Util.zeros(32) }
5
+ let (:identical_msg) { RbNaCl::Util.zeros(32) }
6
+ let (:other_msg) { RbNaCl::Util.zeros(31) + "\001" }
7
+ let (:short_msg) { RbNaCl::Util.zeros(31) }
8
+ let (:long_msg) { RbNaCl::Util.zeros(33) }
9
9
 
10
10
  it "confirms identical messages are identical" do
11
- Crypto::Util.verify32!(msg, identical_msg).should be true
11
+ RbNaCl::Util.verify32!(msg, identical_msg).should be true
12
12
  end
13
13
 
14
14
  it "confirms non-identical messages are non-identical" do
15
- Crypto::Util.verify32!(msg, other_msg).should be false
16
- Crypto::Util.verify32!(other_msg, msg).should be false
15
+ RbNaCl::Util.verify32!(msg, other_msg).should be false
16
+ RbNaCl::Util.verify32!(other_msg, msg).should be false
17
17
  end
18
18
 
19
19
  it "raises descriptively on a short message in position 1" do
20
- expect { Crypto::Util.verify32!(short_msg, msg) }.to raise_error(Crypto::LengthError)
20
+ expect { RbNaCl::Util.verify32!(short_msg, msg) }.to raise_error(RbNaCl::LengthError)
21
21
  end
22
22
  it "raises descriptively on a short message in position 2" do
23
- expect { Crypto::Util.verify32!(msg, short_msg) }.to raise_error(Crypto::LengthError)
23
+ expect { RbNaCl::Util.verify32!(msg, short_msg) }.to raise_error(RbNaCl::LengthError)
24
24
  end
25
25
  it "raises descriptively on a long message in position 1" do
26
- expect { Crypto::Util.verify32!(long_msg, msg) }.to raise_error(Crypto::LengthError)
26
+ expect { RbNaCl::Util.verify32!(long_msg, msg) }.to raise_error(RbNaCl::LengthError)
27
27
  end
28
28
  it "raises descriptively on a long message in position 2" do
29
- expect { Crypto::Util.verify32!(msg, long_msg) }.to raise_error(Crypto::LengthError)
29
+ expect { RbNaCl::Util.verify32!(msg, long_msg) }.to raise_error(RbNaCl::LengthError)
30
30
  end
31
31
  end
32
32
 
33
33
  context ".verify32" do
34
- let (:msg) { Crypto::Util.zeros(32) }
35
- let (:identical_msg) { Crypto::Util.zeros(32) }
36
- let (:other_msg) { Crypto::Util.zeros(31) + "\001" }
37
- let (:short_msg) { Crypto::Util.zeros(31) }
38
- let (:long_msg) { Crypto::Util.zeros(33) }
34
+ let (:msg) { RbNaCl::Util.zeros(32) }
35
+ let (:identical_msg) { RbNaCl::Util.zeros(32) }
36
+ let (:other_msg) { RbNaCl::Util.zeros(31) + "\001" }
37
+ let (:short_msg) { RbNaCl::Util.zeros(31) }
38
+ let (:long_msg) { RbNaCl::Util.zeros(33) }
39
39
 
40
40
  it "confirms identical messages are identical" do
41
- Crypto::Util.verify32(msg, identical_msg).should be true
41
+ RbNaCl::Util.verify32(msg, identical_msg).should be true
42
42
  end
43
43
 
44
44
  it "confirms non-identical messages are non-identical" do
45
- Crypto::Util.verify32(msg, other_msg).should be false
46
- Crypto::Util.verify32(other_msg, msg).should be false
47
- Crypto::Util.verify32(short_msg, msg).should be false
48
- Crypto::Util.verify32(msg, short_msg).should be false
49
- Crypto::Util.verify32(long_msg, msg).should be false
50
- Crypto::Util.verify32(msg, long_msg).should be false
45
+ RbNaCl::Util.verify32(msg, other_msg).should be false
46
+ RbNaCl::Util.verify32(other_msg, msg).should be false
47
+ RbNaCl::Util.verify32(short_msg, msg).should be false
48
+ RbNaCl::Util.verify32(msg, short_msg).should be false
49
+ RbNaCl::Util.verify32(long_msg, msg).should be false
50
+ RbNaCl::Util.verify32(msg, long_msg).should be false
51
51
  end
52
52
 
53
53
  end
54
54
 
55
55
  context ".verify16!" do
56
- let (:msg) { Crypto::Util.zeros(16) }
57
- let (:identical_msg) { Crypto::Util.zeros(16) }
58
- let (:other_msg) { Crypto::Util.zeros(15) + "\001" }
59
- let (:short_msg) { Crypto::Util.zeros(15) }
60
- let (:long_msg) { Crypto::Util.zeros(17) }
56
+ let (:msg) { RbNaCl::Util.zeros(16) }
57
+ let (:identical_msg) { RbNaCl::Util.zeros(16) }
58
+ let (:other_msg) { RbNaCl::Util.zeros(15) + "\001" }
59
+ let (:short_msg) { RbNaCl::Util.zeros(15) }
60
+ let (:long_msg) { RbNaCl::Util.zeros(17) }
61
61
 
62
62
  it "confirms identical messages are identical" do
63
- Crypto::Util.verify16!(msg, identical_msg).should be true
63
+ RbNaCl::Util.verify16!(msg, identical_msg).should be true
64
64
  end
65
65
 
66
66
  it "confirms non-identical messages are non-identical" do
67
- Crypto::Util.verify16!(msg, other_msg).should be false
68
- Crypto::Util.verify16!(other_msg, msg).should be false
67
+ RbNaCl::Util.verify16!(msg, other_msg).should be false
68
+ RbNaCl::Util.verify16!(other_msg, msg).should be false
69
69
  end
70
70
 
71
71
  it "raises descriptively on a short message in position 1" do
72
- expect { Crypto::Util.verify16!(short_msg, msg) }.to raise_error(Crypto::LengthError)
72
+ expect { RbNaCl::Util.verify16!(short_msg, msg) }.to raise_error(RbNaCl::LengthError)
73
73
  end
74
74
  it "raises descriptively on a short message in position 2" do
75
- expect { Crypto::Util.verify16!(msg, short_msg) }.to raise_error(Crypto::LengthError)
75
+ expect { RbNaCl::Util.verify16!(msg, short_msg) }.to raise_error(RbNaCl::LengthError)
76
76
  end
77
77
  it "raises descriptively on a long message in position 1" do
78
- expect { Crypto::Util.verify16!(long_msg, msg) }.to raise_error(Crypto::LengthError)
78
+ expect { RbNaCl::Util.verify16!(long_msg, msg) }.to raise_error(RbNaCl::LengthError)
79
79
  end
80
80
  it "raises descriptively on a long message in position 2" do
81
- expect { Crypto::Util.verify16!(msg, long_msg) }.to raise_error(Crypto::LengthError)
81
+ expect { RbNaCl::Util.verify16!(msg, long_msg) }.to raise_error(RbNaCl::LengthError)
82
82
  end
83
83
  end
84
84
 
85
85
  context ".verify16" do
86
- let (:msg) { Crypto::Util.zeros(16) }
87
- let (:identical_msg) { Crypto::Util.zeros(16) }
88
- let (:other_msg) { Crypto::Util.zeros(15) + "\001" }
89
- let (:short_msg) { Crypto::Util.zeros(15) }
90
- let (:long_msg) { Crypto::Util.zeros(17) }
86
+ let (:msg) { RbNaCl::Util.zeros(16) }
87
+ let (:identical_msg) { RbNaCl::Util.zeros(16) }
88
+ let (:other_msg) { RbNaCl::Util.zeros(15) + "\001" }
89
+ let (:short_msg) { RbNaCl::Util.zeros(15) }
90
+ let (:long_msg) { RbNaCl::Util.zeros(17) }
91
91
 
92
92
  it "confirms identical messages are identical" do
93
- Crypto::Util.verify16(msg, identical_msg).should be true
93
+ RbNaCl::Util.verify16(msg, identical_msg).should be true
94
94
  end
95
95
 
96
96
  it "confirms non-identical messages are non-identical" do
97
- Crypto::Util.verify16(msg, other_msg).should be false
98
- Crypto::Util.verify16(other_msg, msg).should be false
99
- Crypto::Util.verify16(short_msg, msg).should be false
100
- Crypto::Util.verify16(msg, short_msg).should be false
101
- Crypto::Util.verify16(long_msg, msg).should be false
102
- Crypto::Util.verify16(msg, long_msg).should be false
97
+ RbNaCl::Util.verify16(msg, other_msg).should be false
98
+ RbNaCl::Util.verify16(other_msg, msg).should be false
99
+ RbNaCl::Util.verify16(short_msg, msg).should be false
100
+ RbNaCl::Util.verify16(msg, short_msg).should be false
101
+ RbNaCl::Util.verify16(long_msg, msg).should be false
102
+ RbNaCl::Util.verify16(msg, long_msg).should be false
103
103
  end
104
104
  end
105
+
105
106
  context "check_length" do
106
107
  it "accepts strings of the correct length" do
107
- expect { Crypto::Util.check_length("A"*4, 4, "Test String") }.not_to raise_error
108
+ expect { RbNaCl::Util.check_length("A"*4, 4, "Test String") }.not_to raise_error
108
109
  end
109
110
  it "rejects strings which are too short" do
110
- expect { Crypto::Util.check_length("A"*3, 4, "Test String") }.to raise_error(Crypto::LengthError, "Test String was 3 bytes (Expected 4)")
111
+ expect { RbNaCl::Util.check_length("A"*3, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 3 bytes (Expected 4)")
111
112
  end
112
113
  it "rejects strings which are too long" do
113
- expect { Crypto::Util.check_length("A"*5, 4, "Test String") }.to raise_error(Crypto::LengthError, "Test String was 5 bytes (Expected 4)")
114
+ expect { RbNaCl::Util.check_length("A"*5, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 5 bytes (Expected 4)")
114
115
  end
115
116
  it "rejects nil strings" do
116
- expect { Crypto::Util.check_length(nil, 4, "Test String") }.to raise_error(Crypto::LengthError, "Test String was nil (Expected 4)")
117
+ expect { RbNaCl::Util.check_length(nil, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was nil (Expected 4)")
118
+ end
119
+ end
120
+
121
+ context "hex encoding" do
122
+ let (:bytes) { [0xDE,0xAD,0xBE,0xEF].pack('c*') }
123
+ let (:hex) { "deadbeef" }
124
+
125
+ it "encodes to hex with bin2hex" do
126
+ RbNaCl::Util.bin2hex(bytes).should eq hex
127
+ end
128
+
129
+ it "decodes from hex with hex2bin" do
130
+ RbNaCl::Util.hex2bin(hex).should eq bytes
117
131
  end
118
132
  end
119
133
  end
@@ -1,29 +1,27 @@
1
1
  # encoding: binary
2
2
  shared_examples "authenticator" do
3
- let (:hex_key) { hex_vector :auth_key }
4
- let (:key) { test_vector :auth_key }
5
- let (:message) { test_vector :auth_message }
6
- let (:tag) { hex2bytes hex_tag }
3
+ let (:key) { vector :auth_key }
4
+ let (:message) { vector :auth_message }
7
5
 
8
6
  context ".new" do
9
7
  it "accepts a key" do
10
- expect { described_class.new(key) }.to_not raise_error(ArgumentError)
8
+ expect { described_class.new(key) }.to_not raise_error(ArgumentError)
11
9
  end
12
10
 
13
11
  it "requires a key" do
14
- expect { described_class.new }.to raise_error(ArgumentError)
12
+ expect { described_class.new }.to raise_error(ArgumentError)
15
13
  end
16
14
 
17
- it "raises on a nil key" do
18
- expect { described_class.new(nil) }.to raise_error(ArgumentError)
15
+ it "raises TypeError on a nil key" do
16
+ expect { described_class.new(nil) }.to raise_error(TypeError)
19
17
  end
20
18
 
21
- it "raises on a key which is too long" do
22
- expect { described_class.new("\0"*33) }.to raise_error(ArgumentError)
19
+ it "raises ArgumentError on a key which is too long" do
20
+ expect { described_class.new("\0"*33) }.to raise_error(ArgumentError)
23
21
  end
24
22
 
25
- it "raises on a key which is too short" do
26
- expect { described_class.new("\0"*31) }.to raise_error(ArgumentError)
23
+ it "raises ArgumentError on a key which is too short" do
24
+ expect { described_class.new("\0"*31) }.to raise_error(ArgumentError)
27
25
  end
28
26
  end
29
27
 
@@ -32,40 +30,41 @@ shared_examples "authenticator" do
32
30
  described_class.auth(key, message).should eq tag
33
31
  end
34
32
 
35
- it "raises on a nil key" do
36
- expect { described_class.auth(nil, message) }.to raise_error(ArgumentError)
33
+ it "raises TypeError on a nil key" do
34
+ expect { described_class.auth(nil, message) }.to raise_error(TypeError)
37
35
  end
38
36
 
39
- it "raises on a key which is too long" do
40
- expect { described_class.auth("\0"*33, message) }.to raise_error(ArgumentError)
37
+ it "raises ArgumentError on a key which is too long" do
38
+ expect { described_class.auth("\0"*33, message) }.to raise_error(ArgumentError)
41
39
  end
42
40
  end
43
41
 
44
42
  context ".verify" do
45
43
  it "verify an authenticator" do
46
- described_class.verify(key, message, tag).should eq true
44
+ described_class.verify(key, tag, message).should eq true
47
45
  end
48
46
 
49
- it "raises on a nil key" do
50
- expect { described_class.verify(nil, message, tag) }.to raise_error(ArgumentError)
47
+ it "raises TypeError on a nil key" do
48
+ expect { described_class.verify(nil, tag, message) }.to raise_error(TypeError)
51
49
  end
52
50
 
53
- it "raises on a key which is too long" do
54
- expect { described_class.verify("\0"*33, message, tag) }.to raise_error(ArgumentError)
51
+ it "raises ArgumentError on a key which is too long" do
52
+ expect { described_class.verify("\0"*33, tag, message) }.to raise_error(ArgumentError)
55
53
  end
56
54
 
57
55
  it "fails to validate an invalid authenticator" do
58
- described_class.verify(key, message+"\0", tag ).should be false
56
+ expect { described_class.verify(key, tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
59
57
  end
58
+
60
59
  it "fails to validate a short authenticator" do
61
- described_class.verify(key, message, tag[0,tag.bytesize - 2]).should be false
60
+ expect { described_class.verify(key, tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
62
61
  end
62
+
63
63
  it "fails to validate a long authenticator" do
64
- described_class.verify(key, message, tag+"\0").should be false
64
+ expect { described_class.verify(key, tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
65
65
  end
66
66
  end
67
67
 
68
-
69
68
  context "Instance methods" do
70
69
  let(:authenticator) { described_class.new(key) }
71
70
 
@@ -73,41 +72,23 @@ shared_examples "authenticator" do
73
72
  it "produces an authenticator" do
74
73
  authenticator.auth(message).should eq tag
75
74
  end
76
-
77
- it "produces a hex encoded authenticator" do
78
- authenticator.auth(message, :hex).should eq hex_tag
79
- end
80
75
  end
81
76
 
82
77
  context "#verify" do
83
- context "raw bytes" do
84
- it "verifies an authenticator" do
85
- authenticator.verify(message, tag).should be true
86
- end
87
- it "fails to validate an invalid authenticator" do
88
- authenticator.verify(tag, message+"\0").should be false
89
- end
90
- it "fails to validate a short authenticator" do
91
- authenticator.verify(tag[0,tag.bytesize - 2], message).should be false
92
- end
93
- it "fails to validate a long authenticator" do
94
- authenticator.verify(tag+"\0", message).should be false
95
- end
78
+ it "verifies an authenticator" do
79
+ authenticator.verify(tag, message).should be true
80
+ end
81
+
82
+ it "fails to validate an invalid authenticator" do
83
+ expect { authenticator.verify(tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
84
+ end
85
+
86
+ it "fails to validate a short authenticator" do
87
+ expect { authenticator.verify(tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
96
88
  end
97
89
 
98
- context "hex" do
99
- it "verifies an hexencoded authenticator" do
100
- authenticator.verify(message, hex_tag, :hex).should be true
101
- end
102
- it "fails to validate an invalid authenticator" do
103
- authenticator.verify(message+"\0", hex_tag , :hex).should be false
104
- end
105
- it "fails to validate a short authenticator" do
106
- authenticator.verify( message, hex_tag[0,hex_tag.bytesize - 2], :hex).should be false
107
- end
108
- it "fails to validate a long authenticator" do
109
- authenticator.verify(message, hex_tag+"00", :hex).should be false
110
- end
90
+ it "fails to validate a long authenticator" do
91
+ expect { authenticator.verify(tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
111
92
  end
112
93
  end
113
94
  end
data/spec/shared/box.rb CHANGED
@@ -3,12 +3,12 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  shared_examples "box" do
6
- let(:nonce) { test_vector :box_nonce }
6
+ let(:nonce) { vector :box_nonce }
7
7
  let(:invalid_nonce) { nonce[0,12] } # too short!
8
8
  let(:invalid_nonce_long) { nonce + nonce } # too long!
9
- let(:message) { test_vector :box_message }
10
- let(:ciphertext) { test_vector :box_ciphertext }
11
- let (:nonce_error_regex) { /Nonce.*(Expected #{Crypto::NaCl::NONCEBYTES})/ }
9
+ let(:message) { vector :box_message }
10
+ let(:ciphertext) { vector :box_ciphertext }
11
+ let (:nonce_error_regex) { /Nonce.*(Expected #{box.nonce_bytes})/ }
12
12
  let(:corrupt_ciphertext) { ciphertext[80] = " " } # picked at random by fair diceroll
13
13
 
14
14
  context "box" do
@@ -18,11 +18,11 @@ shared_examples "box" do
18
18
  end
19
19
 
20
20
  it "raises on a short nonce" do
21
- expect { box.box(invalid_nonce, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
21
+ expect { box.box(invalid_nonce, message) }.to raise_error(RbNaCl::LengthError, nonce_error_regex)
22
22
  end
23
23
 
24
24
  it "raises on a long nonce" do
25
- expect { box.box(invalid_nonce_long, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
25
+ expect { box.box(invalid_nonce_long, message) }.to raise_error(RbNaCl::LengthError, nonce_error_regex)
26
26
  end
27
27
  end
28
28
 
@@ -33,19 +33,19 @@ shared_examples "box" do
33
33
  end
34
34
 
35
35
  it "raises on a truncated message to decrypt" do
36
- expect { box.open(nonce, ciphertext[0, 64]) }.to raise_error(Crypto::CryptoError, /Decryption failed. Ciphertext failed verification./)
36
+ expect { box.open(nonce, ciphertext[0, 64]) }.to raise_error(RbNaCl::CryptoError, /Decryption failed. Ciphertext failed verification./)
37
37
  end
38
38
 
39
39
  it "raises on a corrupt ciphertext" do
40
- expect { box.open(nonce, corrupt_ciphertext) }.to raise_error(Crypto::CryptoError, /Decryption failed. Ciphertext failed verification./)
40
+ expect { box.open(nonce, corrupt_ciphertext) }.to raise_error(RbNaCl::CryptoError, /Decryption failed. Ciphertext failed verification./)
41
41
  end
42
42
 
43
43
  it "raises on a short nonce" do
44
- expect { box.open(invalid_nonce, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
44
+ expect { box.open(invalid_nonce, message) }.to raise_error(RbNaCl::LengthError, nonce_error_regex)
45
45
  end
46
46
 
47
47
  it "raises on a long nonce" do
48
- expect { box.open(invalid_nonce_long, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
48
+ expect { box.open(invalid_nonce_long, message) }.to raise_error(RbNaCl::LengthError, nonce_error_regex)
49
49
  end
50
50
  end
51
51
  end
@@ -8,7 +8,7 @@ shared_examples "key equality" do
8
8
  (key == key_bytes).should be true
9
9
  end
10
10
  it "keys are not equal to zero" do
11
- (key == Crypto::Util.zeros(32)).should be false
11
+ (key == RbNaCl::Util.zeros(32)).should be false
12
12
  end
13
13
  it "keys are not equal to another key" do
14
14
  (key == other_key).should be false
@@ -17,10 +17,10 @@ shared_examples "key equality" do
17
17
 
18
18
  context "lexicographic sorting" do
19
19
  it "can be compared lexicographically to a key smaller than it" do
20
- (key > Crypto::Util.zeros(32)).should be true
20
+ (key > RbNaCl::Util.zeros(32)).should be true
21
21
  end
22
22
  it "can be compared lexicographically to a key larger than it" do
23
- (described_class.new(Crypto::Util.zeros(32)) < key).should be true
23
+ (described_class.new(RbNaCl::Util.zeros(32)) < key).should be true
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,17 @@
1
+ # encoding: binary
2
+
3
+ shared_examples "serializable" do
4
+ context "serialization" do
5
+ it "supports #to_s" do
6
+ expect(subject.to_s).to be_a String
7
+ end
8
+
9
+ it "supports #to_str" do
10
+ expect(subject.to_str).to be_a String
11
+ end
12
+
13
+ it "supports #inspect" do
14
+ expect(subject.inspect).to be_a String
15
+ end
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,26 +1,25 @@
1
1
  # encoding: binary
2
- require 'rubygems'
2
+ require 'json'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ # Run the specs prior to running the self-test
7
+ $RBNACL_SELF_TEST = false
8
+
3
9
  require 'bundler/setup'
4
10
  require 'rbnacl'
5
11
  require 'shared/box'
6
12
  require 'shared/authenticator'
7
13
  require 'shared/key_equality'
8
- require 'coveralls'
9
-
10
- Coveralls.wear!
11
-
12
- def hex2bytes(hex)
13
- Crypto::Encoder[:hex].decode(hex)
14
- end
15
-
16
- def bytes2hex(bytes)
17
- Crypto::Encoder[:hex].encode(bytes)
18
- end
14
+ require 'shared/serializable'
19
15
 
20
- def test_vector(name)
21
- hex2bytes(hex_vector(name))
16
+ def vector(name)
17
+ [RbNaCl::TestVectors[name]].pack("H*")
22
18
  end
23
19
 
24
- def hex_vector(name)
25
- Crypto::TestVectors[name]
20
+ RSpec.configure do |config|
21
+ config.after :all do
22
+ # Run the self-test after all the specs have passed
23
+ require 'rbnacl/self_test'
24
+ end
26
25
  end
data/tasks/rspec.rake CHANGED
@@ -1,3 +1,4 @@
1
+ gem 'rspec'
1
2
  require 'rspec/core/rake_task'
2
3
 
3
4
  RSpec::Core::RakeTask.new
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- T\r�
2
- ��*=(�#?���x(�=�����D�k⚂n��~�I����T�l�TL�x�@aɰ��?X^�C1p�f��i���抰s�ֹ���&tADZ"�z<ڊ T9�k�w����h�_5���¾��U�lq��l0,�:�L�t�y���Y��x�'�Z���ÿ����*�5��<bjÅ *H� ���B�sY����4��gA�:c~�
3
- ��T���,�b �+��(���g�.��@.I�֩���1cR3m����d
1
+ ��aA�˥�P�$��9�~��b+;�w[!,�fƬ@Iս��a]s8�R�Fu�X|�K��va�a���! œ8���"��aŶ�K��kp�_�HĊ؜�?^n�e���b
2
+ �I��,*����00�?=���@]�w$K6g�L)F�G��e�>u�`�W:�Z�x�ʖ��@���!Cf�q'�^���Ȏ�mX�@|�C���%��kߑr��3���Q�O��(fUw�*��vr�R��z�_ƒ<�K��o
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbnacl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -31,7 +31,7 @@ cert_chain:
31
31
  3L/NVZQttSvxjd+WF6mA9yeCjpomboQMP36GRIZ30SoOVPMGvZ/+QpW52QU7mJW5
32
32
  GzWyf92p0uscgUZVTYixjg==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-04-19 00:00:00.000000000 Z
34
+ date: 2013-11-07 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ffi
@@ -67,14 +67,14 @@ dependencies:
67
67
  requirements:
68
68
  - - '>='
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: '2.14'
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '2.14'
78
78
  description: Ruby binding to the Networking and Cryptography (NaCl) library
79
79
  email:
80
80
  - tony.arcieri@gmail.com
@@ -90,6 +90,7 @@ files:
90
90
  - .yardopts
91
91
  - CHANGES.md
92
92
  - Gemfile
93
+ - Guardfile
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
@@ -100,60 +101,60 @@ files:
100
101
  - images/logo.png
101
102
  - lib/rbnacl.rb
102
103
  - lib/rbnacl/auth.rb
103
- - lib/rbnacl/auth/one_time.rb
104
- - lib/rbnacl/box.rb
105
- - lib/rbnacl/encoder.rb
106
- - lib/rbnacl/encoders/base32.rb
107
- - lib/rbnacl/encoders/base64.rb
108
- - lib/rbnacl/encoders/hex.rb
109
- - lib/rbnacl/encoders/raw.rb
104
+ - lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb
105
+ - lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb
106
+ - lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
107
+ - lib/rbnacl/group_elements/curve25519.rb
110
108
  - lib/rbnacl/hash.rb
109
+ - lib/rbnacl/hash/blake2b.rb
110
+ - lib/rbnacl/hash/sha256.rb
111
+ - lib/rbnacl/hash/sha512.rb
111
112
  - lib/rbnacl/hmac/sha256.rb
112
113
  - lib/rbnacl/hmac/sha512256.rb
113
- - lib/rbnacl/keys/key_comparator.rb
114
- - lib/rbnacl/keys/private_key.rb
115
- - lib/rbnacl/keys/public_key.rb
116
- - lib/rbnacl/keys/signing_key.rb
117
- - lib/rbnacl/keys/verify_key.rb
118
- - lib/rbnacl/nacl.rb
119
- - lib/rbnacl/point.rb
114
+ - lib/rbnacl/init.rb
115
+ - lib/rbnacl/key_comparator.rb
116
+ - lib/rbnacl/one_time_auths/poly1305.rb
120
117
  - lib/rbnacl/rake_tasks.rb
121
118
  - lib/rbnacl/random.rb
122
119
  - lib/rbnacl/random_nonce_box.rb
123
- - lib/rbnacl/secret_box.rb
120
+ - lib/rbnacl/secret_boxes/xsalsa20poly1305.rb
124
121
  - lib/rbnacl/self_test.rb
125
122
  - lib/rbnacl/serializable.rb
123
+ - lib/rbnacl/signatures/ed25519.rb
124
+ - lib/rbnacl/signatures/ed25519/signing_key.rb
125
+ - lib/rbnacl/signatures/ed25519/verify_key.rb
126
+ - lib/rbnacl/sodium.rb
127
+ - lib/rbnacl/sodium/version.rb
126
128
  - lib/rbnacl/test_vectors.rb
127
129
  - lib/rbnacl/util.rb
128
130
  - lib/rbnacl/version.rb
129
131
  - rbnacl.gemspec
130
132
  - rbnacl.gpg
131
- - spec/rbnacl/auth/one_time_spec.rb
132
- - spec/rbnacl/box_spec.rb
133
- - spec/rbnacl/encoder_spec.rb
134
- - spec/rbnacl/encoders/base32_spec.rb
135
- - spec/rbnacl/encoders/base64_spec.rb
136
- - spec/rbnacl/encoders/hex_spec.rb
133
+ - spec/rbnacl/authenticators/poly1305_spec.rb
134
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb
135
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305/public_key_spec.rb
136
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb
137
+ - spec/rbnacl/group_element_spec.rb
138
+ - spec/rbnacl/hash/blake2b_spec.rb
137
139
  - spec/rbnacl/hash_spec.rb
138
140
  - spec/rbnacl/hmac/sha256_spec.rb
139
141
  - spec/rbnacl/hmac/sha512256_spec.rb
140
- - spec/rbnacl/keys/private_key_spec.rb
141
- - spec/rbnacl/keys/public_key_spec.rb
142
- - spec/rbnacl/keys/signing_key_spec.rb
143
- - spec/rbnacl/keys/verify_key_spec.rb
144
- - spec/rbnacl/point_spec.rb
145
142
  - spec/rbnacl/random_nonce_box_spec.rb
146
143
  - spec/rbnacl/random_spec.rb
147
144
  - spec/rbnacl/secret_box_spec.rb
145
+ - spec/rbnacl/signatures/ed25519/signing_key_spec.rb
146
+ - spec/rbnacl/signatures/ed25519/verify_key_spec.rb
148
147
  - spec/rbnacl/util_spec.rb
149
148
  - spec/shared/authenticator.rb
150
149
  - spec/shared/box.rb
151
150
  - spec/shared/key_equality.rb
151
+ - spec/shared/serializable.rb
152
152
  - spec/spec_helper.rb
153
153
  - tasks/ci.rake
154
154
  - tasks/rspec.rake
155
155
  homepage: https://github.com/cryptosphere/rbnacl
156
- licenses: []
156
+ licenses:
157
+ - MIT
157
158
  metadata: {}
158
159
  post_install_message:
159
160
  rdoc_options: []
@@ -177,25 +178,23 @@ specification_version: 4
177
178
  summary: The Networking and Cryptography (NaCl) library provides a high-level toolkit
178
179
  for building cryptographic systems and protocols
179
180
  test_files:
180
- - spec/rbnacl/auth/one_time_spec.rb
181
- - spec/rbnacl/box_spec.rb
182
- - spec/rbnacl/encoder_spec.rb
183
- - spec/rbnacl/encoders/base32_spec.rb
184
- - spec/rbnacl/encoders/base64_spec.rb
185
- - spec/rbnacl/encoders/hex_spec.rb
181
+ - spec/rbnacl/authenticators/poly1305_spec.rb
182
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb
183
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305/public_key_spec.rb
184
+ - spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb
185
+ - spec/rbnacl/group_element_spec.rb
186
+ - spec/rbnacl/hash/blake2b_spec.rb
186
187
  - spec/rbnacl/hash_spec.rb
187
188
  - spec/rbnacl/hmac/sha256_spec.rb
188
189
  - spec/rbnacl/hmac/sha512256_spec.rb
189
- - spec/rbnacl/keys/private_key_spec.rb
190
- - spec/rbnacl/keys/public_key_spec.rb
191
- - spec/rbnacl/keys/signing_key_spec.rb
192
- - spec/rbnacl/keys/verify_key_spec.rb
193
- - spec/rbnacl/point_spec.rb
194
190
  - spec/rbnacl/random_nonce_box_spec.rb
195
191
  - spec/rbnacl/random_spec.rb
196
192
  - spec/rbnacl/secret_box_spec.rb
193
+ - spec/rbnacl/signatures/ed25519/signing_key_spec.rb
194
+ - spec/rbnacl/signatures/ed25519/verify_key_spec.rb
197
195
  - spec/rbnacl/util_spec.rb
198
196
  - spec/shared/authenticator.rb
199
197
  - spec/shared/box.rb
200
198
  - spec/shared/key_equality.rb
199
+ - spec/shared/serializable.rb
201
200
  - spec/spec_helper.rb