From c470ef88655408027d7ca01fa439daa582222b9d Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Mon, 16 Sep 2019 01:51:54 -0700 Subject: [PATCH] Add Nonce spec. --- spec/sodium/nonce_spec.cr | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/sodium/nonce_spec.cr diff --git a/spec/sodium/nonce_spec.cr b/spec/sodium/nonce_spec.cr new file mode 100644 index 0000000..1420beb --- /dev/null +++ b/spec/sodium/nonce_spec.cr @@ -0,0 +1,31 @@ +require "../spec_helper" +require "../../src/sodium/nonce" + +zero = Bytes.new(Sodium::Nonce::NONCE_SIZE) +one = Bytes.new(Sodium::Nonce::NONCE_SIZE).dup +one[0] = 1_u8 + +describe Sodium::Nonce do + it "generates a random nonce" do + nonce = Sodium::Nonce.random + nonce.should_not eq zero + end + + it "loads an existing nonce" do + nonce = Sodium::Nonce.new one + nonce.to_slice.should eq one + end + + it "zero nonce with increment" do + nonce = Sodium::Nonce.zero + nonce.to_slice.should eq zero + + nonce.used?.should be_false + nonce.used! + nonce.used?.should be_true + + nonce.increment + nonce.to_slice.should eq one + nonce.used?.should be_false + end +end