[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 5 | #ifndef COMPONENTS_CRX_FILE_ID_UTIL_H_ |
6 | #define COMPONENTS_CRX_FILE_ID_UTIL_H_ | ||||
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 7 | |
David 'Digit' Turner | 2ccae250 | 2017-11-10 17:16:04 | [diff] [blame] | 8 | #include "base/strings/string_piece.h" |
9 | |||||
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 10 | #include <stddef.h> |
David 'Digit' Turner | 2ccae250 | 2017-11-10 17:16:04 | [diff] [blame] | 11 | #include <stdint.h> |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 12 | |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 13 | #include <string> |
14 | |||||
15 | namespace base { | ||||
16 | class FilePath; | ||||
17 | } | ||||
18 | |||||
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 19 | namespace crx_file { |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 20 | namespace id_util { |
21 | |||||
22 | // The number of bytes in a legal id. | ||||
23 | extern const size_t kIdSize; | ||||
24 | |||||
25 | // Generates an extension ID from arbitrary input. The same input string will | ||||
26 | // always generate the same output ID. | ||||
David 'Digit' Turner | 2ccae250 | 2017-11-10 17:16:04 | [diff] [blame] | 27 | std::string GenerateId(base::StringPiece input); |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 28 | |
xiaochu | 315bef2 | 2017-03-15 02:54:15 | [diff] [blame] | 29 | // Generates an ID from a HEX string. The same input string will always generate |
30 | // the same output ID. | ||||
31 | std::string GenerateIdFromHex(const std::string& input); | ||||
32 | |||||
David 'Digit' Turner | 2ccae250 | 2017-11-10 17:16:04 | [diff] [blame] | 33 | // Generates an ID from the first |kIdSize| bytes of a SHA256 hash. |
34 | // |hash_size| must be at least |kIdSize|. | ||||
35 | std::string GenerateIdFromHash(const uint8_t* hash, size_t hash_size); | ||||
36 | |||||
thestig | 83cbcc4 | 2015-01-29 18:50:32 | [diff] [blame] | 37 | // Generates an ID for an extension in the given path. |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 38 | // Used while developing extensions, before they have a key. |
39 | std::string GenerateIdForPath(const base::FilePath& path); | ||||
40 | |||||
thestig | 83cbcc4 | 2015-01-29 18:50:32 | [diff] [blame] | 41 | // Returns the hash of an extension ID in hex. |
42 | std::string HashedIdInHex(const std::string& id); | ||||
43 | |||||
44 | // Normalizes the path for use by the extension. On Windows, this will make | ||||
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 45 | // sure the drive letter is uppercase. |
46 | base::FilePath MaybeNormalizePath(const base::FilePath& path); | ||||
47 | |||||
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 48 | // Checks if |id| is a valid extension-id. Extension-ids are used for anything |
49 | // that comes in a CRX file, including apps, extensions, and components. | ||||
50 | bool IdIsValid(const std::string& id); | ||||
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 51 | |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 52 | } // namespace id_util |
53 | } // namespace crx_file | ||||
54 | |||||
55 | #endif // COMPONENTS_CRX_FILE_ID_UTIL_H_ |