rbnacl 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -0
  3. data/.travis.yml +4 -3
  4. data/CHANGES.md +5 -0
  5. data/Gemfile +8 -3
  6. data/Guardfile +1 -1
  7. data/README.md +5 -6
  8. data/Rakefile +3 -2
  9. data/lib/rbnacl.rb +1 -1
  10. data/lib/rbnacl/auth.rb +21 -8
  11. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb +17 -13
  12. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305/private_key.rb +68 -65
  13. data/lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb +49 -47
  14. data/lib/rbnacl/group_elements/curve25519.rb +14 -8
  15. data/lib/rbnacl/hash.rb +2 -2
  16. data/lib/rbnacl/hash/blake2b.rb +13 -13
  17. data/lib/rbnacl/hash/sha256.rb +5 -5
  18. data/lib/rbnacl/hash/sha512.rb +5 -5
  19. data/lib/rbnacl/hmac/sha256.rb +12 -11
  20. data/lib/rbnacl/hmac/sha512256.rb +11 -10
  21. data/lib/rbnacl/init.rb +1 -1
  22. data/lib/rbnacl/key_comparator.rb +3 -3
  23. data/lib/rbnacl/one_time_auths/poly1305.rb +4 -4
  24. data/lib/rbnacl/password_hash/scrypt.rb +10 -11
  25. data/lib/rbnacl/random.rb +2 -2
  26. data/lib/rbnacl/secret_boxes/xsalsa20poly1305.rb +28 -14
  27. data/lib/rbnacl/self_test.rb +17 -37
  28. data/lib/rbnacl/serializable.rb +9 -4
  29. data/lib/rbnacl/signatures/ed25519.rb +1 -0
  30. data/lib/rbnacl/signatures/ed25519/signing_key.rb +17 -9
  31. data/lib/rbnacl/signatures/ed25519/verify_key.rb +17 -6
  32. data/lib/rbnacl/simple_box.rb +6 -3
  33. data/lib/rbnacl/sodium.rb +6 -7
  34. data/lib/rbnacl/sodium/version.rb +3 -2
  35. data/lib/rbnacl/test_vectors.rb +57 -55
  36. data/lib/rbnacl/util.rb +12 -11
  37. data/lib/rbnacl/version.rb +3 -1
  38. data/rbnacl.gemspec +6 -8
  39. data/spec/rbnacl/authenticators/poly1305_spec.rb +1 -1
  40. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305/private_key_spec.rb +1 -1
  41. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305/public_key_spec.rb +1 -1
  42. data/spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb +2 -2
  43. data/spec/rbnacl/group_element_spec.rb +1 -1
  44. data/spec/rbnacl/hash/blake2b_spec.rb +1 -1
  45. data/spec/rbnacl/hash_spec.rb +1 -1
  46. data/spec/rbnacl/hmac/sha256_spec.rb +1 -1
  47. data/spec/rbnacl/hmac/sha512256_spec.rb +1 -1
  48. data/spec/rbnacl/password_hash/scrypt_spec.rb +3 -3
  49. data/spec/rbnacl/secret_box_spec.rb +3 -3
  50. data/spec/rbnacl/signatures/ed25519/signing_key_spec.rb +2 -2
  51. data/spec/rbnacl/signatures/ed25519/verify_key_spec.rb +12 -7
  52. data/spec/rbnacl/simple_box_spec.rb +2 -2
  53. data/spec/rbnacl/util_spec.rb +28 -29
  54. data/spec/shared/authenticator.rb +12 -12
  55. data/spec/shared/box.rb +2 -4
  56. data/spec/spec_helper.rb +11 -18
  57. data/tasks/rspec.rake +2 -2
  58. data/tasks/rubocop.rake +1 -1
  59. metadata +4 -5
  60. data/lib/rbnacl/rake_tasks.rb +0 -57
  61. data/tasks/ci.rake +0 -11
@@ -1,5 +1,7 @@
1
1
  # encoding: binary
2
+
3
+ # NaCl/libsodium for Ruby
2
4
  module RbNaCl
3
5
  # The library's version
4
- VERSION = "3.1.2"
6
+ VERSION = "3.2.0"
5
7
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rbnacl/version'
4
+ require "rbnacl/version"
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "rbnacl"
@@ -11,16 +11,14 @@ Gem::Specification.new do |gem|
11
11
  gem.description = "Ruby binding to the Networking and Cryptography (NaCl) library"
12
12
  gem.summary = "The Networking and Cryptography (NaCl) library provides a high-level toolkit for building cryptographic systems and protocols"
13
13
  gem.homepage = "https://github.com/cryptosphere/rbnacl"
14
- gem.licenses = ['MIT']
14
+ gem.licenses = ["MIT"]
15
15
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- if defined? JRUBY_VERSION
22
- gem.platform = "jruby"
23
- end
21
+ gem.platform = "jruby" if defined? JRUBY_VERSION
24
22
 
25
23
  gem.add_runtime_dependency "ffi"
26
24
 
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::OneTimeAuth do
5
5
  let(:tag) { vector :auth_onetime }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::PrivateKey do
5
5
  let(:bobsk) { vector :bob_private }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::PublicKey do
5
5
  let(:alicepk) { vector :alice_public }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::Box do
5
5
  let(:alicepk) { vector :alice_public }
@@ -33,7 +33,7 @@ RSpec.describe RbNaCl::Box do
33
33
  end
34
34
  end
35
35
 
36
- include_examples 'box' do
36
+ include_examples "box" do
37
37
  let(:box) { RbNaCl::Box.new(alicepk, bobsk) }
38
38
  end
39
39
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::GroupElement do
5
5
  let(:alice_private) { vector :alice_private }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::Hash::Blake2b do
5
5
  let(:reference_string) { vector :blake2b_message }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::Hash do
5
5
  context "sha256" do
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::HMAC::SHA256 do
5
5
  let(:tag) { vector :auth_hmacsha256 }
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::HMAC::SHA512256 do
5
5
  let(:tag) { vector :auth_hmacsha512256 }
@@ -1,11 +1,11 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::PasswordHash::SCrypt do
5
5
  let(:reference_password) { vector :scrypt_password }
6
6
  let(:reference_salt) { vector :scrypt_salt }
7
- let(:reference_opslimit) { RbNaCl::TestVectors[:scrypt_opslimit] }
8
- let(:reference_memlimit) { RbNaCl::TestVectors[:scrypt_memlimit] }
7
+ let(:reference_opslimit) { RbNaCl::TEST_VECTORS[:scrypt_opslimit] }
8
+ let(:reference_memlimit) { RbNaCl::TEST_VECTORS[:scrypt_memlimit] }
9
9
  let(:reference_digest) { vector :scrypt_digest }
10
10
 
11
11
  it "calculates the correct digest for a reference password/salt" do
@@ -1,8 +1,8 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::SecretBox do
5
- let (:key) { vector :secret_key }
5
+ let(:key) { vector :secret_key }
6
6
 
7
7
  context "new" do
8
8
  it "accepts strings" do
@@ -14,7 +14,7 @@ RSpec.describe RbNaCl::SecretBox do
14
14
  end
15
15
 
16
16
  it "raises on a short key" do
17
- expect { RbNaCl::SecretBox.new("hello") }.to raise_error(RbNaCl::LengthError, "Secret key was 5 bytes \(Expected #{RbNaCl::SecretBox::KEYBYTES}\)")
17
+ expect { RbNaCl::SecretBox.new("hello") }.to raise_error RbNaCl::LengthError
18
18
  end
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::SigningKey do
5
5
  let(:signing_key) { vector :sign_private }
@@ -23,7 +23,7 @@ RSpec.describe RbNaCl::SigningKey do
23
23
  include_examples "key equality" do
24
24
  let(:key_bytes) { signing_key }
25
25
  let(:key) { described_class.new(key_bytes) }
26
- let(:other_key) { described_class.new("B"*32) }
26
+ let(:other_key) { described_class.new("B" * 32) }
27
27
  end
28
28
 
29
29
  include_examples "serializable"
@@ -1,11 +1,16 @@
1
1
  # encoding: binary
2
2
  RSpec.describe RbNaCl::VerifyKey do
3
- let(:signing_key) { vector :sign_private }
4
- let(:verify_key) { vector :sign_public }
3
+ let(:signing_key) { vector :sign_private }
4
+ let(:verify_key) { vector :sign_public }
5
5
 
6
- let(:message) { vector :sign_message }
7
- let(:signature) { vector :sign_signature }
8
- let(:bad_signature) { sig = signature.dup; sig[0] = (sig[0].ord + 1).chr; sig }
6
+ let(:message) { vector :sign_message }
7
+ let(:signature) { vector :sign_signature }
8
+
9
+ let(:bad_signature) do
10
+ sig = signature.dup
11
+ sig[0] = (sig[0].ord + 1).chr
12
+ sig
13
+ end
9
14
 
10
15
  subject { RbNaCl::SigningKey.new(signing_key).verify_key }
11
16
 
@@ -18,7 +23,7 @@ RSpec.describe RbNaCl::VerifyKey do
18
23
  end
19
24
 
20
25
  it "raises when asked to verify a short signature" do
21
- expect { subject.verify(bad_signature[0,63], message) }.to raise_exception RbNaCl::LengthError
26
+ expect { subject.verify(bad_signature[0, 63], message) }.to raise_exception RbNaCl::LengthError
22
27
  end
23
28
 
24
29
  it "serializes to bytes" do
@@ -32,7 +37,7 @@ RSpec.describe RbNaCl::VerifyKey do
32
37
  include_examples "key equality" do
33
38
  let(:key_bytes) { verify_key }
34
39
  let(:key) { described_class.new(verify_key) }
35
- let(:other_key) { described_class.new("B"*32) }
40
+ let(:other_key) { described_class.new("B" * 32) }
36
41
  end
37
42
 
38
43
  include_examples "serializable"
@@ -1,5 +1,5 @@
1
1
  # encoding: binary
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
4
  RSpec.describe RbNaCl::SimpleBox do
5
5
  let(:secret_key) { vector :secret_key }
@@ -51,7 +51,7 @@ RSpec.describe RbNaCl::SimpleBox do
51
51
  end
52
52
 
53
53
  it "decrypts a message with a 'random' nonce" do
54
- expect(bob.decrypt(nonce+ciphertext)).to eql message
54
+ expect(bob.decrypt(nonce + ciphertext)).to eql message
55
55
  end
56
56
  end
57
57
  end
@@ -1,11 +1,11 @@
1
1
  # encoding: binary
2
2
  RSpec.describe RbNaCl::Util do
3
3
  context ".verify32!" do
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) }
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
11
  expect(RbNaCl::Util.verify32!(msg, identical_msg)).to be true
@@ -29,13 +29,13 @@ RSpec.describe RbNaCl::Util do
29
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) { 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) }
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
41
  expect(RbNaCl::Util.verify32(msg, identical_msg)).to be true
@@ -49,15 +49,14 @@ RSpec.describe RbNaCl::Util do
49
49
  expect(RbNaCl::Util.verify32(long_msg, msg)).to be false
50
50
  expect(RbNaCl::Util.verify32(msg, long_msg)).to be false
51
51
  end
52
-
53
52
  end
54
53
 
55
54
  context ".verify16!" do
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) }
55
+ let(:msg) { RbNaCl::Util.zeros(16) }
56
+ let(:identical_msg) { RbNaCl::Util.zeros(16) }
57
+ let(:other_msg) { RbNaCl::Util.zeros(15) + "\001" }
58
+ let(:short_msg) { RbNaCl::Util.zeros(15) }
59
+ let(:long_msg) { RbNaCl::Util.zeros(17) }
61
60
 
62
61
  it "confirms identical messages are identical" do
63
62
  expect(RbNaCl::Util.verify16!(msg, identical_msg)).to be true
@@ -81,13 +80,13 @@ RSpec.describe RbNaCl::Util do
81
80
  expect { RbNaCl::Util.verify16!(msg, long_msg) }.to raise_error(RbNaCl::LengthError)
82
81
  end
83
82
  end
84
-
83
+
85
84
  context ".verify16" do
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) }
85
+ let(:msg) { RbNaCl::Util.zeros(16) }
86
+ let(:identical_msg) { RbNaCl::Util.zeros(16) }
87
+ let(:other_msg) { RbNaCl::Util.zeros(15) + "\001" }
88
+ let(:short_msg) { RbNaCl::Util.zeros(15) }
89
+ let(:long_msg) { RbNaCl::Util.zeros(17) }
91
90
 
92
91
  it "confirms identical messages are identical" do
93
92
  expect(RbNaCl::Util.verify16(msg, identical_msg)).to be true
@@ -105,13 +104,13 @@ RSpec.describe RbNaCl::Util do
105
104
 
106
105
  context "check_length" do
107
106
  it "accepts strings of the correct length" do
108
- expect { RbNaCl::Util.check_length("A"*4, 4, "Test String") }.not_to raise_error
107
+ expect { RbNaCl::Util.check_length("A" * 4, 4, "Test String") }.not_to raise_error
109
108
  end
110
109
  it "rejects strings which are too short" do
111
- expect { RbNaCl::Util.check_length("A"*3, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 3 bytes (Expected 4)")
110
+ expect { RbNaCl::Util.check_length("A" * 3, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 3 bytes (Expected 4)")
112
111
  end
113
112
  it "rejects strings which are too long" do
114
- expect { RbNaCl::Util.check_length("A"*5, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 5 bytes (Expected 4)")
113
+ expect { RbNaCl::Util.check_length("A" * 5, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was 5 bytes (Expected 4)")
115
114
  end
116
115
  it "rejects nil strings" do
117
116
  expect { RbNaCl::Util.check_length(nil, 4, "Test String") }.to raise_error(RbNaCl::LengthError, "Test String was nil (Expected 4)")
@@ -121,7 +120,7 @@ RSpec.describe RbNaCl::Util do
121
120
  context "check_string" do
122
121
  it "raises EncodingError when given strings with non-BINARY encoding" do
123
122
  string = "foobar"
124
- string.force_encoding('UTF-8')
123
+ string.force_encoding("UTF-8")
125
124
  expect do
126
125
  RbNaCl::Util.check_string(string, string.bytesize, "encoding test")
127
126
  end.to raise_error(EncodingError)
@@ -129,8 +128,8 @@ RSpec.describe RbNaCl::Util do
129
128
  end
130
129
 
131
130
  context "hex encoding" do
132
- let (:bytes) { [0xDE,0xAD,0xBE,0xEF].pack('c*') }
133
- let (:hex) { "deadbeef" }
131
+ let(:bytes) { [0xDE, 0xAD, 0xBE, 0xEF].pack("c*") }
132
+ let(:hex) { "deadbeef" }
134
133
 
135
134
  it "encodes to hex with bin2hex" do
136
135
  expect(RbNaCl::Util.bin2hex(bytes)).to eq hex
@@ -1,7 +1,7 @@
1
1
  # encoding: binary
2
2
  RSpec.shared_examples "authenticator" do
3
- let (:key) { vector :auth_key }
4
- let (:message) { vector :auth_message }
3
+ let(:key) { vector :auth_key }
4
+ let(:message) { vector :auth_message }
5
5
 
6
6
  context ".new" do
7
7
  it "accepts a key" do
@@ -17,11 +17,11 @@ RSpec.shared_examples "authenticator" do
17
17
  end
18
18
 
19
19
  it "raises ArgumentError on a key which is too long" do
20
- expect { described_class.new("\0"*33) }.to raise_error(ArgumentError)
20
+ expect { described_class.new("\0" * 33) }.to raise_error(ArgumentError)
21
21
  end
22
22
 
23
23
  it "raises ArgumentError on a key which is too short" do
24
- expect { described_class.new("\0"*31) }.to raise_error(ArgumentError)
24
+ expect { described_class.new("\0" * 31) }.to raise_error(ArgumentError)
25
25
  end
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ RSpec.shared_examples "authenticator" do
35
35
  end
36
36
 
37
37
  it "raises ArgumentError on a key which is too long" do
38
- expect { described_class.auth("\0"*33, message) }.to raise_error(ArgumentError)
38
+ expect { described_class.auth("\0" * 33, message) }.to raise_error(ArgumentError)
39
39
  end
40
40
  end
41
41
 
@@ -49,19 +49,19 @@ RSpec.shared_examples "authenticator" do
49
49
  end
50
50
 
51
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)
52
+ expect { described_class.verify("\0" * 33, tag, message) }.to raise_error(ArgumentError)
53
53
  end
54
54
 
55
55
  it "fails to validate an invalid authenticator" do
56
- expect { described_class.verify(key, tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
56
+ expect { described_class.verify(key, tag, message + "\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
57
57
  end
58
58
 
59
59
  it "fails to validate a short authenticator" do
60
- expect { described_class.verify(key, tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
60
+ expect { described_class.verify(key, tag[0, tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
61
61
  end
62
62
 
63
63
  it "fails to validate a long authenticator" do
64
- expect { described_class.verify(key, tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
64
+ expect { described_class.verify(key, tag + "\0", message) }.to raise_error(RbNaCl::LengthError)
65
65
  end
66
66
  end
67
67
 
@@ -80,15 +80,15 @@ RSpec.shared_examples "authenticator" do
80
80
  end
81
81
 
82
82
  it "fails to validate an invalid authenticator" do
83
- expect { authenticator.verify(tag, message+"\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
83
+ expect { authenticator.verify(tag, message + "\0") }.to raise_error(RbNaCl::BadAuthenticatorError)
84
84
  end
85
85
 
86
86
  it "fails to validate a short authenticator" do
87
- expect { authenticator.verify(tag[0,tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
87
+ expect { authenticator.verify(tag[0, tag.bytesize - 2], message) }.to raise_error(RbNaCl::LengthError)
88
88
  end
89
89
 
90
90
  it "fails to validate a long authenticator" do
91
- expect { authenticator.verify(tag+"\0", message) }.to raise_error(RbNaCl::LengthError)
91
+ expect { authenticator.verify(tag + "\0", message) }.to raise_error(RbNaCl::LengthError)
92
92
  end
93
93
  end
94
94
  end
@@ -2,15 +2,14 @@
2
2
 
3
3
  RSpec.shared_examples "box" do
4
4
  let(:nonce) { vector :box_nonce }
5
- let(:invalid_nonce) { nonce[0,12] } # too short!
5
+ let(:invalid_nonce) { nonce[0, 12] } # too short!
6
6
  let(:invalid_nonce_long) { nonce + nonce } # too long!
7
7
  let(:message) { vector :box_message }
8
8
  let(:ciphertext) { vector :box_ciphertext }
9
- let (:nonce_error_regex) { /Nonce.*(Expected #{box.nonce_bytes})/ }
9
+ let(:nonce_error_regex) { /Nonce.*(Expected #{box.nonce_bytes})/ }
10
10
  let(:corrupt_ciphertext) { ciphertext[80] = " " } # picked at random by fair diceroll
11
11
 
12
12
  context "box" do
13
-
14
13
  it "encrypts a message" do
15
14
  expect(box.box(nonce, message)).to eq ciphertext
16
15
  end
@@ -25,7 +24,6 @@ RSpec.shared_examples "box" do
25
24
  end
26
25
 
27
26
  context "open" do
28
-
29
27
  it "decrypts a message" do
30
28
  expect(box.open(nonce, ciphertext)).to eq message
31
29
  end
@@ -1,34 +1,27 @@
1
1
  # encoding: binary
2
- require 'json'
3
- require 'coveralls'
2
+ require "json"
3
+ require "coveralls"
4
4
  Coveralls.wear!
5
5
 
6
6
  # Run the specs prior to running the self-test
7
7
  $RBNACL_SELF_TEST = false
8
8
 
9
- require 'bundler/setup'
10
- require 'rbnacl'
11
- require 'shared/box'
12
- require 'shared/authenticator'
13
- require 'shared/key_equality'
14
- require 'shared/serializable'
9
+ require "bundler/setup"
10
+ require "rbnacl/libsodium"
11
+ require "shared/box"
12
+ require "shared/authenticator"
13
+ require "shared/key_equality"
14
+ require "shared/serializable"
15
15
 
16
16
  def vector(name)
17
- [RbNaCl::TestVectors[name]].pack("H*")
17
+ [RbNaCl::TEST_VECTORS[name]].pack("H*")
18
18
  end
19
19
 
20
20
  RSpec.configure do |config|
21
21
  config.after :all do
22
22
  # Run the self-test after all the specs have passed
23
- require 'rbnacl/self_test'
23
+ require "rbnacl/self_test"
24
24
  end
25
25
 
26
- # Setting this config option `false` removes rspec-core's monkey patching of the
27
- # top level methods like `describe`, `shared_examples_for` and `shared_context`
28
- # on `main` and `Module`. The methods are always available through the `RSpec`
29
- # module like `RSpec.describe` regardless of this setting.
30
- # For backwards compatibility this defaults to `true`.
31
- #
32
- # https://relishapp.com/rspec/rspec-core/v/3-0/docs/configuration/global-namespace-dsl
33
- config.expose_dsl_globally = false
26
+ config.disable_monkey_patching!
34
27
  end