2021-06-13 01:04:49 +02:00
|
|
|
require "./spec_helper"
|
2021-06-13 02:42:07 +02:00
|
|
|
require "../src/crypto-secret/not"
|
2021-06-13 01:04:49 +02:00
|
|
|
|
|
|
|
describe Crypto::Secret::Not do
|
|
|
|
it "works" do
|
|
|
|
ksize = 32
|
2021-06-13 21:52:05 +02:00
|
|
|
key = Bytes.new ksize
|
|
|
|
key[1] = 1_u8
|
|
|
|
|
|
|
|
secret1 = Crypto::Secret::Not.new key.dup
|
2021-06-14 03:54:45 +02:00
|
|
|
secret1.to_slice { |s| s.should eq key }
|
2021-06-13 21:52:05 +02:00
|
|
|
|
|
|
|
secret2 = Crypto::Secret::Not.new key.dup
|
|
|
|
|
|
|
|
(secret1 == secret2).should be_true
|
2021-06-14 03:54:45 +02:00
|
|
|
secret1.to_slice do |s1|
|
|
|
|
secret2.to_slice do |s2|
|
|
|
|
(s1 == s2).should be_true
|
|
|
|
end
|
|
|
|
end
|
2021-06-13 01:04:49 +02:00
|
|
|
end
|
2021-06-14 20:15:48 +02:00
|
|
|
|
2021-06-15 01:54:29 +02:00
|
|
|
it "bytesize" do
|
|
|
|
secret = Crypto::Secret::Not.new 5
|
|
|
|
secret.bytesize.should eq 5
|
|
|
|
end
|
|
|
|
|
2021-06-14 20:15:48 +02:00
|
|
|
it "doesn't leak key material" do
|
|
|
|
secret = Crypto::Secret::Not.new 5
|
|
|
|
secret.to_s.should match /\(\*\*\*SECRET\*\*\*\)$/
|
|
|
|
secret.inspect.should match /\(\*\*\*SECRET\*\*\*\)$/
|
|
|
|
secret.to_s.should_not match /Bytes|Slice/
|
|
|
|
secret.inspect.should_not match /Bytes|Slice/
|
|
|
|
end
|
2021-06-15 01:50:32 +02:00
|
|
|
|
|
|
|
it "returns a random secret" do
|
|
|
|
secret1 = Crypto::Secret::Not.new 8
|
|
|
|
secret2 = Crypto::Secret::Not.random 8
|
|
|
|
secret1.should_not eq secret2
|
|
|
|
end
|
2021-06-13 01:04:49 +02:00
|
|
|
end
|