xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/crypto/cert_compressor.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_
6 #define QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "absl/strings/string_view.h"
12 #include "quiche/quic/core/crypto/crypto_protocol.h"
13 #include "quiche/quic/platform/api/quic_export.h"
14 
15 namespace quic {
16 
17 // CertCompressor provides functions for compressing and decompressing
18 // certificate chains using two techniquies:
19 //   1) The peer may provide a list of a 64-bit, FNV-1a hashes of certificates
20 //      that they already have. In the event that one of them is to be
21 //      compressed, it can be replaced with just the hash.
22 //   2) Otherwise the certificates are compressed with zlib using a pre-shared
23 //      dictionary that consists of the certificates handled with the above
24 //      methods and a small chunk of common substrings.
25 class QUICHE_EXPORT CertCompressor {
26  public:
27   CertCompressor() = delete;
28 
29   // CompressChain compresses the certificates in |certs| and returns a
30   // compressed representation. client_cached_cert_hashes| contains
31   // 64-bit, FNV-1a hashes of certificates that the peer already possesses.
32   static std::string CompressChain(const std::vector<std::string>& certs,
33                                    absl::string_view client_cached_cert_hashes);
34 
35   // DecompressChain decompresses the result of |CompressChain|, given in |in|,
36   // into a series of certificates that are written to |out_certs|.
37   // |cached_certs| contains certificates that the peer may have omitted.
38   static bool DecompressChain(absl::string_view in,
39                               const std::vector<std::string>& cached_certs,
40                               std::vector<std::string>* out_certs);
41 };
42 
43 }  // namespace quic
44 
45 #endif  // QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_
46