proxygen
ZlibCertificateDecompressor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
10 
11 using namespace folly;
12 
13 namespace fizz {
14 
15 CertificateCompressionAlgorithm ZlibCertificateDecompressor::getAlgorithm()
16  const {
17  return CertificateCompressionAlgorithm::zlib;
18 }
19 
20 CertificateMsg ZlibCertificateDecompressor::decompress(
21  const CompressedCertificate& cc) {
22  if (cc.algorithm != getAlgorithm()) {
23  throw std::runtime_error(
24  "Compressed certificate uses non-zlib algorithm: " +
25  toString(cc.algorithm));
26  }
27 
29  throw std::runtime_error(
30  "Compressed certificate exceeds maximum certificate message size");
31  }
32 
33  auto rawCertMessage = IOBuf::create(cc.uncompressed_length);
34  unsigned long size = cc.uncompressed_length;
35  auto compRange = cc.compressed_certificate_message->coalesce();
36  auto status = ::uncompress(
37  rawCertMessage->writableData(),
38  &size,
39  compRange.data(),
40  compRange.size());
41  switch (status) {
42  case Z_OK:
43  if (size != cc.uncompressed_length) {
44  throw std::runtime_error("Uncompressed length incorrect");
45  }
46  break;
47  case Z_MEM_ERROR:
48  throw std::runtime_error("Insufficient memory to decompress cert");
49  case Z_BUF_ERROR:
50  throw std::runtime_error(
51  "The uncompressed length given is too small to hold uncompressed data");
52  case Z_DATA_ERROR:
53  throw std::runtime_error(
54  "The compressed certificate data was incomplete or invalid");
55  default:
56  throw std::runtime_error(
57  "Failed to decompress: " + to<std::string>(status));
58  }
59  rawCertMessage->append(size);
60  return decode<CertificateMsg>(std::move(rawCertMessage));
61 }
62 
63 } // namespace fizz
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
CertificateCompressionAlgorithm algorithm
Definition: Types.h:245
CertificateCompressionAlgorithm
Definition: Types.h:167
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
uint32_t uncompressed_length
Definition: Types.h:246
The non test part of the code is expected to have failures gtest_output_test_ cc
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
constexpr size_t kMaxHandshakeSize
Definition: Types.h:78
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
Definition: Actions.h:16