Class: M2mKeygen::Canonicalizer

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/m2m_keygen/canonicalizer.rb

Constant Summary collapse

SCHEME =
'm2m-keygen/2'

Class Method Summary collapse

Class Method Details

.canonical(verb:, path:, expiry:, nonce:, query: '', body: '') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/m2m_keygen/canonicalizer.rb', line 23

def canonical(verb:, path:, expiry:, nonce:, query: '', body: '')
  join_length_prefixed(
    [
      SCHEME,
      verb.upcase,
      path,
      expiry.to_s,
      nonce,
      canonical_query(query),
      body,
    ],
  )
end

.canonical_query(query) ⇒ Object



38
39
40
41
42
# File 'lib/m2m_keygen/canonicalizer.rb', line 38

def canonical_query(query)
  return '' if query.empty?

  query.split('&').sort_by(&:b).join('&')
end