Chromium Code Reviews| OLD | NEW |
|---|---|
| 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( |
| 19 bool encrypt, | |
| 20 bool sign, | |
| 21 const std::string& symmetric_key, | |
| 22 const std::string& public_key, | |
| 23 bool wrapped) | |
| 24 : encrypt(encrypt), | |
| 25 sign(sign), | |
| 26 symmetric_key(symmetric_key), | |
| 27 public_key(public_key), | |
| 28 wrapped(wrapped) { | |
| 29 } | |
| 30 | |
| 31 bool KeyDefinition::AuthorizationData::Secret::operator==( | |
| 32 const Secret& other) const { | |
| 33 return encrypt == other.encrypt && | |
| 34 sign == other.sign && | |
| 35 symmetric_key == other.symmetric_key && | |
| 36 public_key == other.public_key && | |
| 37 wrapped == other.wrapped; | |
| 38 } | |
| 39 | |
| 40 KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256) { | |
| 41 } | |
| 42 | |
| 43 KeyDefinition::AuthorizationData::~AuthorizationData() { | |
| 44 } | |
| 45 | |
| 46 bool KeyDefinition::AuthorizationData::operator==( | |
| 47 const AuthorizationData& other) const { | |
| 48 if (type != other.type || secrets.size() != other.secrets.size()) | |
| 49 return false; | |
| 50 for (size_t i = 0; i < secrets.size(); ++i) { | |
| 51 if (!(secrets[i] == other.secrets[i])) | |
| 52 return false; | |
| 53 } | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 KeyDefinition::ProviderData::ProviderData(const std::string& name) | |
| 58 : name(name) { | |
| 59 } | |
| 60 | |
| 61 KeyDefinition::ProviderData::ProviderData(const ProviderData& other) | |
| 62 : name(other.name) { | |
| 63 if (other.number) | |
| 64 number.reset(new int64(*other.number)); | |
| 65 if (other.bytes) | |
| 66 bytes.reset(new std::string(*other.bytes)); | |
| 67 } | |
| 68 | |
| 69 void KeyDefinition::ProviderData::operator=(const ProviderData& other) { | |
| 70 name = other.name; | |
| 71 number.reset(other.number ? new int64(*other.number) : NULL); | |
| 72 bytes.reset(other.bytes ? new std::string(*other.bytes) : NULL); | |
| 73 } | |
| 74 | |
| 75 KeyDefinition::ProviderData::~ProviderData() { | |
| 76 } | |
| 77 | |
| 78 bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const { | |
| 79 return ((name == other.name) && | |
| 80 (!number || (other.number && *number == *other.number)) && | |
| 81 (!bytes || (other.bytes && *bytes == *other.bytes))); | |
|
Darren Krahn
2014/09/02 18:21:52
Should we verify that both have NULL in !number an
bartfab (slow)
2014/09/04 10:14:18
Done.
| |
| 82 } | |
| 83 | |
| 84 KeyDefinition::KeyDefinition(const std::string& secret, | |
| 19 const std::string& label, | 85 const std::string& label, |
| 20 int /*AuthKeyPrivileges*/ privileges) | 86 int /*AuthKeyPrivileges*/ privileges) |
| 21 : label(label), | 87 : type(TYPE_PASSWORD), |
| 22 revision(1), | 88 label(label), |
| 23 key(key), | 89 privileges(privileges), |
| 24 privileges(privileges) { | 90 revision(0), |
| 91 secret(secret) { | |
| 25 } | 92 } |
| 26 | 93 |
| 27 KeyDefinition::~KeyDefinition() { | 94 KeyDefinition::~KeyDefinition() { |
| 28 } | 95 } |
| 29 | 96 |
| 30 bool KeyDefinition::operator==(const KeyDefinition& other) const { | 97 bool KeyDefinition::operator==(const KeyDefinition& other) const { |
| 31 return label == other.label && | 98 if (type != other.type || |
| 32 revision == other.revision && | 99 label != other.label || |
| 33 key == other.key && | 100 privileges != other.privileges || |
| 34 encryption_key == other.encryption_key && | 101 revision != other.revision || |
| 35 signature_key == other.signature_key && | 102 authorization_data.size() != other.authorization_data.size() || |
| 36 privileges == other.privileges; | 103 provider_data.size() != other.provider_data.size()) { |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 for (size_t i = 0; i < authorization_data.size(); ++i) { | |
| 108 if (!(authorization_data[i] == other.authorization_data[i])) | |
| 109 return false; | |
| 110 } | |
| 111 for (size_t i = 0; i < provider_data.size(); ++i) { | |
| 112 if (!(provider_data[i] == other.provider_data[i])) | |
| 113 return false; | |
| 114 } | |
| 115 return true; | |
| 116 } | |
| 117 | |
| 118 void KeyDefinition::AddSymmetricKey(bool encrypt, | |
| 119 bool sign, | |
| 120 const std::string& symmetric_key) { | |
| 121 authorization_data.push_back(AuthorizationData()); | |
| 122 authorization_data.back().secrets.push_back(AuthorizationData::Secret( | |
| 123 encrypt, | |
| 124 sign, | |
| 125 symmetric_key, | |
| 126 std::string() /* public_key */, | |
| 127 false /* wrapped */)); | |
| 37 } | 128 } |
| 38 | 129 |
| 39 Authorization::Authorization(const std::string& key, const std::string& label) | 130 Authorization::Authorization(const std::string& key, const std::string& label) |
| 40 : key(key), | 131 : key(key), |
| 41 label(label) { | 132 label(label) { |
| 42 } | 133 } |
| 43 | 134 |
| 44 Authorization::Authorization(const KeyDefinition& key_def) | 135 Authorization::Authorization(const KeyDefinition& key_def) |
| 45 : key(key_def.key), | 136 : key(key_def.secret), |
| 46 label(key_def.label) { | 137 label(key_def.label) { |
| 47 } | 138 } |
| 48 | 139 |
| 49 bool Authorization::operator==(const Authorization& other) const { | 140 bool Authorization::operator==(const Authorization& other) const { |
| 50 return key == other.key && label == other.label; | 141 return key == other.key && label == other.label; |
| 51 } | 142 } |
| 52 | 143 |
| 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) { | 144 MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { |
| 72 } | 145 } |
| 73 | 146 |
| 74 bool MountParameters::operator==(const MountParameters& other) const { | 147 bool MountParameters::operator==(const MountParameters& other) const { |
| 75 return ephemeral == other.ephemeral && create_keys == other.create_keys; | 148 return ephemeral == other.ephemeral && create_keys == other.create_keys; |
| 76 } | 149 } |
| 77 | 150 |
| 78 MountParameters::~MountParameters() { | 151 MountParameters::~MountParameters() { |
| 79 } | 152 } |
| 80 | 153 |
| 81 } // namespace cryptohome | 154 } // namespace cryptohome |
| OLD | NEW |