From 5e03d23ed9c2af9b906527aedc68c521b398cb30 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Fri, 6 May 2022 11:29:19 -0700 Subject: [PATCH] Remove #to_slice for keys --- src/sodium/crypto_box/secret_key.cr | 11 +++++++---- src/sodium/key.cr | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sodium/crypto_box/secret_key.cr b/src/sodium/crypto_box/secret_key.cr index 398e1c0..f43490a 100644 --- a/src/sodium/crypto_box/secret_key.cr +++ b/src/sodium/crypto_box/secret_key.cr @@ -43,7 +43,7 @@ class Sodium::CryptoBox getter public_key : PublicKey # Returns key - delegate_to_slice to: @key + # delegate_to_slice to: @key @seed : Crypto::Secret? @@ -163,9 +163,12 @@ class Sodium::CryptoBox # For authenticated messages use `secret_key.box(recipient_public_key).decrypt`. # # Optionally supply a destination buffer. - def decrypt_string(src, dst : Bytes? = nil) : String - msg = decrypt src.to_slice, dst - String.new msg + def decrypt_string(src) : String + dsize = src.bytesize - SEAL_SIZE + String.new(dsize) do |dst| + decrypt src.to_slice, dst.to_slice(dsize) + {dsize, dsize} + end end # :nodoc: diff --git a/src/sodium/key.cr b/src/sodium/key.cr index d402385..fb059ef 100644 --- a/src/sodium/key.cr +++ b/src/sodium/key.cr @@ -4,7 +4,5 @@ require "./wipe" module Sodium abstract class Key include Sodium::Wipe - - abstract def to_slice : Bytes end end