Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chromeos/cryptohome/cryptohome_parameters.cc

Issue 526353002: Merge cryptohome::RetrievedKeyData with cryptohome::KeyDefinition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@d_2_367847_add_get_key_data_ex_to_mount_flow
Patch Set: Rebased. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/cryptohome/cryptohome_parameters.h ('k') | chromeos/cryptohome/homedir_methods.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/cryptohome/cryptohome_parameters.h" 5 #include "chromeos/cryptohome/cryptohome_parameters.h"
6 6
7 #include "chromeos/dbus/cryptohome/key.pb.h" 7 #include "chromeos/dbus/cryptohome/key.pb.h"
8 8
9 namespace cryptohome { 9 namespace cryptohome {
10 10
11 Identification::Identification(const std::string& user_id) : user_id(user_id) { 11 Identification::Identification(const std::string& user_id) : user_id(user_id) {
12 } 12 }
13 13
14 bool Identification::operator==(const Identification& other) const { 14 bool Identification::operator==(const Identification& other) const {
15 return user_id == other.user_id; 15 return user_id == other.user_id;
16 } 16 }
17 17
18 KeyDefinition::KeyDefinition(const std::string& key, 18 KeyDefinition::AuthorizationData::Secret::Secret() : encrypt(false),
19 sign(false),
20 wrapped(false) {
21 }
22
23 KeyDefinition::AuthorizationData::Secret::Secret(
24 bool encrypt,
25 bool sign,
26 const std::string& symmetric_key,
27 const std::string& public_key,
28 bool wrapped)
29 : encrypt(encrypt),
30 sign(sign),
31 symmetric_key(symmetric_key),
32 public_key(public_key),
33 wrapped(wrapped) {
34 }
35
36 bool KeyDefinition::AuthorizationData::Secret::operator==(
37 const Secret& other) const {
38 return encrypt == other.encrypt &&
39 sign == other.sign &&
40 symmetric_key == other.symmetric_key &&
41 public_key == other.public_key &&
42 wrapped == other.wrapped;
43 }
44
45 KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256) {
46 }
47
48 KeyDefinition::AuthorizationData::AuthorizationData(
49 bool encrypt,
50 bool sign,
51 const std::string& symmetric_key) : type(TYPE_HMACSHA256) {
52 secrets.push_back(Secret(encrypt,
53 sign,
54 symmetric_key,
55 std::string() /* public_key */,
56 false /* wrapped */));
57 }
58
59
60 KeyDefinition::AuthorizationData::~AuthorizationData() {
61 }
62
63 bool KeyDefinition::AuthorizationData::operator==(
64 const AuthorizationData& other) const {
65 if (type != other.type || secrets.size() != other.secrets.size())
66 return false;
67 for (size_t i = 0; i < secrets.size(); ++i) {
68 if (!(secrets[i] == other.secrets[i]))
69 return false;
70 }
71 return true;
72 }
73
74 KeyDefinition::ProviderData::ProviderData() {
75 }
76
77 KeyDefinition::ProviderData::ProviderData(const std::string& name)
78 : name(name) {
79 }
80
81 KeyDefinition::ProviderData::ProviderData(const ProviderData& other)
82 : name(other.name) {
83 if (other.number)
84 number.reset(new int64(*other.number));
85 if (other.bytes)
86 bytes.reset(new std::string(*other.bytes));
87 }
88
89 void KeyDefinition::ProviderData::operator=(const ProviderData& other) {
90 name = other.name;
91 number.reset(other.number ? new int64(*other.number) : NULL);
92 bytes.reset(other.bytes ? new std::string(*other.bytes) : NULL);
93 }
94
95 KeyDefinition::ProviderData::~ProviderData() {
96 }
97
98 bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const {
99 const bool has_number = number;
100 const bool other_has_number = other.number;
101 const bool has_bytes = bytes;
102 const bool other_has_bytes = other.bytes;
103 return name == other.name &&
104 has_number == other_has_number &&
105 has_bytes == other_has_bytes &&
106 (!has_number || (*number == *other.number)) &&
107 (!has_bytes || (*bytes == *other.bytes));
108 }
109
110 KeyDefinition::KeyDefinition() : type(TYPE_PASSWORD),
111 privileges(0),
112 revision(0) {
113 }
114
115 KeyDefinition::KeyDefinition(const std::string& secret,
19 const std::string& label, 116 const std::string& label,
20 int /*AuthKeyPrivileges*/ privileges) 117 int /*AuthKeyPrivileges*/ privileges)
21 : label(label), 118 : type(TYPE_PASSWORD),
22 revision(1), 119 label(label),
23 key(key), 120 privileges(privileges),
24 privileges(privileges) { 121 revision(0),
122 secret(secret) {
25 } 123 }
26 124
27 KeyDefinition::~KeyDefinition() { 125 KeyDefinition::~KeyDefinition() {
28 } 126 }
29 127
30 bool KeyDefinition::operator==(const KeyDefinition& other) const { 128 bool KeyDefinition::operator==(const KeyDefinition& other) const {
31 return label == other.label && 129 if (type != other.type ||
32 revision == other.revision && 130 label != other.label ||
33 key == other.key && 131 privileges != other.privileges ||
34 encryption_key == other.encryption_key && 132 revision != other.revision ||
35 signature_key == other.signature_key && 133 authorization_data.size() != other.authorization_data.size() ||
36 privileges == other.privileges; 134 provider_data.size() != other.provider_data.size()) {
135 return false;
136 }
137
138 for (size_t i = 0; i < authorization_data.size(); ++i) {
139 if (!(authorization_data[i] == other.authorization_data[i]))
140 return false;
141 }
142 for (size_t i = 0; i < provider_data.size(); ++i) {
143 if (!(provider_data[i] == other.provider_data[i]))
144 return false;
145 }
146 return true;
37 } 147 }
38 148
39 Authorization::Authorization(const std::string& key, const std::string& label) 149 Authorization::Authorization(const std::string& key, const std::string& label)
40 : key(key), 150 : key(key),
41 label(label) { 151 label(label) {
42 } 152 }
43 153
44 Authorization::Authorization(const KeyDefinition& key_def) 154 Authorization::Authorization(const KeyDefinition& key_def)
45 : key(key_def.key), 155 : key(key_def.secret),
46 label(key_def.label) { 156 label(key_def.label) {
47 } 157 }
48 158
49 bool Authorization::operator==(const Authorization& other) const { 159 bool Authorization::operator==(const Authorization& other) const {
50 return key == other.key && label == other.label; 160 return key == other.key && label == other.label;
51 } 161 }
52 162
53 RetrievedKeyData::ProviderData::ProviderData(const std::string& name)
54 : name(name) {
55 }
56
57 RetrievedKeyData::ProviderData::~ProviderData() {
58 }
59
60 RetrievedKeyData::RetrievedKeyData(Type type,
61 const std::string& label,
62 int64 revision) : type(type),
63 label(label),
64 privileges(0),
65 revision(revision) {
66 }
67
68 RetrievedKeyData::~RetrievedKeyData() {
69 }
70
71 MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { 163 MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) {
72 } 164 }
73 165
74 bool MountParameters::operator==(const MountParameters& other) const { 166 bool MountParameters::operator==(const MountParameters& other) const {
75 return ephemeral == other.ephemeral && create_keys == other.create_keys; 167 return ephemeral == other.ephemeral && create_keys == other.create_keys;
76 } 168 }
77 169
78 MountParameters::~MountParameters() { 170 MountParameters::~MountParameters() {
79 } 171 }
80 172
81 } // namespace cryptohome 173 } // namespace cryptohome
OLDNEW
« no previous file with comments | « chromeos/cryptohome/cryptohome_parameters.h ('k') | chromeos/cryptohome/homedir_methods.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698