lsquic_crt_compress.h revision 7d09751d
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#ifndef __LSQUIC_CRT_COMPRESS_H__
350aadb33SDmitri Tikhonov#define __LSQUIC_CRT_COMPRESS_H__
450aadb33SDmitri Tikhonov
550aadb33SDmitri Tikhonov#include <stdint.h>
650aadb33SDmitri Tikhonov
750aadb33SDmitri Tikhonovstruct lsquic_str;
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#ifdef __cplusplus
1050aadb33SDmitri Tikhonovextern "C" {
1150aadb33SDmitri Tikhonov#endif
1250aadb33SDmitri Tikhonov
135392f7a3SLiteSpeed Tech
1450aadb33SDmitri Tikhonovenum entry_type {
1550aadb33SDmitri Tikhonov    END_OF_LIST = 0,
1650aadb33SDmitri Tikhonov    ENTRY_COMPRESSED = 1,
1750aadb33SDmitri Tikhonov    ENTRY_CACHED = 2,
1850aadb33SDmitri Tikhonov    ENTRY_COMMON = 3,
1950aadb33SDmitri Tikhonov};
2050aadb33SDmitri Tikhonov
2150aadb33SDmitri Tikhonovtypedef struct cert_entry_st {
2250aadb33SDmitri Tikhonov    enum entry_type type;
2350aadb33SDmitri Tikhonov    uint32_t index;
2450aadb33SDmitri Tikhonov    uint64_t hash;
2550aadb33SDmitri Tikhonov    uint64_t set_hash;
2650aadb33SDmitri Tikhonov} cert_entry_t;
2750aadb33SDmitri Tikhonov
285392f7a3SLiteSpeed Tech
2950aadb33SDmitri Tikhonovtypedef struct common_cert_st
3050aadb33SDmitri Tikhonov{
3150aadb33SDmitri Tikhonov    size_t num_certs;
3250aadb33SDmitri Tikhonov    const unsigned char* const* certs;
3350aadb33SDmitri Tikhonov    const size_t* lens;
3450aadb33SDmitri Tikhonov    uint64_t hash;
3550aadb33SDmitri Tikhonov} common_cert_t;
3650aadb33SDmitri Tikhonov
3750aadb33SDmitri Tikhonovstruct lsquic_str * get_common_certs_hash();
3850aadb33SDmitri Tikhonov
395392f7a3SLiteSpeed Tech
405392f7a3SLiteSpeed Techint get_common_cert(uint64_t hash, uint32_t index, struct lsquic_str *buf);
415392f7a3SLiteSpeed Techint match_common_cert(struct lsquic_str * cert, struct lsquic_str * common_set_hashes,
425392f7a3SLiteSpeed Tech                      uint64_t* out_hash, uint32_t* out_index);
435392f7a3SLiteSpeed Tech
445392f7a3SLiteSpeed Techint compress_certs(struct lsquic_str **certs, size_t certs_count,
455392f7a3SLiteSpeed Tech                   struct lsquic_str *client_common_set_hashes,
465392f7a3SLiteSpeed Tech                   struct lsquic_str *client_cached_cert_hashes,
475392f7a3SLiteSpeed Tech                   struct lsquic_str *result);
485392f7a3SLiteSpeed Tech
4950aadb33SDmitri Tikhonovint get_certs_count(struct lsquic_str *compressed_crt_buf);
5050aadb33SDmitri Tikhonovint decompress_certs(const unsigned char *in, const unsigned char *in_end,
5150aadb33SDmitri Tikhonov                     struct lsquic_str *cached_certs, size_t cached_certs_count,
5250aadb33SDmitri Tikhonov                     struct lsquic_str **out_certs,
5350aadb33SDmitri Tikhonov                     size_t *out_certs_count);
5450aadb33SDmitri Tikhonov
5550aadb33SDmitri Tikhonovvoid
5650aadb33SDmitri Tikhonovlsquic_crt_cleanup (void);
5750aadb33SDmitri Tikhonov
585392f7a3SLiteSpeed Tech
5950aadb33SDmitri Tikhonov#ifdef __cplusplus
6050aadb33SDmitri Tikhonov}
6150aadb33SDmitri Tikhonov#endif
6250aadb33SDmitri Tikhonov
635392f7a3SLiteSpeed Tech
6450aadb33SDmitri Tikhonov#endif //__LSQUIC_CRT_COMPRESS_H__
65