Class: OAK::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/oak.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Key

specifically a binary string of 32 bytes (256 bits), randomly-generated and kept very, very secret.

Parameters:

  • key

    String encryption key suitable for AES-256,



78
79
80
81
82
83
84
85
86
87
# File 'lib/oak.rb', line 78

def initialize(key)
  if !key.is_a?(String)
    raise ArgumentError, "bad non-String key: ELIDED"
  end
  rk_size = OAK.random_key.size
  if key.size != rk_size
    raise ArgumentError, "bad key ELIDED, length not #{rk_size}"
  end
  @key = key.dup.freeze # happy :)
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



89
90
91
# File 'lib/oak.rb', line 89

def key
  @key
end

Instance Method Details

#inspectObject



91
92
93
94
95
96
# File 'lib/oak.rb', line 91

def inspect
  #
  # Avoid exposing the key in casual logs or console session.
  #
  to_s[0..-2] + " @key=ELIDED>"
end