Home | History | Annotate | Download | only in applypatch
      1 /*
      2  * Copyright (C) 2008 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 _APPLYPATCH_H
     18 #define _APPLYPATCH_H
     19 
     20 #include <stdint.h>
     21 
     22 #include <functional>
     23 #include <memory>
     24 #include <string>
     25 #include <vector>
     26 
     27 #include <openssl/sha.h>
     28 
     29 // Forward declaration to avoid including "edify/expr.h" in the header.
     30 struct Value;
     31 
     32 struct FileContents {
     33   uint8_t sha1[SHA_DIGEST_LENGTH];
     34   std::vector<unsigned char> data;
     35 };
     36 
     37 using SinkFn = std::function<size_t(const unsigned char*, size_t)>;
     38 
     39 // applypatch.cpp
     40 
     41 int ShowLicenses();
     42 size_t FreeSpaceForFile(const char* filename);
     43 int CacheSizeCheck(size_t bytes);
     44 int ParseSha1(const char* str, uint8_t* digest);
     45 
     46 int applypatch(const char* source_filename,
     47                const char* target_filename,
     48                const char* target_sha1_str,
     49                size_t target_size,
     50                const std::vector<std::string>& patch_sha1_str,
     51                const std::vector<std::unique_ptr<Value>>& patch_data,
     52                const Value* bonus_data);
     53 int applypatch_check(const char* filename,
     54                      const std::vector<std::string>& patch_sha1_str);
     55 int applypatch_flash(const char* source_filename, const char* target_filename,
     56                      const char* target_sha1_str, size_t target_size);
     57 
     58 int LoadFileContents(const char* filename, FileContents* file);
     59 int SaveFileContents(const char* filename, const FileContents* file);
     60 
     61 // bspatch.cpp
     62 
     63 void ShowBSDiffLicense();
     64 
     65 // Applies the bsdiff-patch given in 'patch' (from offset 'patch_offset' to the end) to the source
     66 // data given by (old_data, old_size). Writes the patched output through the given 'sink', and
     67 // updates the SHA-1 context with the output data. Returns 0 on success.
     68 int ApplyBSDiffPatch(const unsigned char* old_data, size_t old_size, const Value& patch,
     69                      size_t patch_offset, SinkFn sink, SHA_CTX* ctx);
     70 
     71 // imgpatch.cpp
     72 
     73 // Applies the imgdiff-patch given in 'patch' to the source data given by (old_data, old_size), with
     74 // the optional bonus data. Writes the patched output through the given 'sink', and updates the
     75 // SHA-1 context with the output data. Returns 0 on success.
     76 int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value& patch, SinkFn sink,
     77                     SHA_CTX* ctx, const Value* bonus_data);
     78 
     79 // freecache.cpp
     80 
     81 int MakeFreeSpaceOnCache(size_t bytes_needed);
     82 
     83 #endif
     84