proxygen
ZlibCertificateCompressor.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 ZlibCertificateCompressor::ZlibCertificateCompressor(int compressLevel)
16  : level_(compressLevel) {
17  if (compressLevel != Z_DEFAULT_COMPRESSION &&
18  !(compressLevel >= Z_NO_COMPRESSION &&
19  compressLevel <= Z_BEST_COMPRESSION)) {
20  throw std::runtime_error(
21  "Invalid compression level requested:" +
22  to<std::string>(compressLevel));
23  }
24 }
25 
27  const {
29 }
30 
32  const CertificateMsg& cert) {
33  auto encoded = encode(cert);
34  auto certRange = encoded->coalesce();
35  auto compressedCert = IOBuf::create(compressBound(certRange.size()));
36  unsigned long size = compressedCert->capacity();
37 
38  int status = ::compress2(
39  compressedCert->writableData(),
40  &size,
41  certRange.data(),
42  certRange.size(),
43  level_);
44  switch (status) {
45  case Z_OK:
46  compressedCert->append(size);
47  break;
48  case Z_MEM_ERROR:
49  throw std::runtime_error("Insufficient memory to compress cert");
50  case Z_BUF_ERROR:
51  throw std::runtime_error("Buffer too small for compressed cert");
52  case Z_STREAM_ERROR:
53  throw std::runtime_error(
54  "Compression level invalid: " + to<std::string>(level_));
55  default:
56  throw std::runtime_error(
57  "Failed to compress: " + to<std::string>(status));
58  }
59 
61  cc.uncompressed_length = certRange.size();
62  cc.algorithm = getAlgorithm();
63  cc.compressed_certificate_message = std::move(compressedCert);
64  return cc;
65 }
66 
67 } // namespace fizz
CertificateCompressionAlgorithm algorithm
Definition: Types.h:245
CertificateCompressionAlgorithm
Definition: Types.h:167
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
CertificateCompressionAlgorithm getAlgorithm() const override
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
CompressedCertificate compress(const CertificateMsg &) override
Definition: Actions.h:16
Buf encode(TokenBindingMessage &&message)
Definition: Types.cpp:124