sodium.cr/spec/cox/secret_box_spec.cr

17 lines
418 B
Crystal
Raw Normal View History

2019-05-29 01:15:57 +02:00
require "../spec_helper"
describe Cox::SecretBox do
2019-05-29 01:15:57 +02:00
it "encrypts/decrypts" do
key = Cox::SecretBox.new
2019-05-29 01:15:57 +02:00
message = "foobar"
encrypted, nonce = key.encrypt_easy message
decrypted = key.decrypt_easy encrypted, nonce
message.should eq String.new(decrypted)
expect_raises(Cox::Error::DecryptionFailed) do
2019-05-29 01:15:57 +02:00
key.decrypt_easy "badmsgbadmsgbadmsgbadmsgbadmsg".to_slice, nonce
end
end
end