10
11
12
13
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
|
# File 'lib/diversion/decode/params.rb', line 10
def get_hash(params, options)
hash = HashWithIndifferentAccess.new.merge(CGI::parse(params))
raise Error::BadUrlDataFormat.new('Missing data parameter') unless hash.include?('d')
params = CGI::parse(CGI::unescape(hash["d"].first))
params_escaped = hash["d"].first
params.each do |k,v|
params[k] = v.first
end
hash.delete(:d)
raise Error::BadUrlDataFormat.new('Missing url parameter') if !params.include?('url') or params["url"].empty?
hash[:key_presented] = ""
if hash.has_key?(:s)
hash[:key_presented] = hash[:s].first
hash.delete(:s)
end
hash[:parsed] = true
unless hash[:key_presented].empty?
hash[:signed] = true
hash[:key_expected] = Signing::sign_data(options[:sign_key], options[:sign_length], params_escaped)
hash[:key_verified] = hash[:key_presented] == hash[:key_expected]
else
hash[:signed] = false
hash[:key_expected] = ""
hash[:key_verified] = false
end
hash = hash.merge(params.symbolize_keys).symbolize_keys
end
|