lsquic_crt_compress.h revision fbc6cc04
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2#ifndef __LSQUIC_CRT_COMPRESS_H__
3#define __LSQUIC_CRT_COMPRESS_H__
4
5#include <stdint.h>
6
7struct lsquic_str;
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13
14enum entry_type {
15    END_OF_LIST = 0,
16    ENTRY_COMPRESSED = 1,
17    ENTRY_CACHED = 2,
18    ENTRY_COMMON = 3,
19};
20
21typedef struct cert_entry_st {
22    enum entry_type type;
23    uint32_t index;
24    uint64_t hash;
25    uint64_t set_hash;
26} cert_entry_t;
27
28
29typedef struct common_cert_st
30{
31    size_t num_certs;
32    const unsigned char* const* certs;
33    const size_t* lens;
34    uint64_t hash;
35} common_cert_t;
36
37int
38lsquic_crt_init (void);
39
40struct lsquic_str * lsquic_get_common_certs_hash();
41
42
43int lsquic_get_common_cert(uint64_t hash, uint32_t index, struct lsquic_str *buf);
44
45struct compressed_cert
46{
47    size_t          len;
48    unsigned        refcnt;
49    unsigned char   buf[0]; /* len bytes */
50};
51
52/* Returns newly allocated structure or NULL on error */
53struct compressed_cert *
54lsquic_compress_certs(struct lsquic_str **certs, size_t certs_count,
55                   struct lsquic_str *client_common_set_hashes,
56                   struct lsquic_str *client_cached_cert_hashes);
57
58int
59lsquic_get_certs_count (const struct compressed_cert *);
60
61int lsquic_decompress_certs(const unsigned char *in, const unsigned char *in_end,
62                     struct lsquic_str *cached_certs, size_t cached_certs_count,
63                     struct lsquic_str **out_certs,
64                     size_t *out_certs_count);
65
66void
67lsquic_crt_cleanup (void);
68
69
70#ifdef __cplusplus
71}
72#endif
73
74
75#endif //__LSQUIC_CRT_COMPRESS_H__
76