Sha256: a27acf0be425f9c128b08a481b5cb290dc21865cc9b7f94bf936cee35dd91962

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# encoding: binary
require 'spec_helper'

describe RbNaCl::RandomNonceBox do
  let(:secret_key) { vector :secret_key }
  let(:secret_box) { RbNaCl::SecretBox.new(secret_key) }
  let(:alicepk)    { vector :alice_public }
  let(:bobsk)      { vector :bob_private }

  context "instantiation" do
    it "can be instantiated from an already existing box" do
      expect { RbNaCl::RandomNonceBox.new(secret_box) }.not_to raise_error
    end

    it "can be instantiated from a secret key" do
      RbNaCl::RandomNonceBox.from_secret_key(secret_key).should be_a RbNaCl::RandomNonceBox
    end

    it "raises TypeError when given a nil secret key" do
      expect { RbNaCl::RandomNonceBox.from_secret_key(nil) }.to raise_error(TypeError)
    end

    it "can be instantiated from a key-pair" do
      RbNaCl::RandomNonceBox.from_keypair(alicepk, bobsk).should be_a RbNaCl::RandomNonceBox
    end

    it "raises TypeError when given nil secret keys in the pair" do
      expect { RbNaCl::RandomNonceBox.from_keypair(nil, bobsk) }.to raise_error(TypeError)
      expect { RbNaCl::RandomNonceBox.from_keypair(alicepk, nil) }.to raise_error(TypeError)
    end
  end

  context "cryptography" do
    let(:nonce)      { vector :box_nonce }
    let(:message)    { vector :box_message }
    let(:ciphertext) { vector :box_ciphertext }
    let(:random_box) { RbNaCl::RandomNonceBox.from_keypair(alicepk, bobsk) }
    let(:enciphered_message) { random_box.box(message) }
    let(:enciphered_message_hex) { random_box.box(message) }

    it "descrypts a message with a 'random' nonce" do
      random_box.open(nonce+ciphertext).should eql message
    end

    it "can successfully round-trip a message" do
      random_box.open(enciphered_message).should eql message
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbnacl-2.0.0 spec/rbnacl/random_nonce_box_spec.rb
rbnacl-2.0.0.pre spec/rbnacl/random_nonce_box_spec.rb