Class: WebAuthn::AttestedCredentialData

Inherits:
Object
  • Object
show all
Defined in:
lib/web_authn/attested_credential_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aaguid:, credential_id:, public_key:, public_cose_key:) ⇒ AttestedCredentialData

Returns a new instance of AttestedCredentialData.



5
6
7
8
9
10
# File 'lib/web_authn/attested_credential_data.rb', line 5

def initialize(aaguid:, credential_id:, public_key:, public_cose_key:)
  self.aaguid = aaguid
  self.credential_id = credential_id
  self.public_key = public_key
  self.public_cose_key = public_cose_key
end

Instance Attribute Details

#aaguidObject

Returns the value of attribute aaguid.



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

def aaguid
  @aaguid
end

#credential_idObject

Returns the value of attribute credential_id.



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

def credential_id
  @credential_id
end

#public_cose_keyObject

Returns the value of attribute public_cose_key.



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

def public_cose_key
  @public_cose_key
end

#public_keyObject

Returns the value of attribute public_key.



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

def public_key
  @public_key
end

Class Method Details

.decode(attested_credential_data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/web_authn/attested_credential_data.rb', line 17

def decode(attested_credential_data)
  length = (
    ((attested_credential_data.getbyte(16) << 8) & 0xFF) +
    (attested_credential_data.getbyte(17) & 0xFF)
  )
  aaguid,
  credential_id,
  cose_key_cbor = [
    attested_credential_data.byteslice(0...16),
    attested_credential_data.byteslice(18...(18 + length)),
    attested_credential_data.byteslice((18 + length)..-1),
  ]
  cose_key = COSE::Key.decode(cose_key_cbor)
  new(
    aaguid: Base64.urlsafe_encode64(aaguid, padding: false),
    credential_id: Base64.urlsafe_encode64(credential_id, padding: false),
    public_key: cose_key.to_key,
    public_cose_key: cose_key
  )
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/web_authn/attested_credential_data.rb', line 12

def anonymous?
  aaguid == 'AAAAAAAAAAAAAAAAAAAAAA' # NOTE: equals to `Base64.urlsafe_encode64("\0" * 16, padding: false)``
end