File: auth_factor_input.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 4,081 bytes parent folder | download | duplicates (7)
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/cryptohome/auth_factor_input.h"

#include <utility>
#include <variant>

#include "base/check_op.h"
#include "base/notreached.h"
#include "chromeos/ash/components/cryptohome/auth_factor.h"

namespace cryptohome {

// =============== `RecoveryCreation` =====================
AuthFactorInput::RecoveryCreation::RecoveryCreation(
    const std::string& pub_key,
    const GaiaId& user_gaia_id,
    const std::string& device_user_id,
    bool ensure_fresh_recovery_id)
    : pub_key(pub_key),
      user_gaia_id(user_gaia_id),
      device_user_id(device_user_id),
      ensure_fresh_recovery_id(ensure_fresh_recovery_id) {}
AuthFactorInput::RecoveryCreation::RecoveryCreation(
    const RecoveryCreation& other) = default;
AuthFactorInput::RecoveryCreation& AuthFactorInput::RecoveryCreation::operator=(
    const RecoveryCreation&) = default;
AuthFactorInput::RecoveryCreation::~RecoveryCreation() = default;

// =============== `SmartCard` =====================
AuthFactorInput::SmartCard::SmartCard(
    std::vector<ChallengeResponseKey::SignatureAlgorithm> algorithms,
    std::string dbus_service_name)
    : signature_algorithms(std::move(algorithms)),
      key_delegate_dbus_service_name(std::move(dbus_service_name)) {}
AuthFactorInput::SmartCard::SmartCard(const SmartCard& other) = default;
AuthFactorInput::SmartCard& AuthFactorInput::SmartCard::operator=(
    const SmartCard&) = default;
AuthFactorInput::SmartCard::~SmartCard() = default;

// =============== `AuthFactorInput` ===============

AuthFactorInput::AuthFactorInput(InputVariant input)
    : factor_input_(std::move(input)) {}

AuthFactorInput::AuthFactorInput(AuthFactorInput&&) noexcept = default;
AuthFactorInput& AuthFactorInput::operator=(AuthFactorInput&&) noexcept =
    default;

AuthFactorInput::~AuthFactorInput() = default;

AuthFactorType AuthFactorInput::GetType() const {
  if (std::holds_alternative<AuthFactorInput::Password>(factor_input_)) {
    return AuthFactorType::kPassword;
  }
  if (std::holds_alternative<AuthFactorInput::Pin>(factor_input_)) {
    return AuthFactorType::kPin;
  }
  if (std::holds_alternative<AuthFactorInput::Kiosk>(factor_input_)) {
    return AuthFactorType::kKiosk;
  }
  if (std::holds_alternative<AuthFactorInput::SmartCard>(factor_input_)) {
    return AuthFactorType::kSmartCard;
  }
  if (std::holds_alternative<AuthFactorInput::RecoveryCreation>(
          factor_input_)) {
    return AuthFactorType::kRecovery;
  }
  if (std::holds_alternative<AuthFactorInput::RecoveryAuthentication>(
          factor_input_)) {
    return AuthFactorType::kRecovery;
  }
  NOTREACHED();
}

bool AuthFactorInput::UsableForCreation() const {
  if (GetType() != AuthFactorType::kRecovery) {
    return true;
  }
  if (std::holds_alternative<AuthFactorInput::RecoveryCreation>(
          factor_input_)) {
    return true;
  }
  return false;
}

bool AuthFactorInput::UsableForAuthentication() const {
  if (GetType() != AuthFactorType::kRecovery) {
    return true;
  }
  if (std::holds_alternative<AuthFactorInput::RecoveryAuthentication>(
          factor_input_)) {
    return true;
  }
  return false;
}

const AuthFactorInput::Password& AuthFactorInput::GetPasswordInput() const {
  return std::get<AuthFactorInput::Password>(factor_input_);
}

const AuthFactorInput::Pin& AuthFactorInput::GetPinInput() const {
  return std::get<AuthFactorInput::Pin>(factor_input_);
}

const AuthFactorInput::RecoveryCreation&
AuthFactorInput::GetRecoveryCreationInput() const {
  return std::get<AuthFactorInput::RecoveryCreation>(factor_input_);
}
const AuthFactorInput::RecoveryAuthentication&
AuthFactorInput::GetRecoveryAuthenticationInput() const {
  return std::get<AuthFactorInput::RecoveryAuthentication>(factor_input_);
}
const AuthFactorInput::SmartCard& AuthFactorInput::GetSmartCardInput() const {
  return std::get<AuthFactorInput::SmartCard>(factor_input_);
}

}  // namespace cryptohome