Secret: #readonly, #readwrite, #noaccess add abstract & type restrictions
This commit is contained in:
parent
df18ae2bf0
commit
f9eefbde0e
@ -33,7 +33,7 @@ module Crypto::Secret
|
||||
|
||||
extend ClassMethods
|
||||
|
||||
# For debugging.
|
||||
# For debugging. Leaks the secret
|
||||
#
|
||||
# Returned String **not** tracked or wiped
|
||||
def hexstring : String
|
||||
@ -92,6 +92,7 @@ module Crypto::Secret
|
||||
wipe
|
||||
end
|
||||
|
||||
# Wipes data & makes this object available for reuse
|
||||
def reset
|
||||
wipe
|
||||
end
|
||||
@ -132,13 +133,20 @@ module Crypto::Secret
|
||||
end
|
||||
end
|
||||
|
||||
# Marks a region allocated using as read & write depending on implementation.
|
||||
# Marks a region as read & write depending on implementation.
|
||||
abstract def readwrite : self
|
||||
# Marks a region allocated using as read-only depending on implementation.
|
||||
# Marks a region as read-only depending on implementation.
|
||||
abstract def readonly : self
|
||||
# Makes a region allocated inaccessible depending on implementation. It cannot be read or written, but the data are preserved.
|
||||
# Makes a region inaccessible depending on implementation. It cannot be read or written, but the data are preserved.
|
||||
abstract def noaccess : self
|
||||
|
||||
# Temporarily marks a region as read & write depending on implementation and yields `Bytes`
|
||||
abstract def readwrite(& : Bytes -> U) forall U
|
||||
# Temporarily marks a region as readonly depending on implementation and yields `Bytes`
|
||||
abstract def readonly(& : Bytes -> U) forall U
|
||||
# Temporarily Makes a region inaccessible depending on implementation. It cannot be read or written, but the data are preserved.
|
||||
abstract def noaccess(& : Bytes -> U) forall U
|
||||
|
||||
protected abstract def to_slice(& : Bytes -> U) forall U
|
||||
abstract def bytesize : Int32
|
||||
|
||||
|
@ -40,7 +40,7 @@ module Crypto::Secret
|
||||
|
||||
# Temporarily make buffer readonly within the block returning to the prior state on exit.
|
||||
# WARNING: Not thread safe unless this object is readonly or readwrite
|
||||
def readonly
|
||||
def readonly(& : Bytes -> U) forall U
|
||||
with_state State::Readonly do
|
||||
to_slice do |slice|
|
||||
yield slice
|
||||
|
@ -20,7 +20,7 @@ module Crypto::Secret::Stateless
|
||||
# `slice` is only available within the block
|
||||
#
|
||||
# Not thread safe
|
||||
def readwrite
|
||||
def readwrite(& : Bytes -> U) forall U
|
||||
to_slice do |slice|
|
||||
yield slice
|
||||
end
|
||||
@ -35,7 +35,7 @@ module Crypto::Secret::Stateless
|
||||
# Don't write to it
|
||||
#
|
||||
# Not thread safe
|
||||
def readonly
|
||||
def readonly(& : Bytes -> U) forall U
|
||||
to_slice do |slice|
|
||||
yield slice
|
||||
end
|
||||
@ -47,7 +47,7 @@ module Crypto::Secret::Stateless
|
||||
end
|
||||
|
||||
# Not thread safe
|
||||
def noaccess
|
||||
def noaccess(& : Bytes -> U) forall U
|
||||
yield
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user