1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef CONTRIB_BROTLI_UTILS_UTILS_BROTLI_DEC_H_ 16 #define CONTRIB_BROTLI_UTILS_UTILS_BROTLI_DEC_H_ 17 18 #include <vector> 19 20 #include "absl/log/die_if_null.h" 21 #include "contrib/brotli/sandboxed.h" 22 #include "sandboxed_api/util/status_macros.h" 23 24 class BrotliDecoder { 25 public: BrotliDecoder(BrotliSandbox * sandbox)26 explicit BrotliDecoder(BrotliSandbox* sandbox) 27 : sandbox_(ABSL_DIE_IF_NULL(sandbox)), api_(sandbox_), state_(nullptr) { 28 status = InitStructs(); 29 } 30 ~BrotliDecoder(); 31 32 bool IsInit(); 33 34 absl::Status SetParameter(BrotliDecoderParameter param, uint32_t value); 35 absl::StatusOr<BrotliDecoderResult> Decompress(std::vector<uint8_t>& buf_in); 36 37 absl::StatusOr<std::vector<uint8_t>> TakeOutput(); 38 39 protected: 40 absl::Status InitStructs(); 41 absl::Status CheckIsInit(); 42 43 BrotliSandbox* sandbox_; 44 BrotliApi api_; 45 absl::Status status; 46 sapi::v::GenericPtr state_; 47 sapi::v::NullPtr null_ptr_; 48 }; 49 50 #endif // CONTRIB_BROTLI_UTILS_UTILS_BROTLI_DEC_H_ 51