OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "extensions/common/id_util.h" | 5 #include "extensions/common/id_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "crypto/sha2.h" | 10 #include "crypto/sha2.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 namespace extensions { | 33 namespace extensions { |
34 namespace id_util { | 34 namespace id_util { |
35 | 35 |
36 // First 16 bytes of SHA256 hashed public key. | 36 // First 16 bytes of SHA256 hashed public key. |
37 const size_t kIdSize = 16; | 37 const size_t kIdSize = 16; |
38 | 38 |
39 std::string GenerateId(const std::string& input) { | 39 std::string GenerateId(const std::string& input) { |
40 uint8 hash[kIdSize]; | 40 uint8 hash[kIdSize]; |
41 crypto::SHA256HashString(input, hash, sizeof(hash)); | 41 crypto::SHA256HashString(input, hash, sizeof(hash)); |
42 std::string output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); | 42 std::string output = |
| 43 base::StringToLowerASCII(base::HexEncode(hash, sizeof(hash))); |
43 ConvertHexadecimalToIDAlphabet(&output); | 44 ConvertHexadecimalToIDAlphabet(&output); |
44 | 45 |
45 return output; | 46 return output; |
46 } | 47 } |
47 | 48 |
48 std::string GenerateIdForPath(const base::FilePath& path) { | 49 std::string GenerateIdForPath(const base::FilePath& path) { |
49 base::FilePath new_path = MaybeNormalizePath(path); | 50 base::FilePath new_path = MaybeNormalizePath(path); |
50 std::string path_bytes = | 51 std::string path_bytes = |
51 std::string(reinterpret_cast<const char*>(new_path.value().data()), | 52 std::string(reinterpret_cast<const char*>(new_path.value().data()), |
52 new_path.value().size() * sizeof(base::FilePath::CharType)); | 53 new_path.value().size() * sizeof(base::FilePath::CharType)); |
(...skipping 11 matching lines...) Expand all Loading... |
64 path_str[0] = towupper(path_str[0]); | 65 path_str[0] = towupper(path_str[0]); |
65 | 66 |
66 return base::FilePath(path_str); | 67 return base::FilePath(path_str); |
67 #else | 68 #else |
68 return path; | 69 return path; |
69 #endif | 70 #endif |
70 } | 71 } |
71 | 72 |
72 } // namespace id_util | 73 } // namespace id_util |
73 } // namespace extensions | 74 } // namespace extensions |
OLD | NEW |