Debian Codegraph @

spec/rbnacl/boxes/curve25519xsalsa20poly1305/public_key_spec.rb

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