Class: TrueLayerSigning::JwsHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/truelayer-signing/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ JwsHeader

Returns a new instance of JwsHeader.

Raises:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/truelayer-signing/utils.rb', line 5

def initialize(args = {})
  raise(Error, "TRUELAYER_SIGNING_CERTIFICATE_ID is missing") \
    if TrueLayerSigning.certificate_id.nil? ||
      TrueLayerSigning.certificate_id.empty?

  @alg = args[:alg] || TrueLayerSigning.algorithm
  @kid = args[:kid] || TrueLayerSigning.certificate_id
  @tl_version = TrueLayerSigning.version
  @tl_headers = retrieve_headers(args[:tl_headers])
  @jku = args[:jku] || nil
end

Instance Attribute Details

#algObject (readonly)

Returns the value of attribute alg.



3
4
5
# File 'lib/truelayer-signing/utils.rb', line 3

def alg
  @alg
end

#jkuObject (readonly)

Returns the value of attribute jku.



3
4
5
# File 'lib/truelayer-signing/utils.rb', line 3

def jku
  @jku
end

#kidObject (readonly)

Returns the value of attribute kid.



3
4
5
# File 'lib/truelayer-signing/utils.rb', line 3

def kid
  @kid
end

#tl_headersObject (readonly)

Returns the value of attribute tl_headers.



3
4
5
# File 'lib/truelayer-signing/utils.rb', line 3

def tl_headers
  @tl_headers
end

#tl_versionObject (readonly)

Returns the value of attribute tl_version.



3
4
5
# File 'lib/truelayer-signing/utils.rb', line 3

def tl_version
  @tl_version
end

Instance Method Details

#filter_headers(headers) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/truelayer-signing/utils.rb', line 23

def filter_headers(headers)
  required_header_keys = tl_headers.split(",").reject { |key| key.empty? }
  normalised_headers = {}

  headers.to_a.each { |header| normalised_headers[header.first.downcase] = header.last }

  ordered_headers = required_header_keys.map do |key|
    value = normalised_headers[key.downcase]

    raise(Error, "Missing header declared in signature: #{key.downcase}") unless value

    [key, value]
  end

  ordered_headers.to_h
end

#to_hObject



17
18
19
20
21
# File 'lib/truelayer-signing/utils.rb', line 17

def to_h
  hash = instance_variables.map { |var| [var[1..-1].to_sym, instance_variable_get(var)] }.to_h

  hash.reject { |key, _value| hash[key].nil? }
end