blob: 05a58566b1c138ebdf6c865c2253debae7f9ea2b [file] [log] [blame]
Sen Jiang57f91802017-11-14 17:42:13 -08001//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_VERITY_WRITER_ANDROID_H_
18#define UPDATE_ENGINE_PAYLOAD_CONSUMER_VERITY_WRITER_ANDROID_H_
19
20#include <memory>
Sen Jianga778e5b2018-09-13 11:42:56 -070021#include <string>
Sen Jiang57f91802017-11-14 17:42:13 -080022
23#include <verity/hash_tree_builder.h>
24
25#include "update_engine/payload_consumer/verity_writer_interface.h"
26
27namespace chromeos_update_engine {
28
29class VerityWriterAndroid : public VerityWriterInterface {
30 public:
31 VerityWriterAndroid() = default;
32 ~VerityWriterAndroid() override = default;
33
34 bool Init(const InstallPlan::Partition& partition) override;
35 bool Update(uint64_t offset, const uint8_t* buffer, size_t size) override;
36
Sen Jianga778e5b2018-09-13 11:42:56 -070037 // Read [data_offset : data_offset + data_size) from |path| and encode FEC
38 // data, if |verify_mode|, then compare the encoded FEC with the one in
39 // |path|, otherwise write the encoded FEC to |path|. We can't encode as we go
40 // in each Update() like hash tree, because for every rs block, its data are
41 // spreaded across entire |data_size|, unless we can cache all data in
42 // memory, we have to re-read them from disk.
43 static bool EncodeFEC(const std::string& path,
44 uint64_t data_offset,
45 uint64_t data_size,
46 uint64_t fec_offset,
47 uint64_t fec_size,
48 uint32_t fec_roots,
49 uint32_t block_size,
50 bool verify_mode);
51
Sen Jiang57f91802017-11-14 17:42:13 -080052 private:
53 const InstallPlan::Partition* partition_ = nullptr;
54
55 std::unique_ptr<HashTreeBuilder> hash_tree_builder_;
56
57 DISALLOW_COPY_AND_ASSIGN(VerityWriterAndroid);
58};
59
60} // namespace chromeos_update_engine
61
62#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_VERITY_WRITER_ANDROID_H_