MD Downloads: enhance comment about how "No downloads" gets populated
[chromium-blink-merge.git] / chromeos / cryptohome / cryptohome_parameters.cc
blob5b3ac4d4372cab188879a70c44222ed22e442f46
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"
9 namespace cryptohome {
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),
19 sign(false),
20 wrapped(false) {
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) {
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;
45 KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256) {
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 */));
60 KeyDefinition::AuthorizationData::~AuthorizationData() {
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;
71 return true;
74 KeyDefinition::ProviderData::ProviderData() {
77 KeyDefinition::ProviderData::ProviderData(const std::string& name)
78 : name(name) {
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));
89 KeyDefinition::ProviderData::ProviderData(const std::string& name, int64 number)
90 : name(name),
91 number(new int64(number)) {
94 KeyDefinition::ProviderData::ProviderData(const std::string& name,
95 const std::string& bytes)
96 : name(name),
97 bytes(new std::string(bytes)) {
100 void KeyDefinition::ProviderData::operator=(const ProviderData& other) {
101 name = other.name;
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),
122 privileges(0),
123 revision(0) {
126 KeyDefinition::KeyDefinition(const std::string& secret,
127 const std::string& label,
128 int /*AuthKeyPrivileges*/ privileges)
129 : type(TYPE_PASSWORD),
130 label(label),
131 privileges(privileges),
132 revision(0),
133 secret(secret) {
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()) {
146 return false;
149 for (size_t i = 0; i < authorization_data.size(); ++i) {
150 if (!(authorization_data[i] == other.authorization_data[i]))
151 return false;
153 for (size_t i = 0; i < provider_data.size(); ++i) {
154 if (!(provider_data[i] == other.provider_data[i]))
155 return false;
157 return true;
160 Authorization::Authorization(const std::string& key, const std::string& label)
161 : key(key),
162 label(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