2019-06-28 12:30:33 +02:00
|
|
|
require "../../spec_helper"
|
2019-06-29 01:17:09 +02:00
|
|
|
require "../../../src/sodium/sign/secret_key"
|
2019-06-28 12:30:33 +02:00
|
|
|
|
2019-07-04 02:56:02 +02:00
|
|
|
private def new_sign_key_to_slice
|
|
|
|
Sodium::Sign::SecretKey.new.to_slice
|
2019-06-29 21:44:47 +02:00
|
|
|
end
|
|
|
|
|
2019-06-29 01:17:09 +02:00
|
|
|
describe Sodium::Sign::SecretKey do
|
2019-06-29 21:44:47 +02:00
|
|
|
it "loads keys" do
|
|
|
|
key1 = Sodium::Sign::SecretKey.new
|
2019-07-04 02:56:02 +02:00
|
|
|
key2 = Sodium::Sign::SecretKey.new key1.to_slice, key1.public_key.to_slice
|
|
|
|
key1.to_slice.should eq key2.to_slice
|
|
|
|
key1.public_key.to_slice.should eq key2.public_key.to_slice
|
2019-06-30 02:21:00 +02:00
|
|
|
end
|
2019-06-29 21:44:47 +02:00
|
|
|
|
2019-06-30 02:21:00 +02:00
|
|
|
it "recomputes the public key" do
|
|
|
|
key1 = Sodium::Sign::SecretKey.new
|
2019-07-04 02:56:02 +02:00
|
|
|
key2 = Sodium::Sign::SecretKey.new key1.to_slice
|
|
|
|
key1.to_slice.should eq key2.to_slice
|
|
|
|
key1.public_key.to_slice.should eq key2.public_key.to_slice
|
2019-06-29 21:44:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "seed keys" do
|
|
|
|
seed = Bytes.new Sodium::Sign::SecretKey::SEED_SIZE
|
|
|
|
key1 = Sodium::Sign::SecretKey.new seed: seed
|
|
|
|
key2 = Sodium::Sign::SecretKey.new seed: seed
|
2019-07-04 02:56:02 +02:00
|
|
|
key1.to_slice.should eq key2.to_slice
|
|
|
|
key1.public_key.to_slice.should eq key2.public_key.to_slice
|
2019-06-29 21:44:47 +02:00
|
|
|
end
|
|
|
|
|
2019-06-28 12:30:33 +02:00
|
|
|
it "signs and verifies" do
|
|
|
|
message = "foo"
|
2019-06-29 01:17:09 +02:00
|
|
|
skey = Sodium::Sign::SecretKey.new
|
2019-06-28 12:30:33 +02:00
|
|
|
sig = skey.sign_detached message
|
|
|
|
|
|
|
|
skey.public_key.verify_detached message, sig
|
|
|
|
end
|
|
|
|
|
|
|
|
it "signs and fails" do
|
|
|
|
message = "foo"
|
2019-06-29 01:17:09 +02:00
|
|
|
skey = Sodium::Sign::SecretKey.new
|
2019-06-28 12:30:33 +02:00
|
|
|
sig = skey.sign_detached message
|
|
|
|
|
2019-06-29 01:17:09 +02:00
|
|
|
expect_raises Sodium::Error::VerificationFailed do
|
2019-06-28 12:30:33 +02:00
|
|
|
skey.public_key.verify_detached "bar", sig
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|