diff options
author | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 06:21:53 +0000 |
---|---|---|
committer | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-24 06:21:53 +0000 |
commit | 978df34538607d50bf4690f2d679c1bef860398c (patch) | |
tree | b99abc0b44316c0bfa16374746996ac209e363a6 /net/base | |
parent | 391bbb3fb3fbb0fb7d072878b9cb45e99a519e6e (diff) | |
download | chromium_src-978df34538607d50bf4690f2d679c1bef860398c.zip chromium_src-978df34538607d50bf4690f2d679c1bef860398c.tar.gz chromium_src-978df34538607d50bf4690f2d679c1bef860398c.tar.bz2 |
Move base64 from 'net/base' into 'base'.
BUG=13572
TEST=none
Review URL: http://codereview.chromium.org/399068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32918 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/base64.cc | 41 | ||||
-rw-r--r-- | net/base/base64.h | 22 | ||||
-rw-r--r-- | net/base/base64_unittest.cc | 29 | ||||
-rw-r--r-- | net/base/data_url.cc | 4 | ||||
-rw-r--r-- | net/base/net_util.cc | 4 | ||||
-rw-r--r-- | net/base/sdch_manager.cc | 4 | ||||
-rw-r--r-- | net/base/strict_transport_security_state.cc | 6 |
7 files changed, 9 insertions, 101 deletions
diff --git a/net/base/base64.cc b/net/base/base64.cc deleted file mode 100644 index ee5605e..0000000 --- a/net/base/base64.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2006-2008 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 "net/base/base64.h" - -#include "third_party/modp_b64/modp_b64.h" - -namespace net { - -bool Base64Encode(const std::string& input, std::string* output) { - std::string temp; - temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte - - // null terminates result since result is base64 text! - int input_size = static_cast<int>(input.size()); - int output_size= modp_b64_encode(&(temp[0]), input.data(), input_size); - if (output_size < 0) - return false; - - temp.resize(output_size); // strips off null byte - output->swap(temp); - return true; -} - -bool Base64Decode(const std::string& input, std::string* output) { - std::string temp; - temp.resize(modp_b64_decode_len(input.size())); - - // does not null terminate result since result is binary data! - int input_size = static_cast<int>(input.size()); - int output_size = modp_b64_decode(&(temp[0]), input.data(), input_size); - if (output_size < 0) - return false; - - temp.resize(output_size); - output->swap(temp); - return true; -} - -} // namespace net diff --git a/net/base/base64.h b/net/base/base64.h deleted file mode 100644 index b2e532a..0000000 --- a/net/base/base64.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2006-2008 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 NET_BASE_BASE64_H__ -#define NET_BASE_BASE64_H__ - -#include <string> - -namespace net { - -// Encodes the input string in base64. Returns true if successful and false -// otherwise. The output string is only modified if successful. -bool Base64Encode(const std::string& input, std::string* output); - -// Decodes the base64 input string. Returns true if successful and false -// otherwise. The output string is only modified if successful. -bool Base64Decode(const std::string& input, std::string* output); - -} // namespace net - -#endif // NET_BASE_BASE64_H__ diff --git a/net/base/base64_unittest.cc b/net/base/base64_unittest.cc deleted file mode 100644 index e2b55b2..0000000 --- a/net/base/base64_unittest.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2006-2008 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 "net/base/base64.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class Base64Test : public testing::Test { -}; - -} // namespace - -TEST(Base64Test, Basic) { - const std::string kText = "hello world"; - const std::string kBase64Text = "aGVsbG8gd29ybGQ="; - - std::string encoded, decoded; - bool ok; - - ok = net::Base64Encode(kText, &encoded); - EXPECT_TRUE(ok); - EXPECT_EQ(kBase64Text, encoded); - - ok = net::Base64Decode(encoded, &decoded); - EXPECT_TRUE(ok); - EXPECT_EQ(kText, decoded); -} diff --git a/net/base/data_url.cc b/net/base/data_url.cc index fb7de68..e30f7da 100644 --- a/net/base/data_url.cc +++ b/net/base/data_url.cc @@ -8,9 +8,9 @@ #include "net/base/data_url.h" +#include "base/base64.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" -#include "net/base/base64.h" #include "net/base/escape.h" namespace net { @@ -93,7 +93,7 @@ bool DataURL::Parse(const GURL& url, std::string* mime_type, } if (base64_encoded) - return Base64Decode(temp_data, data); + return base::Base64Decode(temp_data, data); temp_data.swap(*data); return true; diff --git a/net/base/net_util.cc b/net/base/net_util.cc index af090bd..2677abd 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -26,6 +26,7 @@ #include <fcntl.h> #endif +#include "base/base64.h" #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" @@ -54,7 +55,6 @@ #if defined(OS_WIN) #include "net/base/winsock_init.h" #endif -#include "net/base/base64.h" #include "unicode/datefmt.h" @@ -225,7 +225,7 @@ bool DecodeBQEncoding(const std::string& part, RFC2047EncodingType enc_type, const std::string& charset, std::string* output) { std::string decoded; if (enc_type == B_ENCODING) { - if (!net::Base64Decode(part, &decoded)) { + if (!base::Base64Decode(part, &decoded)) { return false; } } else { diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc index e617ea3..b30a171 100644 --- a/net/base/sdch_manager.cc +++ b/net/base/sdch_manager.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/base64.h" #include "base/field_trial.h" #include "base/histogram.h" #include "base/logging.h" #include "base/sha2.h" #include "base/string_util.h" -#include "net/base/base64.h" #include "net/base/registry_controlled_domain.h" #include "net/base/sdch_manager.h" #include "net/url_request/url_request_http_job.h" @@ -349,7 +349,7 @@ void SdchManager::UrlSafeBase64Encode(const std::string& input, std::string* output) { // Since this is only done during a dictionary load, and hashes are only 8 // characters, we just do the simple fixup, rather than rewriting the encoder. - net::Base64Encode(input, output); + base::Base64Encode(input, output); for (size_t i = 0; i < output->size(); ++i) { switch (output->data()[i]) { case '+': diff --git a/net/base/strict_transport_security_state.cc b/net/base/strict_transport_security_state.cc index 8318185..609241c 100644 --- a/net/base/strict_transport_security_state.cc +++ b/net/base/strict_transport_security_state.cc @@ -4,6 +4,7 @@ #include "net/base/strict_transport_security_state.h" +#include "base/base64.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/logging.h" @@ -13,7 +14,6 @@ #include "base/string_util.h" #include "base/values.h" #include "googleurl/src/gurl.h" -#include "net/base/base64.h" #include "net/base/dns_util.h" namespace net { @@ -198,7 +198,7 @@ void StrictTransportSecurityState::SetDelegate( // |enabled_hosts_|, to a base64 string which we can include in a JSON file. static std::wstring HashedDomainToExternalString(const std::string& hashed) { std::string out; - CHECK(Base64Encode(hashed, &out)); + CHECK(base::Base64Encode(hashed, &out)); return ASCIIToWide(out); } @@ -207,7 +207,7 @@ static std::wstring HashedDomainToExternalString(const std::string& hashed) { static std::string ExternalStringToHashedDomain(const std::wstring& external) { std::string external_ascii = WideToASCII(external); std::string out; - if (!Base64Decode(external_ascii, &out) || + if (!base::Base64Decode(external_ascii, &out) || out.size() != base::SHA256_LENGTH) { return std::string(); } |