Module: Shamu::Security::HashedValue
- Included in:
- Features::ToggleCodec, Shamu::Sessions::CookieStore
- Defined in:
- lib/shamu/security/hashed_value.rb
Overview
Adds support for hashing and verifying a string value.
class Codec
include Shamu::Security::HashedValue
def initialize( private_key = Shamu::Security.private_key )
@private_key = private_key
end
def store( value )
hash_value( value )
end
def restore( hashed )
verify_hash( hashed )
end
end
codec = Codec.new
signed = codec.store "example" # => "0123456789abcdef0123456789abcdef012345678;example"
codec.restore signed # => "example"
codec.restore "example" # => nil
Instance Method Summary collapse
-
#hash_value(string) ⇒ String
Packed string with hash and original value.
Instance Method Details
#hash_value(string) ⇒ String
Returns packed string with hash and original value.
42 43 44 45 |
# File 'lib/shamu/security/hashed_value.rb', line 42 def hash_value( string ) return nil unless string "#{ hash_digest( string ) }$#{ string }" end |