Method: Telnyx::Util.secure_compare
- Defined in:
- lib/telnyx/util.rb
.secure_compare(a, b) ⇒ Object
Constant time string comparison to prevent timing attacks Code borrowed from ActiveSupport
238 239 240 241 242 243 244 245 246 |
# File 'lib/telnyx/util.rb', line 238 def self.secure_compare(a, b) return false unless a.bytesize == b.bytesize l = a.unpack "C#{a.bytesize}" res = 0 b.each_byte { |byte| res |= byte ^ l.shift } res.zero? end |