class HmacAuthExt
Public Class Methods
new(key, secret)
click to toggle source
# File lib/atlasatsrt.rb, line 9 def initialize(key, secret) @key = key @secret = secret end
Public Instance Methods
incoming(message, callback)
click to toggle source
# File lib/atlasatsrt.rb, line 26 def incoming(message, callback) callback.call(message) end
outgoing(message, callback)
click to toggle source
# File lib/atlasatsrt.rb, line 14 def outgoing(message, callback) path = message['channel'] ident = generate_ident(path, message['data']) # todo: message['ext'] ||= {} message['ext']['ident'] = ident callback.call(message) end
Private Instance Methods
generate_ident(path, body)
click to toggle source
# File lib/atlasatsrt.rb, line 32 def generate_ident(path, body) nounce = generate_nounce signature = generate_signature(nounce, path, body) ident = { "key" => @key, "signature" => signature, "nounce" => nounce } end
generate_nounce()
click to toggle source
# File lib/atlasatsrt.rb, line 48 def generate_nounce Time.now.to_i end
generate_signature(nounce, path, body)
click to toggle source
# File lib/atlasatsrt.rb, line 42 def generate_signature(nounce, path, body) raw_signature = "#{@key}:#{nounce}:#{path}:#{body}" return OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, raw_signature) end