sodium.cr/spec/sodium/secret_box_spec.cr

18 lines
465 B
Crystal
Raw Normal View History

2019-05-29 01:15:57 +02:00
require "../spec_helper"
require "../../src/sodium/secret_box"
2019-05-29 01:15:57 +02:00
describe Sodium::SecretBox do
2019-05-29 01:15:57 +02:00
it "encrypts/decrypts" do
key = Sodium::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(Sodium::Error::DecryptionFailed) do
2019-05-29 01:15:57 +02:00
key.decrypt_easy "badmsgbadmsgbadmsgbadmsgbadmsg".to_slice, nonce
end
end
end