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

https://github.com/delowong/logstash · Ruby · 42 lines · 32 code · 9 blank · 1 comment · 0 complexity · d430cb9a6e01e5def68242e40f53c082 MD5 · raw file

  1. # encoding: binary
  2. require 'spec_helper'
  3. describe RbNaCl::PublicKey do
  4. let(:alicepk) { vector :alice_public }
  5. subject { RbNaCl::PublicKey.new(alicepk) }
  6. context "new" do
  7. it "accepts a valid key" do
  8. expect { RbNaCl::PublicKey.new(alicepk) }.not_to raise_error
  9. end
  10. it "rejects a nil key" do
  11. expect { RbNaCl::PublicKey.new(nil) }.to raise_error(TypeError)
  12. end
  13. it "rejects a short key" do
  14. expect { RbNaCl::PublicKey.new("short") }.to raise_error(ArgumentError)
  15. end
  16. end
  17. context "#to_bytes" do
  18. it "returns the bytes of the key" do
  19. subject.to_bytes.should eq alicepk
  20. end
  21. end
  22. context "#to_s" do
  23. it "returns the bytes of the key" do
  24. subject.to_s.should eq alicepk
  25. end
  26. end
  27. include_examples "key equality" do
  28. let(:key) { subject }
  29. let(:key_bytes) { subject.to_bytes }
  30. let(:other_key) { described_class.new(alicepk.succ) }
  31. end
  32. include_examples "serializable"
  33. end