A bunch of remaining parts of extension content verification
[chromium-blink-merge.git] / extensions / browser / computed_hashes.h
blobc68175c8d2c832107335eb4d8abd60266b23540f
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_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/values.h"
14 namespace base {
15 class FilePath;
18 namespace extensions {
20 // A pair of classes for serialization of a set of SHA256 block hashes computed
21 // over the files inside an extension.
22 class ComputedHashes {
23 public:
24 class Reader {
25 public:
26 Reader();
27 ~Reader();
28 bool InitFromFile(const base::FilePath& path);
30 // The block size and hashes for |relative_path| will be copied into the
31 // out parameters.
32 bool GetHashes(const base::FilePath& relative_path,
33 int* block_size,
34 std::vector<std::string>* hashes);
36 private:
37 typedef std::pair<int, std::vector<std::string> > HashInfo;
39 // This maps a relative path to a pair of (block size, hashes)
40 std::map<base::FilePath, HashInfo> data_;
43 class Writer {
44 public:
45 Writer();
46 ~Writer();
48 // Adds hashes for |relative_path|. Should not be called more than once
49 // for a given |relative_path|.
50 void AddHashes(const base::FilePath& relative_path,
51 int block_size,
52 const std::vector<std::string>& hashes);
54 bool WriteToFile(const base::FilePath& path);
56 private:
57 // The top-level object that will be serialized as JSON.
58 base::ListValue file_list_;
62 } // namespace extensions
64 #endif // EXTENSIONS_BROWSER_COMPUTED_HASHES_H_