class PedicelPay::Token
Constants
- Error
Attributes
encrypted_data[RW]
header[RW]
signature[RW]
unencrypted_data[RW]
version[RW]
Public Class Methods
new(unencrypted_data: nil, encrypted_data: nil, header: nil, signature: nil, version: 'EC_v1')
click to toggle source
# 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 || TokenData.new @encrypted_data = encrypted_data @header = header || TokenHeader.new @signature = signature @version = version end
Public Instance Methods
sample()
click to toggle source
# File lib/pedicel-pay/token.rb, line 45 def sample sample_data sample_header self end
sample_data()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/pedicel-pay/token.rb, line 30 def to_json to_hash.to_json end
update_pubkey_hash(recipient:)
click to toggle source
# 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