class Bollard::Signature
Constants
- EXPECTED_ALGORITHM
Attributes
signature[R]
Public Class Methods
calculate_signature(payload)
click to toggle source
# File lib/bollard/signature.rb, line 7 def self.calculate_signature(payload) Digest::SHA256.hexdigest(payload) end
new(signature)
click to toggle source
# File lib/bollard/signature.rb, line 12 def initialize(signature) @signature = signature end
Public Instance Methods
match?(payload)
click to toggle source
# File lib/bollard/signature.rb, line 17 def match?(payload) secure_compare(signature, self.class.calculate_signature(payload)) end
Private Instance Methods
secure_compare(a, b)
click to toggle source
Code borrowed from ActiveSupport
# File lib/bollard/signature.rb, line 29 def 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