Class: ZeroAuth::Utils
- Inherits:
-
Object
- Object
- ZeroAuth::Utils
- Defined in:
- lib/zero_auth/utils.rb
Overview
Provides general helper methods used throughout the ZeroAuth library.
Class Method Summary collapse
-
.secure_compare(a, b) ⇒ Boolean
Uses a "constant time" comparison algorithm I would never have thought about so I copied it line for line from
Devise.secure_compare:.
Class Method Details
.secure_compare(a, b) ⇒ Boolean
Uses a "constant time" comparison algorithm I would never have thought
about so I copied it line for line from Devise.secure_compare:
19 20 21 22 23 24 25 26 |
# File 'lib/zero_auth/utils.rb', line 19 def self.secure_compare(a, b) return false if empty?(a) || empty?(b) || a.bytesize != b.bytesize l = a.unpack "C#{a.bytesize}" res = 0 b.each_byte { |byte| res |= byte ^ l.shift } res == 0 end |