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 |