class Keycard::DigestKey
A typical digest or api key, ready to be encrypted.
Constants
- HIDDEN_KEY
Public Class Methods
new(digest = nil, key: nil)
click to toggle source
To simply mint a new key, call new without any parameters. For wrapping existing, deserialized keys, pass the digest to the constructor. @param digest [String] The value of the hashed key @param key [String] Use this if you'd like to specify the unhashed key.
If a digest is also provided, this parameter is ignored.
# File lib/keycard/digest_key.rb, line 16 def initialize(digest = nil, key: nil) if digest @digest = digest else @key = key || SecureRandom.uuid end end
Public Instance Methods
digest()
click to toggle source
The result of hashing the key @return [String]
# File lib/keycard/digest_key.rb, line 45 def digest @digest ||= Digest::SHA256.hexdigest(@key) end
eql?(other)
click to toggle source
# File lib/keycard/digest_key.rb, line 49 def eql?(other) digest == if other.is_a?(self.class) other.digest else other.to_s end end
Also aliased as: ==
to_s()
click to toggle source
A string representation of this key. For hidden keys, this returns an obfuscated value. @return [String]
# File lib/keycard/digest_key.rb, line 27 def to_s @key || HIDDEN_KEY end
value()
click to toggle source
The unhashed value of the key. @return [String] @raise [HiddenKeyError] This exception is raised if the unhashed key is
not available.
# File lib/keycard/digest_key.rb, line 35 def value if @key @key else raise HiddenKeyError, "Cannot display hashed/hidden keys" end end