Class: WebAuthn::AuthenticatorData

Inherits:
Object
  • Object
show all
Defined in:
lib/web_authn/authenticator_data.rb,
lib/web_authn/authenticator_data/flags.rb

Defined Under Namespace

Classes: Flags

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rp_id_hash:, flags:, sign_count:, raw:, attested_credential_data: nil) ⇒ AuthenticatorData

Returns a new instance of AuthenticatorData.



9
10
11
12
13
14
15
# File 'lib/web_authn/authenticator_data.rb', line 9

def initialize(rp_id_hash:, flags:, sign_count:, raw:, attested_credential_data: nil)
  self.rp_id_hash = rp_id_hash
  self.flags = flags
  self.sign_count = sign_count
  self.raw = raw
  self.attested_credential_data = attested_credential_data
end

Instance Attribute Details

#attested_credential_dataObject

Returns the value of attribute attested_credential_data.



3
4
5
# File 'lib/web_authn/authenticator_data.rb', line 3

def attested_credential_data
  @attested_credential_data
end

#flagsObject

Returns the value of attribute flags.



3
4
5
# File 'lib/web_authn/authenticator_data.rb', line 3

def flags
  @flags
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/web_authn/authenticator_data.rb', line 3

def raw
  @raw
end

#rp_id_hashObject

Returns the value of attribute rp_id_hash.



3
4
5
# File 'lib/web_authn/authenticator_data.rb', line 3

def rp_id_hash
  @rp_id_hash
end

#sign_countObject

Returns the value of attribute sign_count.



3
4
5
# File 'lib/web_authn/authenticator_data.rb', line 3

def sign_count
  @sign_count
end

Class Method Details

.decode(auth_data) ⇒ Object



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
# File 'lib/web_authn/authenticator_data.rb', line 18

def decode(auth_data)
  rp_id_hash,
  _flags_,
  sign_count = [
    auth_data.byteslice(0...32),
    auth_data.byteslice(32),
    auth_data.byteslice(33...37)
  ]
  flags = Flags.decode(_flags_)
  attested_credential_data = if flags.at?
    if flags.ex?
      raise NotImplementedError, 'Extension Data Not Supported Yet'
    else
      AttestedCredentialData.decode auth_data.byteslice(37..-1)
    end
  else
    nil
  end

  new(
    rp_id_hash: Base64.urlsafe_encode64(rp_id_hash, padding: false),
    flags: flags,
    sign_count: sign_count.unpack('N1').first,
    attested_credential_data: attested_credential_data,
    raw: auth_data
  )
end