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

Side by Side Diff: components/crx_file/id_util.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/crx_file/id_util.h" 5 #include "components/crx_file/id_util.h"
6 6
7 #include <stdint.h>
8
7 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
8 #include "base/sha1.h" 10 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "build/build_config.h"
11 #include "crypto/sha2.h" 14 #include "crypto/sha2.h"
12 15
13 namespace { 16 namespace {
14 17
15 // Converts a normal hexadecimal string into the alphabet used by extensions. 18 // Converts a normal hexadecimal string into the alphabet used by extensions.
16 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a 19 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a
17 // completely numeric host, since some software interprets that as an IP 20 // completely numeric host, since some software interprets that as an IP
18 // address. 21 // address.
19 static void ConvertHexadecimalToIDAlphabet(std::string* id) { 22 static void ConvertHexadecimalToIDAlphabet(std::string* id) {
20 for (size_t i = 0; i < id->size(); ++i) { 23 for (size_t i = 0; i < id->size(); ++i) {
21 int val; 24 int val;
22 if (base::HexStringToInt( 25 if (base::HexStringToInt(
23 base::StringPiece(id->begin() + i, id->begin() + i + 1), &val)) { 26 base::StringPiece(id->begin() + i, id->begin() + i + 1), &val)) {
24 (*id)[i] = val + 'a'; 27 (*id)[i] = val + 'a';
25 } else { 28 } else {
26 (*id)[i] = 'a'; 29 (*id)[i] = 'a';
27 } 30 }
28 } 31 }
29 } 32 }
30 33
31 } // namespace 34 } // namespace
32 35
33 namespace crx_file { 36 namespace crx_file {
34 namespace id_util { 37 namespace id_util {
35 38
36 // First 16 bytes of SHA256 hashed public key. 39 // First 16 bytes of SHA256 hashed public key.
37 const size_t kIdSize = 16; 40 const size_t kIdSize = 16;
38 41
39 std::string GenerateId(const std::string& input) { 42 std::string GenerateId(const std::string& input) {
40 uint8 hash[kIdSize]; 43 uint8_t hash[kIdSize];
41 crypto::SHA256HashString(input, hash, sizeof(hash)); 44 crypto::SHA256HashString(input, hash, sizeof(hash));
42 std::string output = 45 std::string output =
43 base::ToLowerASCII(base::HexEncode(hash, sizeof(hash))); 46 base::ToLowerASCII(base::HexEncode(hash, sizeof(hash)));
44 ConvertHexadecimalToIDAlphabet(&output); 47 ConvertHexadecimalToIDAlphabet(&output);
45 48
46 return output; 49 return output;
47 } 50 }
48 51
49 std::string GenerateIdForPath(const base::FilePath& path) { 52 std::string GenerateIdForPath(const base::FilePath& path) {
50 base::FilePath new_path = MaybeNormalizePath(path); 53 base::FilePath new_path = MaybeNormalizePath(path);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 std::string temp = base::ToLowerASCII(id); 89 std::string temp = base::ToLowerASCII(id);
87 for (size_t i = 0; i < temp.size(); i++) 90 for (size_t i = 0; i < temp.size(); i++)
88 if (temp[i] < 'a' || temp[i] > 'p') 91 if (temp[i] < 'a' || temp[i] > 'p')
89 return false; 92 return false;
90 93
91 return true; 94 return true;
92 } 95 }
93 96
94 } // namespace id_util 97 } // namespace id_util
95 } // namespace crx_file 98 } // namespace crx_file
OLDNEW
« 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