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

Unified Diff: chrome/browser/sync/util/cryptographer.cc

Issue 8759019: [Sync] Add intelligent re-encryption support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years 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
Index: chrome/browser/sync/util/cryptographer.cc
diff --git a/chrome/browser/sync/util/cryptographer.cc b/chrome/browser/sync/util/cryptographer.cc
index 59e96103ba71c56891b7dc3a0baf41e69f35a40a..047a6e9120de004fc139d1fea40ed48054e16bc0 100644
--- a/chrome/browser/sync/util/cryptographer.cc
+++ b/chrome/browser/sync/util/cryptographer.cc
@@ -57,9 +57,11 @@ bool Cryptographer::CanDecryptUsingDefaultKey(
return default_nigori_ && (data.key_name() == default_nigori_->first);
}
-bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
- sync_pb::EncryptedData* encrypted) const {
- if (!encrypted || !default_nigori_) {
+bool Cryptographer::Encrypt(
+ const ::google::protobuf::MessageLite& message,
+ sync_pb::EncryptedData* encrypted) const {
+ DCHECK(encrypted);
+ if (!default_nigori_) {
LOG(ERROR) << "Cryptographer not ready, failed to encrypt.";
return false;
}
@@ -70,9 +72,23 @@ bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
return false;
}
+ if (CanDecryptUsingDefaultKey(*encrypted)) {
+ const std::string& original_serialized = DecryptToString(*encrypted);
+ if (original_serialized == serialized) {
+ DVLOG(2) << "Re-encryption unnecessary, encrypted data already matches.";
+ return true;
+ }
+ }
+
+ return EncryptImpl(serialized, default_nigori_, encrypted);
akalin 2011/12/12 22:05:22 do we still need the Encrypt/EncryptImpl divide?
Nicolas Zea 2011/12/13 00:43:30 Done.
+}
+
+bool Cryptographer::EncryptImpl(const std::string& serialized,
+ const NigoriMap::value_type* nigori,
+ sync_pb::EncryptedData* encrypted) const {
encrypted->set_key_name(default_nigori_->first);
- if (!default_nigori_->second->Encrypt(serialized,
- encrypted->mutable_blob())) {
+ if (!nigori->second->Encrypt(serialized,
+ encrypted->mutable_blob())) {
LOG(ERROR) << "Failed to encrypt data.";
return false;
}

Powered by Google App Engine
This is Rietveld 408576698