PageRenderTime 31ms CodeModel.GetById 20ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/vendor/bundle/jruby/2.1/gems/rbnacl-3.0.1/spec/rbnacl/boxes/curve25519xsalsa20poly1305_spec.rb

https://github.com/delowong/logstash
Ruby | 39 lines | 30 code | 8 blank | 1 comment | 0 complexity | 9f8ba712926c0b21c5b7bdc02e029f9e MD5 | raw file
 1# encoding: binary
 2require 'spec_helper'
 3
 4describe 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
39end