Class: TrueLayerSigning::Verifier
- Defined in:
- lib/truelayer-signing/verifier.rb
Constant Summary collapse
- EXPECTED_EC_KEY_COORDS_LENGTH =
66
Instance Attribute Summary collapse
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
-
#key_value ⇒ Object
readonly
Returns the value of attribute key_value.
-
#required_headers ⇒ Object
readonly
Returns the value of attribute required_headers.
Attributes inherited from JwsBase
#body, #headers, #method, #path
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Verifier
constructor
A new instance of Verifier.
- #require_header(name) ⇒ Object
- #require_headers(names) ⇒ Object
- #verify(tl_signature) ⇒ Object
Methods inherited from JwsBase
#add_header, #set_body, #set_headers, #set_method, #set_path
Constructor Details
#initialize(args) ⇒ Verifier
Returns a new instance of Verifier.
9 10 11 12 13 14 |
# File 'lib/truelayer-signing/verifier.rb', line 9 def initialize(args) super @key_type = args[:key_type] @key_value = args[:key_value] end |
Instance Attribute Details
#key_type ⇒ Object (readonly)
Returns the value of attribute key_type.
7 8 9 |
# File 'lib/truelayer-signing/verifier.rb', line 7 def key_type @key_type end |
#key_value ⇒ Object (readonly)
Returns the value of attribute key_value.
7 8 9 |
# File 'lib/truelayer-signing/verifier.rb', line 7 def key_value @key_value end |
#required_headers ⇒ Object (readonly)
Returns the value of attribute required_headers.
7 8 9 |
# File 'lib/truelayer-signing/verifier.rb', line 7 def required_headers @required_headers end |
Class Method Details
.parse_tl_signature(tl_signature) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/truelayer-signing/verifier.rb', line 44 def self.parse_tl_signature(tl_signature) jws_header_b64, signature_b64 = tl_signature.split("..") raise(Error, "Invalid signature format") unless signature_b64 begin jws_header_raw = Base64.urlsafe_decode64(jws_header_b64) rescue ArgumentError raise(Error, "Invalid base64 for header") else jws_header = JwsHeader.new(JSON.parse(jws_header_raw, symbolize_names: true)) end [jws_header, jws_header_b64, signature_b64] end |
Instance Method Details
#require_header(name) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/truelayer-signing/verifier.rb', line 31 def require_header(name) @required_headers ||= [] @required_headers.push(name) self end |
#require_headers(names) ⇒ Object
38 39 40 41 42 |
# File 'lib/truelayer-signing/verifier.rb', line 38 def require_headers(names) @required_headers = names self end |
#verify(tl_signature) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/truelayer-signing/verifier.rb', line 16 def verify(tl_signature) ensure_verifier_config! jws_header, jws_header_b64, signature_b64 = self.class.parse_tl_signature(tl_signature) validate_algorithm!(jws_header.alg) ordered_headers = jws_header.filter_headers(headers) normalised_headers = Utils.normalise_headers!(ordered_headers) validate_required_headers!(normalised_headers) verify_signature_flex(ordered_headers, jws_header, jws_header_b64, signature_b64) end |