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, dup dup, finalize finalize, hexstring : String hexstring, inspect(io : IO) : Nil inspect, move_from(data : Bytes) : Nil move_from, noaccess : self noaccess, random : self random, readonly : self readonly, readwrite : self 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(&) #

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 #

[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]