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.
5 #ifndef EXTENSIONS_BROWSER_COMPUTED_HASHES_H_
6 #define EXTENSIONS_BROWSER_COMPUTED_HASHES_H_
12 #include "base/memory/scoped_ptr.h"
19 namespace extensions
{
21 // A pair of classes for serialization of a set of SHA256 block hashes computed
22 // over the files inside an extension.
23 class ComputedHashes
{
29 bool InitFromFile(const base::FilePath
& path
);
31 // The block size and hashes for |relative_path| will be copied into the
33 bool GetHashes(const base::FilePath
& relative_path
,
35 std::vector
<std::string
>* hashes
);
38 typedef std::pair
<int, std::vector
<std::string
> > HashInfo
;
40 // This maps a relative path to a pair of (block size, hashes)
41 std::map
<base::FilePath
, HashInfo
> data_
;
49 // Adds hashes for |relative_path|. Should not be called more than once
50 // for a given |relative_path|.
51 void AddHashes(const base::FilePath
& relative_path
,
53 const std::vector
<std::string
>& hashes
);
55 bool WriteToFile(const base::FilePath
& path
);
58 // Each element of this list contains the path and block hashes for one
60 scoped_ptr
<base::ListValue
> file_list_
;
63 // Computes the SHA256 hash of each |block_size| chunk in |contents|, placing
64 // the results into |hashes|.
65 static void ComputeHashesForContent(const std::string
& contents
,
67 std::vector
<std::string
>* hashes
);
70 } // namespace extensions
72 #endif // EXTENSIONS_BROWSER_COMPUTED_HASHES_H_