From d104b7529606d602c0bc2d8ba92497ca96eaad79 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Thu, 17 Jun 2021 23:06:44 -0700 Subject: [PATCH] State checking fix --- src/crypto-secret/secret.cr | 4 ++-- src/crypto-secret/stateful.cr | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/crypto-secret/secret.cr b/src/crypto-secret/secret.cr index 4e23287..082aee5 100644 --- a/src/crypto-secret/secret.cr +++ b/src/crypto-secret/secret.cr @@ -113,11 +113,11 @@ module Crypto::Secret # Makes a region allocated inaccessible depending on implementation. It cannot be read or written, but the data are preserved. abstract def noaccess : self - protected abstract def to_slice(& : Bytes -> Nil) + protected abstract def to_slice(& : Bytes -> U) forall U abstract def bytesize : Int32 macro delegate_to_slice(to object) - def to_slice(& : Bytes -> Nil) + def to_slice(& : Bytes -> U) forall U yield {{object.id}}.to_slice end end diff --git a/src/crypto-secret/stateful.cr b/src/crypto-secret/stateful.cr index 98535a3..e22ac86 100644 --- a/src/crypto-secret/stateful.cr +++ b/src/crypto-secret/stateful.cr @@ -81,10 +81,12 @@ module Crypto::Secret return if @state == new_state case new_state - in State::Readwrite; readwrite - in State::Readonly ; readonly - in State::Noaccess ; noaccess - in State::Wiped ; raise Error::KeyWiped.new + when State::Readwrite; readwrite + when State::Readonly ; readonly + when State::Noaccess ; noaccess + when State::Wiped ; raise Error::KeyWiped.new + else + raise Error::InvalidStateTransition.new("can't change to #{new_state}") end end