Class: SebElink::Gateway
- Inherits:
-
Object
- Object
- SebElink::Gateway
- Includes:
- MessageSpecs
- Defined in:
- lib/seb_elink/gateway.rb
Constant Summary
Constants included from MessageSpecs
MessageSpecs::V001_MESSAGE0002_SPEC, MessageSpecs::V001_MESSAGE0003_SPEC, MessageSpecs::V001_MESSAGE0004_SPEC
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#privkey ⇒ Object
readonly
Returns the value of attribute privkey.
Instance Method Summary collapse
- #ibank_api_uri ⇒ Object
-
#initialize(privkey, defaults = {}) ⇒ Gateway
constructor
A new instance of Gateway.
-
#produce_footprint(options) ⇒ Object
options: { message_code: “000x”, version: “00x” skip_validation: false, # true for from-SEB messages like 0003 and 0004 data: { IB_SND_ID: “TESTACC”, … } }.
-
#sign(options) ⇒ Object
options: { version: “00x”, message_footprint: “001a..” }.
-
#spec_for(options) ⇒ Object
options: { version: “00x”, message_code: “000x” }.
-
#verify(options) ⇒ Object
options: { version: “00x”, message:, base64_signature: # OR signature: }.
Constructor Details
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
4 5 6 |
# File 'lib/seb_elink/gateway.rb', line 4 def defaults @defaults end |
#privkey ⇒ Object (readonly)
Returns the value of attribute privkey.
4 5 6 |
# File 'lib/seb_elink/gateway.rb', line 4 def privkey @privkey end |
Instance Method Details
#ibank_api_uri ⇒ Object
11 12 13 |
# File 'lib/seb_elink/gateway.rb', line 11 def ibank_api_uri @ibank_api_uri ||= defaults[:IBANK_API_URI] end |
#produce_footprint(options) ⇒ Object
options: {
message_code: "000x",
version: "00x"
skip_validation: false, # true for from-SEB messages like 0003 and 0004
data: {
IB_SND_ID: "TESTACC",
...
}
}
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seb_elink/gateway.rb', line 24 def produce_footprint() data_hash = [:data] spec_set = spec_for(version: [:version], message_code: [:message_code]) footprint_string = spec_set.map do |field, spec| next unless spec[:in_signature] unless [:skip_validation] # 1. validate each field's length in .bytesize and format raise_nil_error(field) if data_hash[field] == nil raise_length_error(field) if data_hash[field].to_s.bytesize > spec[:max_length] raise_format_error(field) if !data_hash[field].to_s[spec[:format]] end # 2. build the 'len(p1)||p1..' string "#{data_hash[field].to_s.bytesize.to_s.rjust(3, "0")}#{data_hash[field]}" end.join("") end |
#sign(options) ⇒ Object
options:
version: "00x",
message_footprint: "001a.."
55 56 57 58 59 60 61 62 |
# File 'lib/seb_elink/gateway.rb', line 55 def sign() Base64.encode64( privkey_rsa.sign( send("v#{[:version]}_digest"), #=> digest algorythm, SHA1 [:message_footprint] ) ) end |
#spec_for(options) ⇒ Object
options:
version: "00x",
message_code: "000x"
47 48 49 |
# File 'lib/seb_elink/gateway.rb', line 47 def spec_for() send(:class).const_get("V#{[:version]}_MESSAGE#{[:message_code]}_SPEC") end |
#verify(options) ⇒ Object
options:
version: "00x",
message:,
base64_signature:
# OR
signature:
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/seb_elink/gateway.rb', line 71 def verify() received_binary_signature = [:signature] || Base64.decode64([:base64_signature]) ibank_pubkey_rsa.verify( send("v#{[:version]}_digest"), received_binary_signature, [:message] ) end |