module Yoti::Protobuf
Constants
- CT_DATE
- CT_INT
- CT_JPEG
- CT_JSON
- CT_MULTI_VALUE
- CT_PNG
- CT_STRING
- CT_UNDEFINED
Public Class Methods
application_profile(receipt)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 40 def application_profile(receipt) return nil unless valid_receipt?(receipt) decipher_profile(receipt['profile_content'], receipt['wrapped_receipt_key']) end
attribute_list(data)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 52 def attribute_list(data) Yoti::Protobuf::Attrpubapi::AttributeList.decode(data) end
current_user(receipt)
click to toggle source
@deprecated replaced by user_profile
# File lib/yoti/protobuf/main.rb, line 28 def current_user(receipt) return nil unless valid_receipt?(receipt) decode_profile(receipt['other_party_profile_content']) end
extra_data(receipt)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 46 def extra_data(receipt) return nil if receipt['extra_data_content'].nil? || receipt['extra_data_content'] == '' decipher_extra_data(receipt['extra_data_content'], receipt['wrapped_receipt_key']) end
user_profile(receipt)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 34 def user_profile(receipt) return nil unless valid_receipt?(receipt) decipher_profile(receipt['other_party_profile_content'], receipt['wrapped_receipt_key']) end
value_based_on_attribute_name(value, attr_name)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 56 def value_based_on_attribute_name(value, attr_name) case attr_name when Yoti::Attribute::DOCUMENT_DETAILS Yoti::DocumentDetails.new(value) when Yoti::Attribute::DOCUMENT_IMAGES raise(TypeError, 'Document Images could not be decoded') unless value.is_a?(Yoti::MultiValue) value.allow_type(Yoti::Image).items else value end end
value_based_on_content_type(value, content_type = nil)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 69 def value_based_on_content_type(value, content_type = nil) raise(TypeError, 'Warning: value is NULL') if value.empty? && content_type != CT_STRING case content_type when CT_STRING, CT_DATE value.encode('utf-8') when CT_JSON JSON.parse(value) when CT_INT value.to_i when CT_JPEG Yoti::ImageJpeg.new(value) when CT_PNG Yoti::ImagePng.new(value) when CT_MULTI_VALUE convert_multi_value(value) else Yoti::Log.logger.warn("Unknown Content Type '#{content_type}', parsing as a String") value.encode('utf-8') end end
Private Class Methods
convert_multi_value(value)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 93 def convert_multi_value(value) proto_multi_values = Yoti::Protobuf::Attrpubapi::MultiValue.decode(value).values items = [] proto_multi_values.each do |item| items << value_based_on_content_type(item.data, item.content_type) end MultiValue.new(items) end
decipher_data(encrypted_content, wrapped_key)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 124 def decipher_data(encrypted_content, wrapped_key) encrypted_data = decode_profile(encrypted_content) unwrapped_key = Yoti::SSL.decrypt_token(wrapped_key) Yoti::SSL.decipher(unwrapped_key, encrypted_data.iv, encrypted_data.cipher_text) end
decipher_extra_data(extra_data_content, wrapped_key)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 118 def decipher_extra_data(extra_data_content, wrapped_key) decrypted_data = decipher_data(extra_data_content, wrapped_key) proto = Yoti::Protobuf::Sharepubapi::ExtraData.decode(decrypted_data) Share::ExtraData.new(proto) end
decipher_profile(profile_content, wrapped_key)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 113 def decipher_profile(profile_content, wrapped_key) decrypted_data = decipher_data(profile_content, wrapped_key) Protobuf.attribute_list(decrypted_data) end
decode_profile(profile_content)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 108 def decode_profile(profile_content) decoded_profile_content = Base64.decode64(profile_content) Yoti::Protobuf::Compubapi::EncryptedData.decode(decoded_profile_content) end
valid_receipt?(receipt)
click to toggle source
# File lib/yoti/protobuf/main.rb, line 102 def valid_receipt?(receipt) receipt.key?('other_party_profile_content') && !receipt['other_party_profile_content'].nil? && receipt['other_party_profile_content'] != '' end