Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: stouset/sodium
base: f918090e11
...
head fork: stouset/sodium
compare: ccc0f7ce7d
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
2  test/sodium/auth_test.rb
View
@@ -33,7 +33,7 @@
must_raise Sodium::LengthError
end
- it 'must raise when verifying an invalid authenticators' do
+ it 'must raise when verifying an invalid authenticator' do
lambda { self.subject.verify('message', 'blaaah') }.
must_raise Sodium::LengthError
end
52 test/sodium/one_time_auth/poly1305.rb
View
@@ -0,0 +1,52 @@
+require 'test_helper'
+
+describe Sodium::OneTimeAuth::Poly1305 do
+ subject { self.klass.new(self.key) }
+
+ let(:klass) { Sodium::OneTimeAuth::Poly1305 }
+ let(:primitive) { :poly1305 }
+
+ let :constants do
+ { :BYTES => 16,
+ :KEYBYTES => 32, }
+ end
+
+ let(:key) { Base64.decode64 'tZUeTVtSHOfgOei4DUwCt10xqrIYhALpO08NIDMWFB0=' }
+ let(:authenticator) { Base64.decode64 'n+6StqC6SLRuLT8YZoQoFw==' }
+ let(:plaintext) { 'message' }
+
+ it '::primitive must be correct' do
+ self.klass.primitive.must_equal self.primitive
+ end
+
+ it 'must have correct values for its constants' do
+ self.constants.each_pair do |name, value|
+ self.klass[name].must_equal value
+ end
+ end
+
+ it 'must mint keys' do
+ self.klass.key.length.
+ must_equal self.klass::KEYBYTES
+ end
+
+ it 'must generate authenticators' do
+ self.subject.auth(
+ self.plaintext
+ ).must_equal self.authenticator
+ end
+
+ it 'must verify authenticators' do
+ self.subject.verify(
+ self.plaintext,
+ self.authenticator
+ ).must_equal true
+ end
+
+ it 'must not verify forged authenticators' do
+ self.subject.verif(
+ self.plaintext,
+ self.authenticator.suck
+ ).must_equal false
+ end
+end
47 test/sodium/one_time_auth_test.rb
View
@@ -0,0 +1,47 @@
+require 'test_helper'
+
+describe Sodium::OneTimeAuth do
+ subject { self.klass.new(self.key) }
+ let(:klass) { Sodium::OneTimeAuth }
+ let(:key) { self.klass.key }
+
+ it 'must default to the Poly1305 implementation' do
+ self.klass.implementation.
+ must_equal Sodium::OneTimeAuth::Poly1305
+ end
+
+ it 'must allow access to alternate implementations' do
+ self.klass.implementation(:foo).
+ must_equal nil
+ end
+
+ it 'must instantiate the default implementation' do
+ self.subject.
+ must_be_kind_of Sodium::OneTimeAuth::Poly1305
+ end
+
+ it 'must mint keys from the default implementation' do
+ sodium_mock_default(self.klass) do |klass, mock|
+ mock.expect :[], 0, [:KEYBYTES]
+
+ klass.key.length.must_equal 0
+ end
+ end
+
+ it 'must raise when instantiating with an invalid key' do
+ lambda { self.klass.new(self.key[0..-2]) }.
+ must_raise Sodium::LengthError
+ end
+
+ it 'must raise when verifying an invalid authenticator' do
+ lambda { self.subject.verify('message', 'blaah') }.
+ must_raise Sodium::LengthError
+ end
+
+ it 'must raise when failing to generate an authenticator' do
+ sodium_stub_failure(self.klass, :nacl) do
+ lambda { self.subject.one_time_auth('message') }.
+ must_raise Sodium::CryptoError
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.