14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/shared-secret-authentication/hash_signatures.rb', line 14
def self.hash_signature(hash)
d = Digest::SHA2.new
string_keys = hash.keys.inject({}) {|keys, key| keys.merge!(key.to_s => key) }
string_keys.keys.sort.each do |key|
puts key.inspect
d.update key
value = hash[string_keys[key]]
if value.instance_of? Hash
value = value.collect {|k,v|
if v.respond_to? :strftime
if v.respond_to? :utc
k.to_s + v.utc.strftime('%a %b %m %H:%M:%S %Y')
else
k.to_s + v.strftime('%a %b %m %H:%M:%S %Y')
end
else
k.to_s + v.to_s
end
}
end
if value.instance_of? Array
puts value.inspect
value = value.sort
value = value.collect {|v|
if v.respond_to? :strftime
if v.respond_to? :utc
puts 'here in utc'
v.utc.strftime('%a %b %m %H:%M:%S %Y')
else
puts 'not in utc'
v.strftime('%a %b %m %H:%M:%S %Y')
end
else
v.to_s
end
}
elsif value.respond_to? :strftime
value = value.strftime('%a %b %m %H:%M:%S %Y')
end
puts 'in here'
puts value.to_s.inspect
d.update value.to_s
end
d.update SHARED_SECRET
d.to_s
end
|