2017-07-12 05:13:52 +02:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
describe Cox do
|
|
|
|
# TODO: Write tests
|
|
|
|
|
2018-02-12 08:06:34 +01:00
|
|
|
it "works for encrypting" do
|
2017-07-12 05:13:52 +02:00
|
|
|
data = "Hello World!"
|
|
|
|
|
|
|
|
# Alice is the sender
|
|
|
|
alice = Cox::KeyPair.new
|
|
|
|
|
|
|
|
# Bob is the recipient
|
|
|
|
bob = Cox::KeyPair.new
|
|
|
|
|
|
|
|
# Encrypt a message for Bob using his public key, signing it with Alice's
|
|
|
|
# secret key
|
|
|
|
nonce, encrypted = Cox.encrypt(data, bob.public, alice.secret)
|
|
|
|
|
|
|
|
# Decrypt the message using Bob's secret key, and verify its signature against
|
|
|
|
# Alice's public key
|
|
|
|
decrypted = Cox.decrypt(encrypted, nonce, alice.public, bob.secret)
|
|
|
|
|
|
|
|
String.new(decrypted).should eq(data)
|
|
|
|
end
|
2018-02-12 08:06:34 +01:00
|
|
|
|
|
|
|
it "works for signing" do
|
|
|
|
message = "test"
|
|
|
|
|
|
|
|
signing_pair = Cox::SignKeyPair.new
|
2018-02-14 05:20:27 +01:00
|
|
|
|
2018-02-12 08:06:34 +01:00
|
|
|
# Create signature using the secret key
|
2018-02-14 05:20:27 +01:00
|
|
|
signature = Cox.sign_detached(message, signing_pair.secret)
|
2018-02-12 08:06:34 +01:00
|
|
|
|
|
|
|
# Verify the signature on the message
|
2018-02-14 05:20:27 +01:00
|
|
|
verified = Cox.verify_detached(signature, message, signing_pair.public)
|
2018-02-12 08:06:34 +01:00
|
|
|
|
|
|
|
verified.should eq(true)
|
|
|
|
end
|
2017-07-12 05:13:52 +02:00
|
|
|
end
|