summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 22:40:58 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-02 22:40:58 +0000
commita0ea1bc8f4c78cbc57bb3e282882a796a8ab1a57 (patch)
tree706d5f2b8e10dd445ae81467cf37205b33f979cc
parent7dc52f27b89ea2ab8b82a127fc899efef70fc613 (diff)
downloadchromium_src-a0ea1bc8f4c78cbc57bb3e282882a796a8ab1a57.zip
chromium_src-a0ea1bc8f4c78cbc57bb3e282882a796a8ab1a57.tar.gz
chromium_src-a0ea1bc8f4c78cbc57bb3e282882a796a8ab1a57.tar.bz2
Convert encryptor.cc and friends to string16.
Review URL: http://codereview.chromium.org/28292 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10740 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/string16.cc6
-rw-r--r--base/string16.h2
-rw-r--r--chrome/browser/password_manager/encryptor.cc16
-rw-r--r--chrome/browser/password_manager/encryptor.h26
-rw-r--r--chrome/browser/password_manager/encryptor_unittest.cc42
-rw-r--r--chrome/browser/webdata/web_database.cc22
-rw-r--r--chrome/common/temp_scaffolding_stubs.h9
7 files changed, 68 insertions, 55 deletions
diff --git a/base/string16.cc b/base/string16.cc
index 2a7ec9c..a47a147 100644
--- a/base/string16.cc
+++ b/base/string16.cc
@@ -13,6 +13,8 @@
#elif defined(WCHAR_T_IS_UTF32)
+#include "base/string_util.h"
+
namespace base {
int c16memcmp(const char16* s1, const char16* s2, size_t n) {
@@ -65,4 +67,8 @@ char16* c16memset(char16* s, char16 c, size_t n) {
} // namespace base
+std::ostream& operator<<(std::ostream& out, const string16& str) {
+ return out << UTF16ToUTF8(str);
+}
+
#endif // WCHAR_T_IS_UTF32
diff --git a/base/string16.h b/base/string16.h
index f545286..11f79e3 100644
--- a/base/string16.h
+++ b/base/string16.h
@@ -124,6 +124,8 @@ struct string16_char_traits {
typedef std::basic_string<char16, base::string16_char_traits> string16;
+extern std::ostream& operator<<(std::ostream& out, const string16& str);
+
#endif // WCHAR_T_IS_UTF32
#endif // BASE_STRING16_H_
diff --git a/chrome/browser/password_manager/encryptor.cc b/chrome/browser/password_manager/encryptor.cc
index b5c0755..0f7ea1d 100644
--- a/chrome/browser/password_manager/encryptor.cc
+++ b/chrome/browser/password_manager/encryptor.cc
@@ -10,18 +10,18 @@
#pragma comment(lib, "crypt32.lib")
-bool Encryptor::EncryptWideString(const std::wstring& plaintext,
- std::string* ciphertext) {
- return EncryptString(WideToUTF8(plaintext), ciphertext);
+bool Encryptor::EncryptString16(const string16& plaintext,
+ std::string* ciphertext) {
+ return EncryptString(UTF16ToUTF8(plaintext), ciphertext);
}
-bool Encryptor::DecryptWideString(const std::string& ciphertext,
- std::wstring* plaintext){
+bool Encryptor::DecryptString16(const std::string& ciphertext,
+ string16* plaintext) {
std::string utf8;
if (!DecryptString(ciphertext, &utf8))
return false;
- *plaintext = UTF8ToWide(utf8);
+ *plaintext = UTF8ToUTF16(utf8);
return true;
}
@@ -47,7 +47,7 @@ bool Encryptor::EncryptString(const std::string& plaintext,
}
bool Encryptor::DecryptString(const std::string& ciphertext,
- std::string* plaintext){
+ std::string* plaintext) {
DATA_BLOB input;
input.pbData = const_cast<BYTE*>(
reinterpret_cast<const BYTE*>(ciphertext.data()));
@@ -56,7 +56,7 @@ bool Encryptor::DecryptString(const std::string& ciphertext,
DATA_BLOB output;
BOOL result = CryptUnprotectData(&input, NULL, NULL, NULL, NULL,
0, &output);
- if(!result)
+ if (!result)
return false;
plaintext->assign(reinterpret_cast<char*>(output.pbData), output.cbData);
diff --git a/chrome/browser/password_manager/encryptor.h b/chrome/browser/password_manager/encryptor.h
index 7233960..8170892 100644
--- a/chrome/browser/password_manager/encryptor.h
+++ b/chrome/browser/password_manager/encryptor.h
@@ -3,27 +3,28 @@
// found in the LICENSE file.
// A class for encrypting/decrypting strings
-#ifndef CHROME_BROWSER_ENCRYPTOR_H__
-#define CHROME_BROWSER_ENCRYPTOR_H__
+#ifndef CHROME_BROWSER_PASSWORD_MANAGER_ENCRYPTOR_H__
+#define CHROME_BROWSER_PASSWORD_MANAGER_ENCRYPTOR_H__
#include <string>
#include "base/values.h"
+#include "base/string16.h"
class Encryptor {
-public:
- // Encrypt a wstring. The output (second argument) is
+ public:
+ // Encrypt a string16. The output (second argument) is
// really an array of bytes, but we're passing it back
// as a std::string
- static bool EncryptWideString(const std::wstring& plaintext,
- std::string* ciphertext);
+ static bool EncryptString16(const string16& plaintext,
+ std::string* ciphertext);
- // Decrypt an array of bytes obtained with EnctryptWideString
- // back into a wstring. Note that the input (first argument)
+ // Decrypt an array of bytes obtained with EncryptString16
+ // back into a string16. Note that the input (first argument)
// is a std::string, so you need to first get your (binary)
// data into a string.
- static bool DecryptWideString(const std::string& ciphertext,
- std::wstring* plaintext);
+ static bool DecryptString16(const std::string& ciphertext,
+ string16* plaintext);
// Encrypt a string.
static bool EncryptString(const std::string& plaintext,
@@ -36,9 +37,8 @@ public:
static bool DecryptString(const std::string& ciphertext,
std::string* plaintext);
-private:
+ private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Encryptor);
};
-#endif // CHROME_BROWSER_ENCRYPTOR_H__
-
+#endif // CHROME_BROWSER_PASSWORD_MANAGER_ENCRYPTOR_H__
diff --git a/chrome/browser/password_manager/encryptor_unittest.cc b/chrome/browser/password_manager/encryptor_unittest.cc
index a1bbd36..dda9299 100644
--- a/chrome/browser/password_manager/encryptor_unittest.cc
+++ b/chrome/browser/password_manager/encryptor_unittest.cc
@@ -11,45 +11,45 @@
namespace {
-TEST(EncryptorTest, WideEncryptionDecryption) {
- std::wstring plaintext;
- std::wstring result;
+TEST(EncryptorTest, String16EncryptionDecryption) {
+ string16 plaintext;
+ string16 result;
std::string utf8_plaintext;
std::string utf8_result;
std::string ciphertext;
// test borderline cases (empty strings)
- EXPECT_TRUE(Encryptor::EncryptWideString(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptWideString(ciphertext, &result));
+ EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// test a simple string
- plaintext = L"hello";
- EXPECT_TRUE(Encryptor::EncryptWideString(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptWideString(ciphertext, &result));
+ plaintext = ASCIIToUTF16("hello");
+ EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// test unicode
- std::wstring::value_type wchars[] = { 0xdbeb,0xdf1b,0x4e03,0x6708,0x8849,
- 0x661f,0x671f,0x56db,0x597c,0x4e03,
- 0x6708,0x56db,0x6708,0xe407,0xdbaf,
- 0xdeb5,0x4ec5,0x544b,0x661f,0x671f,
- 0x65e5,0x661f,0x671f,0x4e94,0xd8b1,
- 0xdce1,0x7052,0x5095,0x7c0b,0xe586, 0};
+ char16 wchars[] = { 0xdbeb, 0xdf1b, 0x4e03, 0x6708, 0x8849,
+ 0x661f, 0x671f, 0x56db, 0x597c, 0x4e03,
+ 0x6708, 0x56db, 0x6708, 0xe407, 0xdbaf,
+ 0xdeb5, 0x4ec5, 0x544b, 0x661f, 0x671f,
+ 0x65e5, 0x661f, 0x671f, 0x4e94, 0xd8b1,
+ 0xdce1, 0x7052, 0x5095, 0x7c0b, 0xe586, 0};
plaintext = wchars;
- utf8_plaintext = WideToUTF8(plaintext);
- EXPECT_EQ(plaintext, UTF8ToWide(utf8_plaintext));
- EXPECT_TRUE(Encryptor::EncryptWideString(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptWideString(ciphertext, &result));
+ utf8_plaintext = UTF16ToUTF8(plaintext);
+ EXPECT_EQ(plaintext, UTF8ToUTF16(utf8_plaintext));
+ EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &utf8_result));
- EXPECT_EQ(utf8_plaintext, WideToUTF8(result));
+ EXPECT_EQ(utf8_plaintext, UTF16ToUTF8(result));
EXPECT_TRUE(Encryptor::EncryptString(utf8_plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptWideString(ciphertext, &result));
+ EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &utf8_result));
- EXPECT_EQ(utf8_plaintext, WideToUTF8(result));
+ EXPECT_EQ(utf8_plaintext, UTF16ToUTF8(result));
}
TEST(EncryptorTest, EncryptionDecryption) {
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index 7fcfa4c..b8a7e8c 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -118,7 +118,7 @@ std::string JoinStrings(const std::string& separator,
return std::string();
std::vector<std::string>::const_iterator i(strings.begin());
std::string result(*i);
- while(++i != strings.end())
+ while (++i != strings.end())
result += separator + *i;
return result;
}
@@ -641,7 +641,8 @@ bool WebDatabase::AddLogin(const PasswordForm& form) {
s.bind_wstring(2, form.username_element);
s.bind_wstring(3, form.username_value);
s.bind_wstring(4, form.password_element);
- Encryptor::EncryptWideString(form.password_value, &encrypted_password);
+ Encryptor::EncryptString16(WideToUTF16Hack(form.password_value),
+ &encrypted_password);
s.bind_blob(5, encrypted_password.data(),
static_cast<int>(encrypted_password.length()));
s.bind_wstring(6, form.submit_element);
@@ -676,7 +677,8 @@ bool WebDatabase::UpdateLogin(const PasswordForm& form) {
}
s.bind_string(0, form.action.spec());
- Encryptor::EncryptWideString(form.password_value, &encrypted_password);
+ Encryptor::EncryptString16(WideToUTF16Hack(form.password_value),
+ &encrypted_password);
s.bind_blob(1, encrypted_password.data(),
static_cast<int>(encrypted_password.length()));
s.bind_int(2, form.ssl_valid);
@@ -757,6 +759,7 @@ static void InitPasswordFormFromStatement(PasswordForm* form,
SQLStatement* s) {
std::string encrypted_password;
std::string tmp;
+ string16 decrypted_password;
s->column_string(0, &tmp);
form->origin = GURL(tmp);
s->column_string(1, &tmp);
@@ -765,7 +768,8 @@ static void InitPasswordFormFromStatement(PasswordForm* form,
s->column_wstring(3, &form->username_value);
s->column_wstring(4, &form->password_element);
s->column_blob_as_string(5, &encrypted_password);
- Encryptor::DecryptWideString(encrypted_password, &form->password_value);
+ Encryptor::DecryptString16(encrypted_password, &decrypted_password);
+ form->password_value = UTF16ToWideHack(decrypted_password);
s->column_wstring(6, &form->submit_element);
s->column_string(7, &tmp);
form->signon_realm = tmp;
@@ -863,10 +867,10 @@ bool WebDatabase::ClearAutofillEmptyValueElements() {
bool success = true;
for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end();
++iter) {
- if (!RemoveFormElement(*iter))
+ if (!RemoveFormElement(*iter))
success = false;
}
-
+
return success;
}
@@ -1059,7 +1063,7 @@ bool WebDatabase::RemoveFormElementsAddedBetween(const Time delete_begin,
return false;
}
s.bind_int64(0, delete_begin.ToTimeT());
- s.bind_int64(1,
+ s.bind_int64(1,
delete_end.is_null() ?
std::numeric_limits<int64>::max() :
delete_end.ToTimeT());
@@ -1113,7 +1117,7 @@ bool WebDatabase::RemoveFormElementForTimeRange(int64 pair_id,
}
bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) {
- int count=0;
+ int count = 0;
if (!GetCountOfFormElement(pair_id, &count))
return false;
@@ -1145,7 +1149,7 @@ bool WebDatabase::RemoveFormElement(int64 pair_id) {
void WebDatabase::MigrateOldVersionsAsNeeded() {
// Migrate if necessary.
int current_version = meta_table_.GetVersionNumber();
- switch(current_version) {
+ switch (current_version) {
// Versions 1 - 19 are unhandled. Version numbers greater than
// kCurrentVersionNumber should have already been weeded out by the caller.
default:
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index fbc7d5a..27fc505 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -18,6 +18,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
+#include "base/string16.h"
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -581,14 +582,14 @@ class SharedMemory;
class Encryptor {
public:
- static bool EncryptWideString(const std::wstring& plaintext,
- std::string* ciphertext) {
+ static bool EncryptString16(const string16& plaintext,
+ std::string* ciphertext) {
NOTIMPLEMENTED();
return false;
}
- static bool DecryptWideString(const std::string& ciphertext,
- std::wstring* plaintext) {
+ static bool DecryptString16(const std::string& ciphertext,
+ string16* plaintext) {
NOTIMPLEMENTED();
return false;
}