State checking fix

master
Didactic Drunk 2021-06-17 23:06:44 -07:00
parent 8fb32f3d82
commit d104b75296
2 changed files with 8 additions and 6 deletions

View File

@ -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

View File

@ -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