From ee884e431eba5c6f1fff5b8c727dc9ffbfec8fbd Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Sat, 30 Apr 2022 11:23:56 -0700 Subject: [PATCH] Sign: Add .random --- src/sodium/sign/secret_key.cr | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/sodium/sign/secret_key.cr b/src/sodium/sign/secret_key.cr index c3ae296..83bcfb8 100644 --- a/src/sodium/sign/secret_key.cr +++ b/src/sodium/sign/secret_key.cr @@ -27,16 +27,14 @@ module Sodium @seed : Crypto::Secret? # Generates a new random secret/public key pair. - def initialize - @key = SecureBuffer.new KEY_SIZE - @public_key = PublicKey.new - @key.readwrite do |kslice| - if LibSodium.crypto_sign_keypair(@public_key.to_slice, kslice) != 0 - raise Sodium::Error.new("crypto_sign_keypair") - end - end + def self.random + new(random: true) end + @[Deprecated("Use .random")] + def self.new + random + end # Copies secret *key* to a `SecureBuffer` def self.copy_from(key : Bytes) @@ -104,8 +102,6 @@ module Sodium end end - - getter seed : Crypto::Secret do SecureBuffer.new(SEED_SIZE).tap do |seed_buf| @key.readonly do |kslice|