Class: Castle::Utils::SecureCompare
- Inherits:
-
Object
- Object
- Castle::Utils::SecureCompare
- Defined in:
- lib/castle/utils/secure_compare.rb
Overview
Code borrowed from ActiveSupport
Class Method Summary collapse
Class Method Details
.call(str_a, str_b) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/castle/utils/secure_compare.rb', line 10 def call(str_a, str_b) return false unless str_a.bytesize == str_b.bytesize l = str_a.unpack "C#{str_a.bytesize}" res = 0 str_b.each_byte { |byte| res |= byte ^ l.shift } res.zero? end |