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

Unified Diff: components/crx_file/id_util.cc

Issue 481433005: Extensions: Move id_util functions to crx_file component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert last patchset. function returns Extension* and can't use an assert. Created 6 years, 4 months 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 | « components/crx_file/id_util.h ('k') | components/crx_file/id_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/crx_file/id_util.cc
diff --git a/extensions/common/id_util.cc b/components/crx_file/id_util.cc
similarity index 76%
rename from extensions/common/id_util.cc
rename to components/crx_file/id_util.cc
index c59351c0cebc083acbef8e33f30d5d5b84bb7786..3d3b33928dabc66aade12fbef8be2e938f133698 100644
--- a/extensions/common/id_util.cc
+++ b/components/crx_file/id_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "extensions/common/id_util.h"
+#include "components/crx_file/id_util.h"
#include "base/files/file_path.h"
#include "base/strings/string_number_conversions.h"
@@ -18,9 +18,8 @@ namespace {
static void ConvertHexadecimalToIDAlphabet(std::string* id) {
for (size_t i = 0; i < id->size(); ++i) {
int val;
- if (base::HexStringToInt(base::StringPiece(id->begin() + i,
- id->begin() + i + 1),
- &val)) {
+ if (base::HexStringToInt(
+ base::StringPiece(id->begin() + i, id->begin() + i + 1), &val)) {
(*id)[i] = val + 'a';
} else {
(*id)[i] = 'a';
@@ -30,7 +29,7 @@ static void ConvertHexadecimalToIDAlphabet(std::string* id) {
} // namespace
-namespace extensions {
+namespace crx_file {
namespace id_util {
// First 16 bytes of SHA256 hashed public key.
@@ -70,5 +69,20 @@ base::FilePath MaybeNormalizePath(const base::FilePath& path) {
#endif
}
+bool IdIsValid(const std::string& id) {
+ // Verify that the id is legal.
+ if (id.size() != (crx_file::id_util::kIdSize * 2))
+ return false;
+
+ // We only support lowercase IDs, because IDs can be used as URL components
+ // (where GURL will lowercase it).
+ std::string temp = base::StringToLowerASCII(id);
+ for (size_t i = 0; i < temp.size(); i++)
+ if (temp[i] < 'a' || temp[i] > 'p')
+ return false;
+
+ return true;
+}
+
} // namespace id_util
-} // namespace extensions
+} // namespace crx_file
« no previous file with comments | « components/crx_file/id_util.h ('k') | components/crx_file/id_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698