From c99862505620a3ec135bbe12a2ff63f3c0def3e4 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:52:06 -0700 Subject: [PATCH] Continue #8 --- spec/sodium/sign/secret_key_spec.cr | 10 ++++++++++ src/sodium/sign/public_key.cr | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/spec/sodium/sign/secret_key_spec.cr b/spec/sodium/sign/secret_key_spec.cr index 20db91a..8ab8327 100644 --- a/spec/sodium/sign/secret_key_spec.cr +++ b/spec/sodium/sign/secret_key_spec.cr @@ -76,6 +76,16 @@ describe Sodium::Sign::SecretKey do message = "foo" sskey = Sodium::Sign::SecretKey.new cskey = sskey.to_curve25519 + + spkey = sskey.public_key + cpkey = spkey.to_curve25519 + + data = "foo".to_slice + cskey.box cpkey do |box| + enc, nonce = box.encrypt data + dec = box.decrypt enc, nonce: nonce + dec.should eq data + end end it "RbNaCl detached test vectors" do diff --git a/src/sodium/sign/public_key.cr b/src/sodium/sign/public_key.cr index e89d584..ad66d12 100644 --- a/src/sodium/sign/public_key.cr +++ b/src/sodium/sign/public_key.cr @@ -35,6 +35,12 @@ module Sodium end end + def to_curve25519 : CryptoBox::PublicKey + pk = CryptoBox::PublicKey.new + LibSodium.crypto_sign_ed25519_pk_to_curve25519 pk.to_slice, @bytes + pk + end + module SerializeConverter def self.to_json(value : PublicKey, json : JSON::Builder) json.string Base64.strict_encode(value.to_slice)