File: client_data.rb

package info (click to toggle)
ruby-u2f 0.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: ruby: 727; makefile: 12
file content (29 lines) | stat: -rw-r--r-- 755 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module U2F
  ##
  # A representation of ClientData, chapter 7
  # http://fidoalliance.org/specs/fido-u2f-raw-message-formats-v1.0-rd-20141008.pdf
  class ClientData
    REGISTRATION_TYP   = "navigator.id.finishEnrollment".freeze
    AUTHENTICATION_TYP = "navigator.id.getAssertion".freeze

    attr_accessor :typ, :challenge, :origin
    alias_method :type, :typ

    def registration?
      typ == REGISTRATION_TYP
    end

    def authentication?
      typ == AUTHENTICATION_TYP
    end

    def self.load_from_json(json)
      client_data = ::JSON.parse(json)
      instance = new
      instance.typ = client_data['typ']
      instance.challenge = client_data['challenge']
      instance.origin = client_data['origin']
      instance
    end
  end
end