blob: 63705600eb87c98fb8753d5c4ffd2205552515dc [file] [log] [blame]
[email protected]fdd28372014-08-21 02:27:261// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]993da5e2013-03-23 21:25:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]fdd28372014-08-21 02:27:265#ifndef COMPONENTS_CRX_FILE_ID_UTIL_H_
6#define COMPONENTS_CRX_FILE_ID_UTIL_H_
[email protected]993da5e2013-03-23 21:25:167
David 'Digit' Turner2ccae2502017-11-10 17:16:048#include "base/strings/string_piece.h"
9
avibc5337b2015-12-25 23:16:3310#include <stddef.h>
David 'Digit' Turner2ccae2502017-11-10 17:16:0411#include <stdint.h>
avibc5337b2015-12-25 23:16:3312
[email protected]993da5e2013-03-23 21:25:1613#include <string>
14
15namespace base {
16class FilePath;
17}
18
[email protected]fdd28372014-08-21 02:27:2619namespace crx_file {
[email protected]993da5e2013-03-23 21:25:1620namespace id_util {
21
22// The number of bytes in a legal id.
23extern 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' Turner2ccae2502017-11-10 17:16:0427std::string GenerateId(base::StringPiece input);
[email protected]993da5e2013-03-23 21:25:1628
xiaochu315bef22017-03-15 02:54:1529// Generates an ID from a HEX string. The same input string will always generate
30// the same output ID.
31std::string GenerateIdFromHex(const std::string& input);
32
David 'Digit' Turner2ccae2502017-11-10 17:16:0433// Generates an ID from the first |kIdSize| bytes of a SHA256 hash.
34// |hash_size| must be at least |kIdSize|.
35std::string GenerateIdFromHash(const uint8_t* hash, size_t hash_size);
36
thestig83cbcc42015-01-29 18:50:3237// Generates an ID for an extension in the given path.
[email protected]993da5e2013-03-23 21:25:1638// Used while developing extensions, before they have a key.
39std::string GenerateIdForPath(const base::FilePath& path);
40
thestig83cbcc42015-01-29 18:50:3241// Returns the hash of an extension ID in hex.
42std::string HashedIdInHex(const std::string& id);
43
44// Normalizes the path for use by the extension. On Windows, this will make
[email protected]993da5e2013-03-23 21:25:1645// sure the drive letter is uppercase.
46base::FilePath MaybeNormalizePath(const base::FilePath& path);
47
[email protected]fdd28372014-08-21 02:27:2648// 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.
50bool IdIsValid(const std::string& id);
[email protected]993da5e2013-03-23 21:25:1651
[email protected]fdd28372014-08-21 02:27:2652} // namespace id_util
53} // namespace crx_file
54
55#endif // COMPONENTS_CRX_FILE_ID_UTIL_H_