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

Unified Diff: components/sync/base/cryptographer.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/base/cryptographer.h ('k') | components/sync/base/cryptographer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/base/cryptographer.cc
diff --git a/sync/util/cryptographer.cc b/components/sync/base/cryptographer.cc
similarity index 89%
rename from sync/util/cryptographer.cc
rename to components/sync/base/cryptographer.cc
index 5a5bcfce6be9d5c077807a50411457a085712cfe..b6c130abb311878a9c39b5bf57215c04aa318a95 100644
--- a/sync/util/cryptographer.cc
+++ b/components/sync/base/cryptographer.cc
@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/util/cryptographer.h"
+#include "components/sync/base/cryptographer.h"
#include <stddef.h>
+
#include <algorithm>
#include <utility>
#include "base/base64.h"
#include "base/logging.h"
-#include "sync/protocol/nigori_specifics.pb.h"
-#include "sync/util/encryptor.h"
+#include "components/sync/base/encryptor.h"
+#include "components/sync/protocol/nigori_specifics.pb.h"
namespace syncer {
@@ -23,8 +24,7 @@ const char kNigoriTag[] = "google_chrome_nigori";
// assign the same name to a particular triplet.
const char kNigoriKeyName[] = "nigori-key";
-Cryptographer::Cryptographer(Encryptor* encryptor)
- : encryptor_(encryptor) {
+Cryptographer::Cryptographer(Encryptor* encryptor) : encryptor_(encryptor) {
DCHECK(encryptor);
}
@@ -32,8 +32,7 @@ Cryptographer::Cryptographer(const Cryptographer& other)
: encryptor_(other.encryptor_),
default_nigori_name_(other.default_nigori_name_) {
for (NigoriMap::const_iterator it = other.nigoris_.begin();
- it != other.nigoris_.end();
- ++it) {
+ it != other.nigoris_.end(); ++it) {
std::string user_key, encryption_key, mac_key;
it->second->ExportKeys(&user_key, &encryption_key, &mac_key);
linked_ptr<Nigori> nigori_copy(new Nigori());
@@ -48,7 +47,6 @@ Cryptographer::Cryptographer(const Cryptographer& other)
Cryptographer::~Cryptographer() {}
-
void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) {
if (is_initialized()) {
NOTREACHED();
@@ -72,9 +70,8 @@ bool Cryptographer::CanDecryptUsingDefaultKey(
data.key_name() == default_nigori_name_;
}
-bool Cryptographer::Encrypt(
- const ::google::protobuf::MessageLite& message,
- sync_pb::EncryptedData* encrypted) const {
+bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
+ sync_pb::EncryptedData* encrypted) const {
DCHECK(encrypted);
if (default_nigori_name_.empty()) {
LOG(ERROR) << "Cryptographer not ready, failed to encrypt.";
@@ -90,9 +87,8 @@ bool Cryptographer::Encrypt(
return EncryptString(serialized, encrypted);
}
-bool Cryptographer::EncryptString(
- const std::string& serialized,
- sync_pb::EncryptedData* encrypted) const {
+bool Cryptographer::EncryptString(const std::string& serialized,
+ sync_pb::EncryptedData* encrypted) const {
if (CanDecryptUsingDefaultKey(*encrypted)) {
const std::string& original_serialized = DecryptToString(*encrypted);
if (original_serialized == serialized) {
@@ -109,8 +105,7 @@ bool Cryptographer::EncryptString(
}
encrypted->set_key_name(default_nigori_name_);
- if (!default_nigori->second->Encrypt(serialized,
- encrypted->mutable_blob())) {
+ if (!default_nigori->second->Encrypt(serialized, encrypted->mutable_blob())) {
LOG(ERROR) << "Failed to encrypt data.";
return false;
}
@@ -153,8 +148,7 @@ bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const {
const Nigori& nigori = *it->second;
sync_pb::NigoriKey* key = bag.add_key();
key->set_name(it->first);
- nigori.ExportKeys(key->mutable_user_key(),
- key->mutable_encryption_key(),
+ nigori.ExportKeys(key->mutable_user_key(), key->mutable_encryption_key(),
key->mutable_mac_key());
}
@@ -165,8 +159,7 @@ bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const {
bool Cryptographer::AddKey(const KeyParams& params) {
// Create the new Nigori and make it the default encryptor.
std::unique_ptr<Nigori> nigori(new Nigori);
- if (!nigori->InitByDerivation(params.hostname,
- params.username,
+ if (!nigori->InitByDerivation(params.hostname, params.username,
params.password)) {
NOTREACHED(); // Invalid username or password.
return false;
@@ -178,8 +171,7 @@ bool Cryptographer::AddNonDefaultKey(const KeyParams& params) {
DCHECK(is_initialized());
// Create the new Nigori and add it to the keybag.
std::unique_ptr<Nigori> nigori(new Nigori);
- if (!nigori->InitByDerivation(params.hostname,
- params.username,
+ if (!nigori->InitByDerivation(params.hostname, params.username,
params.password)) {
NOTREACHED(); // Invalid username or password.
return false;
@@ -190,8 +182,8 @@ bool Cryptographer::AddNonDefaultKey(const KeyParams& params) {
bool Cryptographer::AddKeyFromBootstrapToken(
const std::string& restored_bootstrap_token) {
// Create the new Nigori and make it the default encryptor.
- std::string serialized_nigori_key = UnpackBootstrapToken(
- restored_bootstrap_token);
+ std::string serialized_nigori_key =
+ UnpackBootstrapToken(restored_bootstrap_token);
return ImportNigoriKey(serialized_nigori_key);
}
@@ -216,7 +208,8 @@ bool Cryptographer::AddKeyImpl(std::unique_ptr<Nigori> initialized_nigori,
}
// The just-added key takes priority over the pending keys as default.
- if (set_as_default) SetDefaultKey(name);
+ if (set_as_default)
+ SetDefaultKey(name);
return true;
}
@@ -247,8 +240,7 @@ const sync_pb::EncryptedData& Cryptographer::GetPendingKeys() const {
bool Cryptographer::DecryptPendingKeys(const KeyParams& params) {
Nigori nigori;
- if (!nigori.InitByDerivation(params.hostname,
- params.username,
+ if (!nigori.InitByDerivation(params.hostname, params.username,
params.password)) {
NOTREACHED();
return false;
@@ -312,8 +304,7 @@ void Cryptographer::InstallKeyBag(const sync_pb::NigoriKeyBag& bag) {
// Only use this key if we don't already know about it.
if (nigoris_.end() == nigoris_.find(key.name())) {
std::unique_ptr<Nigori> new_nigori(new Nigori);
- if (!new_nigori->InitByImport(key.user_key(),
- key.encryption_key(),
+ if (!new_nigori->InitByImport(key.user_key(), key.encryption_key(),
key.mac_key())) {
NOTREACHED();
continue;
« no previous file with comments | « components/sync/base/cryptographer.h ('k') | components/sync/base/cryptographer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698