Class: PedicelPay::Token
- Inherits:
-
Object
- Object
- PedicelPay::Token
- Defined in:
- lib/pedicel-pay/token.rb
Constant Summary collapse
- Error =
Class.new(PedicelPay::Error)
Instance Attribute Summary collapse
-
#encrypted_data ⇒ Object
Returns the value of attribute encrypted_data.
-
#header ⇒ Object
Returns the value of attribute header.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#unencrypted_data ⇒ Object
Returns the value of attribute unencrypted_data.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(unencrypted_data: nil, encrypted_data: nil, header: nil, signature: nil, version: 'EC_v1') ⇒ Token
constructor
A new instance of Token.
- #sample ⇒ Object
- #sample_data ⇒ Object
- #sample_header ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #update_pubkey_hash(recipient:) ⇒ Object
Constructor Details
#initialize(unencrypted_data: nil, encrypted_data: nil, header: nil, signature: nil, version: 'EC_v1') ⇒ Token
Returns a new instance of Token.
16 17 18 19 20 21 22 |
# File 'lib/pedicel-pay/token.rb', line 16 def initialize(unencrypted_data: nil, encrypted_data: nil, header: nil, signature: nil, version: 'EC_v1') @unencrypted_data = unencrypted_data @encrypted_data = encrypted_data @header = header @signature = signature @version = version end |
Instance Attribute Details
#encrypted_data ⇒ Object
Returns the value of attribute encrypted_data.
9 10 11 |
# File 'lib/pedicel-pay/token.rb', line 9 def encrypted_data @encrypted_data end |
#header ⇒ Object
Returns the value of attribute header.
9 10 11 |
# File 'lib/pedicel-pay/token.rb', line 9 def header @header end |
#signature ⇒ Object
Returns the value of attribute signature.
9 10 11 |
# File 'lib/pedicel-pay/token.rb', line 9 def signature @signature end |
#unencrypted_data ⇒ Object
Returns the value of attribute unencrypted_data.
9 10 11 |
# File 'lib/pedicel-pay/token.rb', line 9 def unencrypted_data @unencrypted_data end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/pedicel-pay/token.rb', line 9 def version @version end |
Instance Method Details
#sample ⇒ Object
45 46 47 48 49 50 |
# File 'lib/pedicel-pay/token.rb', line 45 def sample sample_data sample_header self end |
#sample_data ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pedicel-pay/token.rb', line 52 def sample_data return if encrypted_data if unencrypted_data unencrypted_data.sample else self.unencrypted_data = TokenData.new.sample end self end |
#sample_header ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/pedicel-pay/token.rb', line 64 def sample_header if header header.sample else self.header = TokenHeader.new.sample end self end |
#to_hash ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pedicel-pay/token.rb', line 34 def to_hash raise Error, 'no encrypted data' unless encrypted_data { 'data' => Base64.strict_encode64(encrypted_data), 'header' => header.to_hash, 'signature' => signature, 'version' => version, } end |
#to_json ⇒ Object
30 31 32 |
# File 'lib/pedicel-pay/token.rb', line 30 def to_json to_hash.to_json end |
#update_pubkey_hash(recipient:) ⇒ Object
24 25 26 27 28 |
# File 'lib/pedicel-pay/token.rb', line 24 def update_pubkey_hash(recipient:) pubkey = Helper.recipient_certificate(recipient: recipient) header.pubkey_hash = Digest::SHA256.base64digest(pubkey.to_der) end |