Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
21 test/sodium/auth/hmacsha256_test.rb
@@ -3,21 +3,26 @@
3 3 describe Sodium::Auth::HMACSHA256 do
4 4 subject { self.klass.new(self.key) }
5 5
6   - let(:klass) { Sodium::Auth::HMACSHA256 }
  6 + let(:klass) { Sodium::Auth::HMACSHA256 }
  7 + let(:primitive) { :hmacsha256 }
  8 +
  9 + let :constants do
  10 + { :BYTES => 32,
  11 + :KEYBYTES => 32, }
  12 + end
  13 +
7 14 let(:key) { Base64.decode64 'XMfWD8/yrcNDzJyGhxRIwi5tSGKf8D0ul9FyX/djvjg=' }
8 15 let(:authenticator) { Base64.decode64 '6WDKvxKevcZts0Yc1HWGnylNYEpcxPO9tVtApEK8XWc=' }
9 16 let(:plaintext) { 'message' }
10 17
11 18 it '::primitive must be correct' do
12   - self.klass.primitive.must_equal :hmacsha256
13   - end
14   -
15   - it '::BYTES must be correct' do
16   - self.klass::BYTES.must_equal 32
  19 + self.klass.primitive.must_equal self.primitive
17 20 end
18 21
19   - it '::KEYBYTES must be correct' do
20   - self.klass::KEYBYTES.must_equal 32
  22 + it 'must have correct values for its constants' do
  23 + self.constants.each_pair do |name, value|
  24 + self.klass[name].must_equal value
  25 + end
21 26 end
22 27
23 28 it 'must mint keys' do
24 test/sodium/auth/hmacsha512256_test.rb
@@ -3,26 +3,30 @@
3 3 describe Sodium::Auth::HMACSHA512256 do
4 4 subject { self.klass.new(self.key) }
5 5
6   - let(:klass) { Sodium::Auth::HMACSHA512256 }
  6 + let(:klass) { Sodium::Auth::HMACSHA512256 }
  7 + let(:primitive) { :hmacsha512256 }
  8 +
  9 + let :constants do
  10 + { :BYTES => 32,
  11 + :KEYBYTES => 32, }
  12 + end
  13 +
7 14 let(:key) { Base64.decode64 'XMfWD8/yrcNDzJyGhxRIwi5tSGKf8D0ul9FyX/djvjg=' }
8 15 let(:authenticator) { Base64.decode64 '6BN5+HNq0F8skQKkta+CLiBJ7mrrJaGw3G2J7jMT2qA=' }
9 16 let(:plaintext) { 'message' }
10 17
11 18 it '::primitive must be correct' do
12   - self.klass.primitive.must_equal :hmacsha512256
13   - end
14   -
15   - it '::BYTES must be correct' do
16   - self.klass::BYTES.must_equal 32
  19 + self.klass.primitive.must_equal self.primitive
17 20 end
18 21
19   - it '::KEYBYTES must be correct' do
20   - self.klass::KEYBYTES.must_equal 32
  22 + it 'must have correct values for its constants' do
  23 + self.constants.each_pair do |name, value|
  24 + self.klass[name].must_equal value
  25 + end
21 26 end
22 27
23 28 it 'must mint keys' do
24   - self.klass.key.length.
25   - must_equal self.klass::KEYBYTES
  29 + self.klass.key.length.must_equal self.klass[:KEYBYTES]
26 30 end
27 31
28 32 it 'must generate authenticators' do
77 test/sodium/box/curve25519xsalsa20poly1305_test.rb
... ... @@ -0,0 +1,77 @@
  1 +require 'test_helper'
  2 +
  3 +describe Sodium::Box::Curve25519XSalsa20Poly1305 do
  4 + subject { self.klass.new(self.secret_key, self.public_key) }
  5 +
  6 + let(:klass) { Sodium::Box::Curve25519XSalsa20Poly1305 }
  7 + let(:primitive) { :curve25519xsalsa20poly1305 }
  8 +
  9 + let :constants do
  10 + { :PUBLICKEYBYTES => 32,
  11 + :SECRETKEYBYTES => 32,
  12 + :BEFORENMBYTES => 32,
  13 + :NONCEBYTES => 24,
  14 + :ZEROBYTES => 32,
  15 + :BOXZEROBYTES => 16,
  16 + :MACBYTES => 16, }
  17 + end
  18 +
  19 + let(:secret_key) { Base64.decode64 'f52WNdyy0r1YA5NCGlcF+vJ5HPG8yfHwzn/HJSJzfQk=' }
  20 + let(:public_key) { Base64.decode64 'es8h5AH9GGD7PF10D1txeHAFAB2UNc9OZF+JqFWE9y8=' }
  21 + let(:shared_key) { Base64.decode64 'TTp8bQBhIuiiQ0plVcqS3Cj62i/IdAFnopx4t9di2Kg=' }
  22 + let(:nonce) { Base64.decode64 'i72xIDJ4tcHCOHGYAzI6PoiVm31PFVgx' }
  23 + let(:ciphertext) { Base64.decode64 'lHhCSFzopX4z02nlIuInHe3hFwpHFdA=' }
  24 + let(:plaintext) { 'message' }
  25 +
  26 + it '::primitive must be correct' do
  27 + self.klass.primitive.must_equal self.primitive
  28 + end
  29 +
  30 + it 'must have correct values for its constants' do
  31 + self.constants.each_pair do |name, value|
  32 + self.klass[name].must_equal value
  33 + end
  34 + end
  35 +
  36 + it 'must mint secret keys' do
  37 + self.klass.keypair[0].length.must_equal self.klass[:SECRETKEYBYTES]
  38 + end
  39 +
  40 + it 'must mint public keys' do
  41 + self.klass.keypair[1].length.must_equal self.klass[:PUBLICKEYBYTES]
  42 + end
  43 +
  44 + it 'must generate closed boxes' do
  45 + self.subject.box(
  46 + self.plaintext,
  47 + self.nonce
  48 + ).must_equal self.ciphertext
  49 + end
  50 +
  51 + it 'must open boxes' do
  52 + self.subject.open(
  53 + self.ciphertext,
  54 + self.nonce
  55 + ).must_equal self.plaintext
  56 + end
  57 +
  58 + it 'must generate shared keys' do
  59 + self.subject.beforenm.must_equal self.shared_key
  60 + end
  61 +
  62 + it 'must generate closed boxes with shared keys' do
  63 + self.subject.afternm(
  64 + self.shared_key,
  65 + self.plaintext,
  66 + self.nonce
  67 + ).must_equal self.ciphertext
  68 + end
  69 +
  70 + it 'must open boxes with shared keys' do
  71 + self.subject.open_afternm(
  72 + self.shared_key,
  73 + self.ciphertext,
  74 + self.nonce
  75 + ).must_equal self.plaintext
  76 + end
  77 +end
4 test/sodium/delegate_test.rb
@@ -22,6 +22,10 @@ class Subclass2 < self; PRIMITIVE = :subclass2; end
22 22 self.klass.implementation.must_equal self.subclass
23 23 end
24 24
  25 + it 'must allow access to constants through indexing' do
  26 + self.klass.implementation[:PRIMITIVE].must_equal :subclass1
  27 + end
  28 +
25 29 it 'must allow access to arbitrary implementations' do
26 30 self.klass.implementation(:subclass2).must_equal DelegateTest::Subclass2
27 31 end
2  test/test_helper.rb
@@ -24,7 +24,7 @@ def sodium_override_default(klass, implementation)
24 24
25 25 def sodium_mock_default(klass)
26 26 mock = MiniTest::Mock.new
27   - sodium_override_default(klass, mock) {|klass| yield klass, mock }
  27 + sodium_override_default(klass, mock) {|dup| yield dup, mock }
28 28 mock.verify
29 29 end
30 30

No commit comments for this range

Something went wrong with that request. Please try again.