index_hash.h revision 215187
1317027Sdim/**
2317027Sdim * \file        lzma/index_hash.h
3353358Sdim * \brief       Validate Index by using a hash function
4353358Sdim *
5353358Sdim * Hashing makes it possible to use constant amount of memory to validate
6317027Sdim * Index of arbitrary size.
7317027Sdim */
8317027Sdim
9317027Sdim/*
10317027Sdim * Author: Lasse Collin
11317027Sdim *
12317027Sdim * This file has been put into the public domain.
13344779Sdim * You can do whatever you want with this file.
14344779Sdim *
15317027Sdim * See ../lzma.h for information about liblzma as a whole.
16344779Sdim */
17360784Sdim
18317027Sdim#ifndef LZMA_H_INTERNAL
19321238Sdim#	error Never include this file directly. Use <lzma.h> instead.
20317027Sdim#endif
21317027Sdim
22317027Sdim/**
23317027Sdim * \brief       Opaque data type to hold the Index hash
24317027Sdim */
25317027Sdimtypedef struct lzma_index_hash_s lzma_index_hash;
26317027Sdim
27317027Sdim
28317027Sdim/**
29317027Sdim * \brief       Allocate and initialize a new lzma_index_hash structure
30317027Sdim *
31317027Sdim * If index_hash is NULL, a new lzma_index_hash structure is allocated,
32317027Sdim * initialized, and a pointer to it returned. If allocation fails, NULL
33317027Sdim * is returned.
34353358Sdim *
35341825Sdim * If index_hash is non-NULL, it is reinitialized and the same pointer
36317027Sdim * returned. In this case, return value cannot be NULL or a different
37341825Sdim * pointer than the index_hash that was given as an argument.
38341825Sdim */
39341825Sdimextern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
40341825Sdim		lzma_index_hash *index_hash, lzma_allocator *allocator)
41341825Sdim		lzma_nothrow lzma_attr_warn_unused_result;
42341825Sdim
43341825Sdim
44317027Sdim/**
45353358Sdim * \brief       Deallocate lzma_index_hash structure
46317027Sdim */
47317027Sdimextern LZMA_API(void) lzma_index_hash_end(
48353358Sdim		lzma_index_hash *index_hash, lzma_allocator *allocator)
49341825Sdim		lzma_nothrow;
50353358Sdim
51317027Sdim
52317027Sdim/**
53317027Sdim * \brief       Add a new Record to an Index hash
54317027Sdim *
55317027Sdim * \param       index             Pointer to a lzma_index_hash structure
56317027Sdim * \param       unpadded_size     Unpadded Size of a Block
57317027Sdim * \param       uncompressed_size Uncompressed Size of a Block
58317027Sdim *
59353358Sdim * \return      - LZMA_OK
60317027Sdim *              - LZMA_DATA_ERROR: Compressed or uncompressed size of the
61317027Sdim *                Stream or size of the Index field would grow too big.
62317027Sdim *              - LZMA_PROG_ERROR: Invalid arguments or this function is being
63317027Sdim *                used when lzma_index_hash_decode() has already been used.
64317027Sdim */
65317027Sdimextern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
66317027Sdim		lzma_vli unpadded_size, lzma_vli uncompressed_size)
67317027Sdim		lzma_nothrow lzma_attr_warn_unused_result;
68341825Sdim
69341825Sdim
70317027Sdim/**
71353358Sdim * \brief       Decode and validate the Index field
72317027Sdim *
73317027Sdim * After telling the sizes of all Blocks with lzma_index_hash_append(),
74353358Sdim * the actual Index field is decoded with this function. Specifically,
75317027Sdim * once decoding of the Index field has been started, no more Records
76317027Sdim * can be added using lzma_index_hash_append().
77353358Sdim *
78317027Sdim * This function doesn't use lzma_stream structure to pass the input data.
79317027Sdim * Instead, the input buffer is specified using three arguments. This is
80353358Sdim * because it matches better the internal APIs of liblzma.
81317027Sdim *
82317027Sdim * \param       index_hash      Pointer to a lzma_index_hash structure
83353358Sdim * \param       in              Pointer to the beginning of the input buffer
84317027Sdim * \param       in_pos          in[*in_pos] is the next byte to process
85317027Sdim * \param       in_size         in[in_size] is the first byte not to process
86317027Sdim *
87317027Sdim * \return      - LZMA_OK: So far good, but more input is needed.
88317027Sdim *              - LZMA_STREAM_END: Index decoded successfully and it matches
89317027Sdim *                the Records given with lzma_index_hash_append().
90317027Sdim *              - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
91341825Sdim *                information given with lzma_index_hash_append().
92341825Sdim *              - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
93341825Sdim *              - LZMA_PROG_ERROR
94341825Sdim */
95317027Sdimextern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
96353358Sdim		const uint8_t *in, size_t *in_pos, size_t in_size)
97317027Sdim		lzma_nothrow lzma_attr_warn_unused_result;
98317027Sdim
99353358Sdim
100317027Sdim/**
101317027Sdim * \brief       Get the size of the Index field as bytes
102353358Sdim *
103317027Sdim * This is needed to verify the Backward Size field in the Stream Footer.
104317027Sdim */
105353358Sdimextern LZMA_API(lzma_vli) lzma_index_hash_size(
106317027Sdim		const lzma_index_hash *index_hash)
107317027Sdim		lzma_nothrow lzma_attr_pure;
108317027Sdim