proxygen
fizz::ZlibCertificateDecompressor Class Reference

#include <ZlibCertificateDecompressor.h>

Inheritance diagram for fizz::ZlibCertificateDecompressor:
fizz::CertificateDecompressor

Public Member Functions

 ~ZlibCertificateDecompressor () override=default
 
CertificateCompressionAlgorithm getAlgorithm () const override
 
CertificateMsg decompress (const CompressedCertificate &) override
 
- Public Member Functions inherited from fizz::CertificateDecompressor
virtual ~CertificateDecompressor ()=default
 

Detailed Description

Definition at line 15 of file ZlibCertificateDecompressor.h.

Constructor & Destructor Documentation

fizz::ZlibCertificateDecompressor::~ZlibCertificateDecompressor ( )
overridedefault

Member Function Documentation

CertificateMsg fizz::ZlibCertificateDecompressor::decompress ( const CompressedCertificate cc)
overridevirtual

Implements fizz::CertificateDecompressor.

Definition at line 20 of file ZlibCertificateDecompressor.cpp.

References fizz::CompressedCertificate::algorithm, fizz::CompressedCertificate::compressed_certificate_message, folly::IOBuf::create(), fizz::kMaxHandshakeSize, folly::gen::move, folly::size(), fizz::toString(), and fizz::CompressedCertificate::uncompressed_length.

21  {
22  if (cc.algorithm != getAlgorithm()) {
23  throw std::runtime_error(
24  "Compressed certificate uses non-zlib algorithm: " +
25  toString(cc.algorithm));
26  }
27 
28  if (cc.uncompressed_length > kMaxHandshakeSize) {
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 }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CertificateCompressionAlgorithm getAlgorithm() const override
The non test part of the code is expected to have failures gtest_output_test_ cc
constexpr size_t kMaxHandshakeSize
Definition: Types.h:78
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
CertificateCompressionAlgorithm fizz::ZlibCertificateDecompressor::getAlgorithm ( ) const
overridevirtual

The documentation for this class was generated from the following files: