id_util.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_CRX_FILE_ID_UTIL_H_
  5. #define COMPONENTS_CRX_FILE_ID_UTIL_H_
  6. #include "base/strings/string_piece.h"
  7. #include <stddef.h>
  8. #include <stdint.h>
  9. #include <string>
  10. namespace base {
  11. class FilePath;
  12. }
  13. namespace crx_file {
  14. namespace id_util {
  15. // The number of bytes in a legal id.
  16. extern const size_t kIdSize;
  17. // Generates an extension ID from arbitrary input. The same input string will
  18. // always generate the same output ID.
  19. std::string GenerateId(base::StringPiece input);
  20. // Generates an ID from a HEX string. The same input string will always generate
  21. // the same output ID.
  22. std::string GenerateIdFromHex(const std::string& input);
  23. // Generates an ID from the first |kIdSize| bytes of a SHA256 hash.
  24. // |hash_size| must be at least |kIdSize|.
  25. std::string GenerateIdFromHash(const uint8_t* hash, size_t hash_size);
  26. // Generates an ID for an extension in the given path.
  27. // Used while developing extensions, before they have a key.
  28. std::string GenerateIdForPath(const base::FilePath& path);
  29. // Returns the hash of an extension ID in hex.
  30. std::string HashedIdInHex(const std::string& id);
  31. // Normalizes the path for use by the extension. On Windows, this will make
  32. // sure the drive letter is uppercase.
  33. base::FilePath MaybeNormalizePath(const base::FilePath& path);
  34. // Checks if |id| is a valid extension-id. Extension-ids are used for anything
  35. // that comes in a CRX file, including apps, extensions, and components.
  36. bool IdIsValid(const std::string& id);
  37. } // namespace id_util
  38. } // namespace crx_file
  39. #endif // COMPONENTS_CRX_FILE_ID_UTIL_H_