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