Class: Touchpass::Verification
- Inherits:
-
Object
- Object
- Touchpass::Verification
- Defined in:
- lib/touchpass/verification.rb
Constant Summary collapse
- STATE_CREATED =
'created'
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#claimed_prp ⇒ Object
readonly
Returns the value of attribute claimed_prp.
-
#claimed_token ⇒ Object
readonly
Returns the value of attribute claimed_token.
-
#crypted_messages ⇒ Object
readonly
Returns the value of attribute crypted_messages.
-
#crypted_salts ⇒ Object
readonly
Returns the value of attribute crypted_salts.
-
#crypted_tokens ⇒ Object
readonly
Returns the value of attribute crypted_tokens.
-
#location_verification ⇒ Object
readonly
Returns the value of attribute location_verification.
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_message(message, options = {}) ⇒ Object
-
#http_params ⇒ Object
create http parameters.
- #id ⇒ Object
-
#initialize(vp_devices, options = {}) ⇒ Verification
constructor
A new instance of Verification.
- #state ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(vp_devices, options = {}) ⇒ Verification
Returns a new instance of Verification.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/touchpass/verification.rb', line 11 def initialize(vp_devices, = {}) # Generate token token = Crypt.salt hashed_token = Crypt.hash(token) @claimed_token = hashed_token @vp_devices = vp_devices @crypted_messages = [] @attributes = {} # Encrypt message using each verifying party's (to_party) device public keys ([:message]) if ![:message].nil? # Encrypt post-verification message, if present if ![:message_post_verification].nil? ([:message_post_verification], :requires_verification => true, :scratch_to_reveal => [:scratch_to_reveal]) end # Encrypt post-verification location message, if present if ![:message_post_verification_location].nil? ([:message_post_verification_location], :requires_verification => true, :requires_location_verification => true, :scratch_to_reveal => [:scratch_to_reveal]) end # allow adding messages from array of hashes (containing message and options) = [:messages] = .values if .kind_of?(Hash) if .kind_of?(Array) .each { |i| (i[:message], i) } end # Encrypt token using each verifying party's (to_party) device public keys # (only use RSA encryption for the token) @crypted_tokens = crypted_values("crypted_tokens", token, :rsa_only => true) # Encrypt prp-hash using verifying_party (to_party) devices if ![:address].nil? # For location verification @location_verification = true # Convert address to PRP @resolution = [:resolution] || "LOCAL" # Resolution used to calculate PRP prp = Proximity::PRP.new(:address => [:address], :resolution => @resolution) # puts prp.print_bbox # for debugging # Generate random salt salt = Crypt.salt # puts "Using salt: #{salt}" # for debugging # Encrypt PRP using salt claimed_prp = prp.encrypt(salt) @claimed_prp = claimed_prp # Encrypt salt using verifiying_party (to_party) devices @crypted_salts = crypted_values("crypted_salts", salt, :rsa_only => true) end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/touchpass/verification.rb', line 9 def attributes @attributes end |
#claimed_prp ⇒ Object (readonly)
Returns the value of attribute claimed_prp.
8 9 10 |
# File 'lib/touchpass/verification.rb', line 8 def claimed_prp @claimed_prp end |
#claimed_token ⇒ Object (readonly)
Returns the value of attribute claimed_token.
7 8 9 |
# File 'lib/touchpass/verification.rb', line 7 def claimed_token @claimed_token end |
#crypted_messages ⇒ Object (readonly)
Returns the value of attribute crypted_messages.
6 7 8 |
# File 'lib/touchpass/verification.rb', line 6 def @crypted_messages end |
#crypted_salts ⇒ Object (readonly)
Returns the value of attribute crypted_salts.
6 7 8 |
# File 'lib/touchpass/verification.rb', line 6 def crypted_salts @crypted_salts end |
#crypted_tokens ⇒ Object (readonly)
Returns the value of attribute crypted_tokens.
6 7 8 |
# File 'lib/touchpass/verification.rb', line 6 def crypted_tokens @crypted_tokens end |
#location_verification ⇒ Object (readonly)
Returns the value of attribute location_verification.
8 9 10 |
# File 'lib/touchpass/verification.rb', line 8 def location_verification @location_verification end |
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
8 9 10 |
# File 'lib/touchpass/verification.rb', line 8 def resolution @resolution end |
Instance Method Details
#[](key) ⇒ Object
93 94 95 |
# File 'lib/touchpass/verification.rb', line 93 def [](key) @attributes.kind_of?(Hash) ? @attributes[key] : nil end |
#add_message(message, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/touchpass/verification.rb', line 73 def (, = {}) @crypted_messages ||= [] @crypted_messages += crypted_values("crypted_messages", , ) end |
#http_params ⇒ Object
create http parameters
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/touchpass/verification.rb', line 79 def http_params params = {} params[:claimed_token] = @claimed_token params[:crypted_messages] = param_hash(@crypted_messages) params[:crypted_tokens] = param_hash(@crypted_tokens) params[:crypted_salts] = param_hash(@crypted_salts) params[:location_verification] = @location_verification params[:resolution] = @resolution params[:claimed_prp] = @claimed_prp params end |
#id ⇒ Object
101 102 103 |
# File 'lib/touchpass/verification.rb', line 101 def id self['id'] end |
#state ⇒ Object
105 106 107 |
# File 'lib/touchpass/verification.rb', line 105 def state self['state'] end |
#to_h ⇒ Object
97 98 99 |
# File 'lib/touchpass/verification.rb', line 97 def to_h @attributes end |