summaryrefslogtreecommitdiffstats
path: root/components/sync_driver
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-15 06:28:03 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-15 06:28:03 +0000
commit5aed8ebdc4fbb64293d9b069506e7c4dbffd99dc (patch)
treeacc274a46837ad84183fc7ef9a8c680341552e00 /components/sync_driver
parentaa003a516ad8ee8e86066ab2ea343a30426b47ca (diff)
downloadchromium_src-5aed8ebdc4fbb64293d9b069506e7c4dbffd99dc.zip
chromium_src-5aed8ebdc4fbb64293d9b069506e7c4dbffd99dc.tar.gz
chromium_src-5aed8ebdc4fbb64293d9b069506e7c4dbffd99dc.tar.bz2
Eliminate ChromeEncryptor in favor of using webdata's Encryptor directly.
BUG=339731 TEST=chrome, unit_tests, sync_unit_tests R=zea@chromium.org TBR=thestig,joi Review URL: https://codereview.chromium.org/154753004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/sync_driver')
-rw-r--r--components/sync_driver/DEPS1
-rw-r--r--components/sync_driver/system_encryptor.cc23
-rw-r--r--components/sync_driver/system_encryptor.h27
-rw-r--r--components/sync_driver/system_encryptor_unittest.cc37
4 files changed, 88 insertions, 0 deletions
diff --git a/components/sync_driver/DEPS b/components/sync_driver/DEPS
index 067cea9..d3a3e4d 100644
--- a/components/sync_driver/DEPS
+++ b/components/sync_driver/DEPS
@@ -1,5 +1,6 @@
include_rules = [
# SyncDriver is used by iOS, which does not use content.
"-content",
+ "+components/webdata/encryptor",
"+sync",
]
diff --git a/components/sync_driver/system_encryptor.cc b/components/sync_driver/system_encryptor.cc
new file mode 100644
index 0000000..74d63fc
--- /dev/null
+++ b/components/sync_driver/system_encryptor.cc
@@ -0,0 +1,23 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/sync_driver/system_encryptor.h"
+
+#include "components/webdata/encryptor/encryptor.h"
+
+namespace browser_sync {
+
+SystemEncryptor::~SystemEncryptor() {}
+
+bool SystemEncryptor::EncryptString(const std::string& plaintext,
+ std::string* ciphertext) {
+ return ::Encryptor::EncryptString(plaintext, ciphertext);
+}
+
+bool SystemEncryptor::DecryptString(const std::string& ciphertext,
+ std::string* plaintext) {
+ return ::Encryptor::DecryptString(ciphertext, plaintext);
+}
+
+} // namespace browser_sync
diff --git a/components/sync_driver/system_encryptor.h b/components/sync_driver/system_encryptor.h
new file mode 100644
index 0000000..5552b76
--- /dev/null
+++ b/components/sync_driver/system_encryptor.h
@@ -0,0 +1,27 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_
+#define COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_
+
+#include "base/compiler_specific.h"
+#include "sync/util/encryptor.h"
+
+namespace browser_sync {
+
+// Encryptor that uses the Chrome password manager's encryptor.
+class SystemEncryptor : public syncer::Encryptor {
+ public:
+ virtual ~SystemEncryptor();
+
+ virtual bool EncryptString(const std::string& plaintext,
+ std::string* ciphertext) OVERRIDE;
+
+ virtual bool DecryptString(const std::string& ciphertext,
+ std::string* plaintext) OVERRIDE;
+};
+
+} // namespace browser_sync
+
+#endif // COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_
diff --git a/components/sync_driver/system_encryptor_unittest.cc b/components/sync_driver/system_encryptor_unittest.cc
new file mode 100644
index 0000000..a172afa
--- /dev/null
+++ b/components/sync_driver/system_encryptor_unittest.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/sync_driver/system_encryptor.h"
+
+#include "components/webdata/encryptor/encryptor.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser_sync {
+
+namespace {
+
+const char kPlaintext[] = "The Magic Words are Squeamish Ossifrage";
+
+class SystemEncryptorTest : public testing::Test {
+ protected:
+ SystemEncryptor encryptor_;
+};
+
+TEST_F(SystemEncryptorTest, EncryptDecrypt) {
+#if defined(OS_MACOSX)
+ // SystemEncryptor ends up needing access to the keychain on OS X,
+ // so use the mock keychain to prevent prompts.
+ ::Encryptor::UseMockKeychain(true);
+#endif
+ std::string ciphertext;
+ EXPECT_TRUE(encryptor_.EncryptString(kPlaintext, &ciphertext));
+ EXPECT_NE(kPlaintext, ciphertext);
+ std::string plaintext;
+ EXPECT_TRUE(encryptor_.DecryptString(ciphertext, &plaintext));
+ EXPECT_EQ(kPlaintext, plaintext);
+}
+
+} // namespace
+
+} // namespace browser_sync