File: passphrase_enums.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 3,382 bytes parent folder | download | duplicates (6)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_BASE_PASSPHRASE_ENUMS_H_
#define COMPONENTS_SYNC_BASE_PASSPHRASE_ENUMS_H_

#include <cstdint>
#include <optional>

namespace sync_pb {
enum NigoriSpecifics_KeyDerivationMethod : int;
enum NigoriSpecifics_PassphraseType : int;
}  // namespace sync_pb

namespace syncer {

// The different states for the encryption passphrase. These control if and how
// the user should be prompted for a decryption passphrase.
// Do not re-order or delete these entries; they are used in a UMA histogram.
// Please edit SyncPassphraseType in enums.xml if a value is added.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.sync
// LINT.IfChange(SyncPassphraseType)
enum class PassphraseType {
  // GAIA-based passphrase (deprecated).
  // TODO(crbug.com/1201684,crbug.com/1466401): Some codepaths use this value as
  // a synonym for an unknown passphrase type. Rename to reflect this or use
  // std::optional<>.
  kImplicitPassphrase = 0,
  // Keystore passphrase.
  kKeystorePassphrase = 1,
  // Frozen GAIA passphrase.
  kFrozenImplicitPassphrase = 2,
  // User-provided passphrase.
  kCustomPassphrase = 3,
  // Trusted-vault passphrase.
  kTrustedVaultPassphrase = 4,
  // Alias used by UMA macros to deduce the correct boundary value.
  kMaxValue = kTrustedVaultPassphrase
};
// LINT.ThenChange(/tools/metrics/histograms/metadata/sync/enums.xml:SyncPassphraseType)

bool IsExplicitPassphrase(PassphraseType type);

// Function meant to convert `NigoriSpecifics.passphrase_type` into enum.
// All unknown values are returned as UNKNOWN, which mainly represents future
// values of the enum that are not currently supported. Note however that if the
// field is not populated, it defaults to IMPLICIT_PASSPHRASE for backwards
// compatibility reasons.
sync_pb::NigoriSpecifics_PassphraseType ProtoPassphraseInt32ToProtoEnum(
    std::int32_t type);

// Returns std::nullopt if `type` represents an unknown value, likely coming
// from a future version of the browser. Note however that if the field is not
// populated, it defaults to IMPLICIT_PASSPHRASE for backwards compatibility
// reasons.
std::optional<PassphraseType> ProtoPassphraseInt32ToEnum(std::int32_t type);

sync_pb::NigoriSpecifics_PassphraseType EnumPassphraseTypeToProto(
    PassphraseType type);

// Different key derivation methods. Used for deriving the encryption key from a
// user's custom passphrase.
enum class KeyDerivationMethod {
  PBKDF2_HMAC_SHA1_1003 = 0,  // PBKDF2-HMAC-SHA1 with 1003 iterations.
  SCRYPT_8192_8_11 = 1,  // scrypt with N = 2^13, r = 8, p = 11 and random salt.
};

// This function accepts an integer and not KeyDerivationMethod from the proto
// in order to be able to handle new, unknown values. Returns nullopt if value
// is unknown (indicates protocol violation or value coming from newer version)
// and PBKDF2_HMAC_SHA1_1003 if value is unspecified (indicates value coming
// from older version, that is not aware of the field).
std::optional<KeyDerivationMethod> ProtoKeyDerivationMethodToEnum(
    std::int32_t method);

sync_pb::NigoriSpecifics_KeyDerivationMethod EnumKeyDerivationMethodToProto(
    KeyDerivationMethod method);

}  // namespace syncer

#endif  // COMPONENTS_SYNC_BASE_PASSPHRASE_ENUMS_H_