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

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: Rebase again 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
« no previous file with comments | « chrome/browser/sync/util/cryptographer.h ('k') | chrome/browser/sync/util/cryptographer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/cryptographer.cc
diff --git a/chrome/browser/sync/util/cryptographer.cc b/chrome/browser/sync/util/cryptographer.cc
index a24e9cfd36d88d2bcf67cfa1f4141b7976e1291e..5d1e45009dac82da7320d3749196d16945cca5a6 100644
--- a/chrome/browser/sync/util/cryptographer.cc
+++ b/chrome/browser/sync/util/cryptographer.cc
@@ -55,9 +55,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;
}
@@ -68,6 +70,14 @@ 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;
+ }
+ }
+
encrypted->set_key_name(default_nigori_->first);
if (!default_nigori_->second->Encrypt(serialized,
encrypted->mutable_blob())) {
« no previous file with comments | « chrome/browser/sync/util/cryptographer.h ('k') | chrome/browser/sync/util/cryptographer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698