Module: JsonWebToken::Util
- Defined in:
- lib/json_web_token/util.rb
Overview
Utility methods
Class Method Summary collapse
-
.constant_time_compare?(a, b) ⇒ Boolean
A predicate that compares two strings for equality in constant-time to avoid timing attacks.
-
.symbolize_keys(hsh) ⇒ Hash
A new hash with all keys converted to symbols, as long as they respond to to_sym.
Class Method Details
.constant_time_compare?(a, b) ⇒ Boolean
Returns a predicate that compares two strings for equality in constant-time to avoid timing attacks.
16 17 18 19 |
# File 'lib/json_web_token/util.rb', line 16 def constant_time_compare?(a, b) return false if a.nil? || b.nil? || a.empty? || b.empty? secure_compare(a, b) end |
.symbolize_keys(hsh) ⇒ Hash
Returns a new hash with all keys converted to symbols, as long as they respond to to_sym.
28 29 30 |
# File 'lib/json_web_token/util.rb', line 28 def symbolize_keys(hsh) transform_keys(hsh) { |key| key.to_sym rescue key } end |