1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_CRX_FILE_ID_UTIL_H_
6 #define COMPONENTS_CRX_FILE_ID_UTIL_H_
8 #include "base/strings/string_piece.h"
19 namespace crx_file::id_util {
21 // The number of bytes in a legal id.
22 extern const size_t kIdSize;
24 // Generates an extension ID from arbitrary input. The same input string will
25 // always generate the same output ID.
26 std::string GenerateId(base::StringPiece input);
28 // Generates an ID from a HEX string. The same input string will always generate
29 // the same output ID.
30 std::string GenerateIdFromHex(const std::string& input);
32 // Generates an ID from the first |kIdSize| bytes of a SHA256 hash.
33 // |hash_size| must be at least |kIdSize|.
34 std::string GenerateIdFromHash(const uint8_t* hash, size_t hash_size);
36 // Generates an ID for an extension in the given path.
37 // Used while developing extensions, before they have a key.
38 std::string GenerateIdForPath(const base::FilePath& path);
40 // Returns the hash of an extension ID in hex.
41 std::string HashedIdInHex(const std::string& id);
43 // Normalizes the path for use by the extension. On Windows, this will make
44 // sure the drive letter is uppercase.
45 base::FilePath MaybeNormalizePath(const base::FilePath& path);
47 // Checks if |id| is a valid extension-id. Extension-ids are used for anything
48 // that comes in a CRX file, including apps, extensions, and components.
49 bool IdIsValid(base::StringPiece id);
51 } // namespace crx_file::id_util
53 #endif // COMPONENTS_CRX_FILE_ID_UTIL_H_