Chromium Code Reviews| Index: chromeos/cryptohome/cryptohome_parameters.cc |
| diff --git a/chromeos/cryptohome/cryptohome_parameters.cc b/chromeos/cryptohome/cryptohome_parameters.cc |
| index 41246f37e0e8640ba0cba2a94caa0bd0d31a85bd..f82405010a12912b7d05997be8a7eb08403f6b1f 100644 |
| --- a/chromeos/cryptohome/cryptohome_parameters.cc |
| +++ b/chromeos/cryptohome/cryptohome_parameters.cc |
| @@ -15,25 +15,116 @@ bool Identification::operator==(const Identification& other) const { |
| return user_id == other.user_id; |
| } |
| -KeyDefinition::KeyDefinition(const std::string& key, |
| +KeyDefinition::AuthorizationData::Secret::Secret( |
| + bool encrypt, |
| + bool sign, |
| + const std::string& symmetric_key, |
| + const std::string& public_key, |
| + bool wrapped) |
| + : encrypt(encrypt), |
| + sign(sign), |
| + symmetric_key(symmetric_key), |
| + public_key(public_key), |
| + wrapped(wrapped) { |
| +} |
| + |
| +bool KeyDefinition::AuthorizationData::Secret::operator==( |
| + const Secret& other) const { |
| + return encrypt == other.encrypt && |
| + sign == other.sign && |
| + symmetric_key == other.symmetric_key && |
| + public_key == other.public_key && |
| + wrapped == other.wrapped; |
| +} |
| + |
| +KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256) { |
| +} |
| + |
| +KeyDefinition::AuthorizationData::~AuthorizationData() { |
| +} |
| + |
| +bool KeyDefinition::AuthorizationData::operator==( |
| + const AuthorizationData& other) const { |
| + if (type != other.type || secrets.size() != other.secrets.size()) |
| + return false; |
| + for (size_t i = 0; i < secrets.size(); ++i) { |
| + if (!(secrets[i] == other.secrets[i])) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +KeyDefinition::ProviderData::ProviderData(const std::string& name) |
| + : name(name) { |
| +} |
| + |
| +KeyDefinition::ProviderData::ProviderData(const ProviderData& other) |
| + : name(other.name) { |
| + if (other.number) |
| + number.reset(new int64(*other.number)); |
| + if (other.bytes) |
| + bytes.reset(new std::string(*other.bytes)); |
| +} |
| + |
| +void KeyDefinition::ProviderData::operator=(const ProviderData& other) { |
| + name = other.name; |
| + number.reset(other.number ? new int64(*other.number) : NULL); |
| + bytes.reset(other.bytes ? new std::string(*other.bytes) : NULL); |
| +} |
| + |
| +KeyDefinition::ProviderData::~ProviderData() { |
| +} |
| + |
| +bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const { |
| + return ((name == other.name) && |
| + (!number || (other.number && *number == *other.number)) && |
| + (!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.
|
| +} |
| + |
| +KeyDefinition::KeyDefinition(const std::string& secret, |
| const std::string& label, |
| int /*AuthKeyPrivileges*/ privileges) |
| - : label(label), |
| - revision(1), |
| - key(key), |
| - privileges(privileges) { |
| + : type(TYPE_PASSWORD), |
| + label(label), |
| + privileges(privileges), |
| + revision(0), |
| + secret(secret) { |
| } |
| KeyDefinition::~KeyDefinition() { |
| } |
| bool KeyDefinition::operator==(const KeyDefinition& other) const { |
| - return label == other.label && |
| - revision == other.revision && |
| - key == other.key && |
| - encryption_key == other.encryption_key && |
| - signature_key == other.signature_key && |
| - privileges == other.privileges; |
| + if (type != other.type || |
| + label != other.label || |
| + privileges != other.privileges || |
| + revision != other.revision || |
| + authorization_data.size() != other.authorization_data.size() || |
| + provider_data.size() != other.provider_data.size()) { |
| + return false; |
| + } |
| + |
| + for (size_t i = 0; i < authorization_data.size(); ++i) { |
| + if (!(authorization_data[i] == other.authorization_data[i])) |
| + return false; |
| + } |
| + for (size_t i = 0; i < provider_data.size(); ++i) { |
| + if (!(provider_data[i] == other.provider_data[i])) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +void KeyDefinition::AddSymmetricKey(bool encrypt, |
| + bool sign, |
| + const std::string& symmetric_key) { |
| + authorization_data.push_back(AuthorizationData()); |
| + authorization_data.back().secrets.push_back(AuthorizationData::Secret( |
| + encrypt, |
| + sign, |
| + symmetric_key, |
| + std::string() /* public_key */, |
| + false /* wrapped */)); |
| } |
| Authorization::Authorization(const std::string& key, const std::string& label) |
| @@ -42,7 +133,7 @@ Authorization::Authorization(const std::string& key, const std::string& label) |
| } |
| Authorization::Authorization(const KeyDefinition& key_def) |
| - : key(key_def.key), |
| + : key(key_def.secret), |
| label(key_def.label) { |
| } |
| @@ -50,24 +141,6 @@ bool Authorization::operator==(const Authorization& other) const { |
| return key == other.key && label == other.label; |
| } |
| -RetrievedKeyData::ProviderData::ProviderData(const std::string& name) |
| - : name(name) { |
| -} |
| - |
| -RetrievedKeyData::ProviderData::~ProviderData() { |
| -} |
| - |
| -RetrievedKeyData::RetrievedKeyData(Type type, |
| - const std::string& label, |
| - int64 revision) : type(type), |
| - label(label), |
| - privileges(0), |
| - revision(revision) { |
| -} |
| - |
| -RetrievedKeyData::~RetrievedKeyData() { |
| -} |
| - |
| MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { |
| } |