Class: RCL::Token
Instance Method Summary collapse
- #authenticate(key) ⇒ Object
-
#initialize(key) ⇒ Token
constructor
A new instance of Token.
Constructor Details
#initialize(key) ⇒ Token
Returns a new instance of Token.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rcl/token.rb', line 10 def initialize(key) raise ArgumentError, 'nil key' if key.nil? raise ArgumentError, 'invalid key class' if key.class != String raise ArgumentError, 'empty key' if key.empty? srand @salt = [Array.new(6) { rand(256).chr }.join].pack("m").chomp @hash = Digest::SHA256.hexdigest(@salt+key) nil end |
Instance Method Details
#authenticate(key) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rcl/token.rb', line 23 def authenticate(key) raise ArgumentError, 'nil key' if key.nil? raise ArgumentError, 'invalid key class' if key.class != String raise ArgumentError, 'empty key' if key.empty? Digest::SHA256.hexdigest(@salt+key) == @hash end |