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
3 // found in the LICENSE file.
5 #include "chromeos/cryptohome/cryptohome_parameters.h"
7 #include "chromeos/dbus/cryptohome/key.pb.h"
11 Identification::Identification(const std::string
& user_id
) : user_id(user_id
) {
14 bool Identification::operator==(const Identification
& other
) const {
15 return user_id
== other
.user_id
;
18 KeyDefinition::AuthorizationData::Secret::Secret() : encrypt(false),
23 KeyDefinition::AuthorizationData::Secret::Secret(
26 const std::string
& symmetric_key
,
27 const std::string
& public_key
,
31 symmetric_key(symmetric_key
),
32 public_key(public_key
),
36 bool KeyDefinition::AuthorizationData::Secret::operator==(
37 const Secret
& other
) const {
38 return encrypt
== other
.encrypt
&&
40 symmetric_key
== other
.symmetric_key
&&
41 public_key
== other
.public_key
&&
42 wrapped
== other
.wrapped
;
45 KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256
) {
48 KeyDefinition::AuthorizationData::AuthorizationData(
51 const std::string
& symmetric_key
) : type(TYPE_HMACSHA256
) {
52 secrets
.push_back(Secret(encrypt
,
55 std::string() /* public_key */,
56 false /* wrapped */));
60 KeyDefinition::AuthorizationData::~AuthorizationData() {
63 bool KeyDefinition::AuthorizationData::operator==(
64 const AuthorizationData
& other
) const {
65 if (type
!= other
.type
|| secrets
.size() != other
.secrets
.size())
67 for (size_t i
= 0; i
< secrets
.size(); ++i
) {
68 if (!(secrets
[i
] == other
.secrets
[i
]))
74 KeyDefinition::ProviderData::ProviderData() {
77 KeyDefinition::ProviderData::ProviderData(const std::string
& name
)
81 KeyDefinition::ProviderData::ProviderData(const ProviderData
& other
)
84 number
.reset(new int64(*other
.number
));
86 bytes
.reset(new std::string(*other
.bytes
));
89 KeyDefinition::ProviderData::ProviderData(const std::string
& name
, int64 number
)
91 number(new int64(number
)) {
94 KeyDefinition::ProviderData::ProviderData(const std::string
& name
,
95 const std::string
& bytes
)
97 bytes(new std::string(bytes
)) {
100 void KeyDefinition::ProviderData::operator=(const ProviderData
& other
) {
102 number
.reset(other
.number
? new int64(*other
.number
) : NULL
);
103 bytes
.reset(other
.bytes
? new std::string(*other
.bytes
) : NULL
);
106 KeyDefinition::ProviderData::~ProviderData() {
109 bool KeyDefinition::ProviderData::operator==(const ProviderData
& other
) const {
110 const bool has_number
= number
;
111 const bool other_has_number
= other
.number
;
112 const bool has_bytes
= bytes
;
113 const bool other_has_bytes
= other
.bytes
;
114 return name
== other
.name
&&
115 has_number
== other_has_number
&&
116 has_bytes
== other_has_bytes
&&
117 (!has_number
|| (*number
== *other
.number
)) &&
118 (!has_bytes
|| (*bytes
== *other
.bytes
));
121 KeyDefinition::KeyDefinition() : type(TYPE_PASSWORD
),
126 KeyDefinition::KeyDefinition(const std::string
& secret
,
127 const std::string
& label
,
128 int /*AuthKeyPrivileges*/ privileges
)
129 : type(TYPE_PASSWORD
),
131 privileges(privileges
),
136 KeyDefinition::~KeyDefinition() {
139 bool KeyDefinition::operator==(const KeyDefinition
& other
) const {
140 if (type
!= other
.type
||
141 label
!= other
.label
||
142 privileges
!= other
.privileges
||
143 revision
!= other
.revision
||
144 authorization_data
.size() != other
.authorization_data
.size() ||
145 provider_data
.size() != other
.provider_data
.size()) {
149 for (size_t i
= 0; i
< authorization_data
.size(); ++i
) {
150 if (!(authorization_data
[i
] == other
.authorization_data
[i
]))
153 for (size_t i
= 0; i
< provider_data
.size(); ++i
) {
154 if (!(provider_data
[i
] == other
.provider_data
[i
]))
160 Authorization::Authorization(const std::string
& key
, const std::string
& label
)
165 Authorization::Authorization(const KeyDefinition
& key_def
)
166 : key(key_def
.secret
),
167 label(key_def
.label
) {
170 bool Authorization::operator==(const Authorization
& other
) const {
171 return key
== other
.key
&& label
== other
.label
;
174 MountParameters::MountParameters(bool ephemeral
) : ephemeral(ephemeral
) {
177 bool MountParameters::operator==(const MountParameters
& other
) const {
178 return ephemeral
== other
.ephemeral
&& create_keys
== other
.create_keys
;
181 MountParameters::~MountParameters() {
184 } // namespace cryptohome