index_hash.h revision 207842
1212795Sdim/**
2212795Sdim * \file        lzma/index_hash.h
3212795Sdim * \brief       Validates Index by using a hash function
4212795Sdim *
5212795Sdim * Hashing makes it possible to use constant amount of memory to validate
6212795Sdim * Index of arbitrary size.
7212795Sdim */
8212795Sdim
9212795Sdim/*
10212795Sdim * Author: Lasse Collin
11212795Sdim *
12212795Sdim * This file has been put into the public domain.
13212795Sdim * You can do whatever you want with this file.
14212795Sdim *
15212795Sdim * See ../lzma.h for information about liblzma as a whole.
16212795Sdim */
17249423Sdim
18212795Sdim#ifndef LZMA_H_INTERNAL
19212795Sdim#	error Never include this file directly. Use <lzma.h> instead.
20212795Sdim#endif
21212795Sdim
22212795Sdim/**
23212795Sdim * \brief       Opaque data type to hold the Index hash
24218893Sdim */
25218893Sdimtypedef struct lzma_index_hash_s lzma_index_hash;
26221345Sdim
27221345Sdim
28263508Sdim/**
29263508Sdim * \brief       Allocate and initialize a new lzma_index_hash structure
30263508Sdim *
31218893Sdim * If index_hash is NULL, a new lzma_index_hash structure is allocated,
32218893Sdim * initialized, and a pointer to it returned. If allocation fails, NULL
33212795Sdim * is returned.
34212795Sdim *
35212795Sdim * If index_hash is non-NULL, it is reinitialized and the same pointer
36226633Sdim * returned. In this case, return value cannot be NULL or a different
37212795Sdim * pointer than the index_hash that was given as an argument.
38212795Sdim */
39212795Sdimextern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
40212795Sdim		lzma_index_hash *index_hash, lzma_allocator *allocator)
41218893Sdim		lzma_nothrow lzma_attr_warn_unused_result;
42212795Sdim
43212795Sdim
44212795Sdim/**
45212795Sdim * \brief       Deallocate lzma_index_hash structure
46212795Sdim */
47212795Sdimextern LZMA_API(void) lzma_index_hash_end(
48212795Sdim		lzma_index_hash *index_hash, lzma_allocator *allocator)
49212795Sdim		lzma_nothrow;
50212795Sdim
51226633Sdim
52226633Sdim/**
53226633Sdim * \brief       Add a new Record to an Index hash
54226633Sdim *
55239462Sdim * \param       index             Pointer to a lzma_index_hash structure
56239462Sdim * \param       unpadded_size     Unpadded Size of a Block
57226633Sdim * \param       uncompressed_size Uncompressed Size of a Block
58212795Sdim *
59212795Sdim * \return      - LZMA_OK
60212795Sdim *              - LZMA_DATA_ERROR: Compressed or uncompressed size of the
61212795Sdim *                Stream or size of the Index field would grow too big.
62212795Sdim *              - LZMA_PROG_ERROR: Invalid arguments or this function is being
63249423Sdim *                used when lzma_index_hash_decode() has already been used.
64249423Sdim */
65249423Sdimextern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
66249423Sdim		lzma_vli unpadded_size, lzma_vli uncompressed_size)
67249423Sdim		lzma_nothrow lzma_attr_warn_unused_result;
68249423Sdim
69249423Sdim
70249423Sdim/**
71249423Sdim * \brief       Decode and validate the Index field
72249423Sdim *
73249423Sdim * After telling the sizes of all Blocks with lzma_index_hash_append(),
74249423Sdim * the actual Index field is decoded with this function. Specifically,
75249423Sdim * once decoding of the Index field has been started, no more Records
76249423Sdim * can be added using lzma_index_hash_append().
77249423Sdim *
78212795Sdim * This function doesn't use lzma_stream structure to pass the input data.
79212795Sdim * Instead, the input buffer is specified using three arguments. This is
80212795Sdim * because it matches better the internal APIs of liblzma.
81212795Sdim *
82212795Sdim * \param       index_hash      Pointer to a lzma_index_hash structure
83 * \param       in              Pointer to the beginning of the input buffer
84 * \param       in_pos          in[*in_pos] is the next byte to process
85 * \param       in_size         in[in_size] is the first byte not to process
86 *
87 * \return      - LZMA_OK: So far good, but more input is needed.
88 *              - LZMA_STREAM_END: Index decoded successfully and it matches
89 *                the Records given with lzma_index_hash_append().
90 *              - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
91 *                information given with lzma_index_hash_append().
92 *              - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
93 *              - LZMA_PROG_ERROR
94 */
95extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
96		const uint8_t *in, size_t *in_pos, size_t in_size)
97		lzma_nothrow lzma_attr_warn_unused_result;
98
99
100/**
101 * \brief       Get the size of the Index field as bytes
102 *
103 * This is needed to verify the Backward Size field in the Stream Footer.
104 */
105extern LZMA_API(lzma_vli) lzma_index_hash_size(
106		const lzma_index_hash *index_hash)
107		lzma_nothrow lzma_attr_pure;
108