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:



17
18
19
20
21
22
23
24
25
26
# File 'lib/truelayer-signing/utils.rb', line 17

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.



15
16
17
# File 'lib/truelayer-signing/utils.rb', line 15

def alg
  @alg
end

#jkuObject (readonly)

Returns the value of attribute jku.



15
16
17
# File 'lib/truelayer-signing/utils.rb', line 15

def jku
  @jku
end

#kidObject (readonly)

Returns the value of attribute kid.



15
16
17
# File 'lib/truelayer-signing/utils.rb', line 15

def kid
  @kid
end

#tl_headersObject (readonly)

Returns the value of attribute tl_headers.



15
16
17
# File 'lib/truelayer-signing/utils.rb', line 15

def tl_headers
  @tl_headers
end

#tl_versionObject (readonly)

Returns the value of attribute tl_version.



15
16
17
# File 'lib/truelayer-signing/utils.rb', line 15

def tl_version
  @tl_version
end

Instance Method Details

#filter_headers(headers) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/truelayer-signing/utils.rb', line 34

def filter_headers(headers)
  required_header_keys = tl_headers.split(",").reject(&:empty?)
  normalised_headers = Utils.normalise_headers!(headers)
  ordered_headers = validate_declared_headers!(required_header_keys, normalised_headers)

  ordered_headers.to_h
end

#to_hObject



28
29
30
31
32
# File 'lib/truelayer-signing/utils.rb', line 28

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

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