module Crypto::Secret::Stateful

Overview

Development guide:

  1. Create your initialize method and optionally allocate memory
  2. Create a finalize method to deallocate memory if necessary
  3. Fill in the missing abstract methods
  4. Optionally override any included methods (especially wipe_impl if the secret is not held in the provided slice)
  5. Provide and test a dup method or raise on dup if not possible

When state changes are required (such as using #noaccess) and the buffer is accessed from multiple threads wrap each #readonly/#readwrite block in a lock.

Included Modules

Defined in:

crypto-secret/lib.cr
crypto-secret/stateful.cr

Instance Method Summary

Instance methods inherited from module Crypto::Secret

==(other : Secret) : Bool
==(other : Bytes) : Bool
==
, bytesize : Int32 bytesize, copy_from(data : Bytes) : Nil
copy_from(data : Crypto::Secret) : Nil
copy_from
, dup dup, finalize finalize, hexstring : String hexstring, inspect(io : IO) : Nil inspect, move_from(data : Crypto::Secret) : Nil
move_from(data : Bytes) : Nil
move_from
, noaccess : self noaccess, random : self random, readonly : self
readonly(& : Bytes -> U) forall U
readonly
, readwrite : self
readwrite(& : Bytes -> U) forall U
readwrite
, reset reset, wipe(&)
wipe
wipe

Instance Method Detail

def dup #

[View source]
def noaccess : self #

Makes a region inaccessible. It cannot be read or written, but the data are preserved. WARNING: Not thread safe


[View source]
def readonly(& : Bytes -> U) forall U #

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


[View source]
def readonly : self #

Marks a region allocated using sodium_malloc() or sodium_allocarray() as read-only. WARNING: Not thread safe


[View source]
def readwrite(&) #

Temporarily make buffer readwrite within the block returning to the prior state on exit. WARNING: Not thread safe unless this object is readwrite


[View source]
def readwrite : self #

Marks a region allocated as readable and writable WARNING: Not thread safe


[View source]
def reset #
Description copied from module Crypto::Secret

Wipes data & makes this object available for reuse


[View source]
def set_state(new_state : State) #

WARNING: Not thread safe Kept public for .dup :nodoc:


[View source]
def wipe #

WARNING: Not thread safe


[View source]