Class: Selenium::WebDriver::Credential

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, resident_credential:, rp_id:, private_key:, **opts) ⇒ Credential

Returns a new instance of Credential.

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 59

def initialize(id:, resident_credential:, rp_id:, private_key:, **opts)
  @id = id
  @resident_credential = resident_credential
  @rp_id = rp_id
  @user_handle = opts.delete(:user_handle) { nil }
  @private_key = private_key
  @sign_count = opts.delete(:sign_count) { 0 }

  raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def id
  @id
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def private_key
  @private_key
end

#resident_credentialObject (readonly) Also known as: resident_credential?

Returns the value of attribute resident_credential.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def resident_credential
  @resident_credential
end

#rp_idObject (readonly)

Returns the value of attribute rp_id.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def rp_id
  @rp_id
end

#sign_countObject (readonly)

Returns the value of attribute sign_count.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def sign_count
  @sign_count
end

#user_handleObject (readonly)

Returns the value of attribute user_handle.



56
57
58
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 56

def user_handle
  @user_handle
end

Class Method Details

.decode(base64) ⇒ Object



41
42
43
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 41

def decode(base64)
  Base64.urlsafe_decode64(base64).unpack('C*')
end

.encode(byte_array) ⇒ Object



37
38
39
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 37

def encode(byte_array)
  Base64.urlsafe_encode64(byte_array&.pack('C*'))
end

.from_json(opts) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 45

def from_json(opts)
  user_handle = opts['userHandle'] ? decode(opts['userHandle']) : nil
  new(id: decode(opts['credentialId']),
      resident_credential: opts['isResidentCredential'],
      rp_id: opts['rpId'],
      private_key: opts['privateKey'],
      sign_count: opts['signCount'],
      user_handle: user_handle)
end

.non_resident(**opts) ⇒ Object



33
34
35
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 33

def non_resident(**opts)
  Credential.new(resident_credential: false, **opts)
end

.resident(**opts) ⇒ Object



29
30
31
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 29

def resident(**opts)
  Credential.new(resident_credential: true, **opts)
end

Instance Method Details

#as_jsonObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
78
79
80
81
82
# File 'rb/lib/selenium/webdriver/common/virtual_authenticator/credential.rb', line 74

def as_json(*)
  credential_data = {'credentialId' => Credential.encode(id),
                     'isResidentCredential' => resident_credential?,
                     'rpId' => rp_id,
                     'privateKey' => Credential.encode(private_key),
                     'signCount' => sign_count}
  credential_data['userHandle'] = Credential.encode(user_handle) if user_handle
  credential_data
end