Path: blob/master/Utilities/cmliblzma/liblzma/api/lzma/stream_flags.h
3158 views
/* SPDX-License-Identifier: 0BSD */12/**3* \file lzma/stream_flags.h4* \brief .xz Stream Header and Stream Footer encoder and decoder5* \note Never include this file directly. Use <lzma.h> instead.6*/78/*9* Author: Lasse Collin10*/1112#ifndef LZMA_H_INTERNAL13# error Never include this file directly. Use <lzma.h> instead.14#endif151617/**18* \brief Size of Stream Header and Stream Footer19*20* Stream Header and Stream Footer have the same size and they are not21* going to change even if a newer version of the .xz file format is22* developed in future.23*/24#define LZMA_STREAM_HEADER_SIZE 12252627/**28* \brief Options for encoding/decoding Stream Header and Stream Footer29*/30typedef struct {31/**32* \brief Stream Flags format version33*34* To prevent API and ABI breakages if new features are needed in35* Stream Header or Stream Footer, a version number is used to36* indicate which members in this structure are in use. For now,37* version must always be zero. With non-zero version, the38* lzma_stream_header_encode() and lzma_stream_footer_encode()39* will return LZMA_OPTIONS_ERROR.40*41* lzma_stream_header_decode() and lzma_stream_footer_decode()42* will always set this to the lowest value that supports all the43* features indicated by the Stream Flags field. The application44* must check that the version number set by the decoding functions45* is supported by the application. Otherwise it is possible that46* the application will decode the Stream incorrectly.47*/48uint32_t version;4950/**51* \brief Backward Size52*53* Backward Size must be a multiple of four bytes. In this Stream54* format version, Backward Size is the size of the Index field.55*56* Backward Size isn't actually part of the Stream Flags field, but57* it is convenient to include in this structure anyway. Backward58* Size is present only in the Stream Footer. There is no need to59* initialize backward_size when encoding Stream Header.60*61* lzma_stream_header_decode() always sets backward_size to62* LZMA_VLI_UNKNOWN so that it is convenient to use63* lzma_stream_flags_compare() when both Stream Header and Stream64* Footer have been decoded.65*/66lzma_vli backward_size;6768/**69* \brief Minimum value for lzma_stream_flags.backward_size70*/71# define LZMA_BACKWARD_SIZE_MIN 47273/**74* \brief Maximum value for lzma_stream_flags.backward_size75*/76# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)7778/**79* \brief Check ID80*81* This indicates the type of the integrity check calculated from82* uncompressed data.83*/84lzma_check check;8586/*87* Reserved space to allow possible future extensions without88* breaking the ABI. You should not touch these, because the89* names of these variables may change.90*91* (We will never be able to use all of these since Stream Flags92* is just two bytes plus Backward Size of four bytes. But it's93* nice to have the proper types when they are needed.)94*/9596/** \private Reserved member. */97lzma_reserved_enum reserved_enum1;9899/** \private Reserved member. */100lzma_reserved_enum reserved_enum2;101102/** \private Reserved member. */103lzma_reserved_enum reserved_enum3;104105/** \private Reserved member. */106lzma_reserved_enum reserved_enum4;107108/** \private Reserved member. */109lzma_bool reserved_bool1;110111/** \private Reserved member. */112lzma_bool reserved_bool2;113114/** \private Reserved member. */115lzma_bool reserved_bool3;116117/** \private Reserved member. */118lzma_bool reserved_bool4;119120/** \private Reserved member. */121lzma_bool reserved_bool5;122123/** \private Reserved member. */124lzma_bool reserved_bool6;125126/** \private Reserved member. */127lzma_bool reserved_bool7;128129/** \private Reserved member. */130lzma_bool reserved_bool8;131132/** \private Reserved member. */133uint32_t reserved_int1;134135/** \private Reserved member. */136uint32_t reserved_int2;137138} lzma_stream_flags;139140141/**142* \brief Encode Stream Header143*144* \param options Stream Header options to be encoded.145* options->backward_size is ignored and doesn't146* need to be initialized.147* \param[out] out Beginning of the output buffer of148* LZMA_STREAM_HEADER_SIZE bytes.149*150* \return Possible lzma_ret values:151* - LZMA_OK: Encoding was successful.152* - LZMA_OPTIONS_ERROR: options->version is not supported by153* this liblzma version.154* - LZMA_PROG_ERROR: Invalid options.155*/156extern LZMA_API(lzma_ret) lzma_stream_header_encode(157const lzma_stream_flags *options, uint8_t *out)158lzma_nothrow lzma_attr_warn_unused_result;159160161/**162* \brief Encode Stream Footer163*164* \param options Stream Footer options to be encoded.165* \param[out] out Beginning of the output buffer of166* LZMA_STREAM_HEADER_SIZE bytes.167*168* \return Possible lzma_ret values:169* - LZMA_OK: Encoding was successful.170* - LZMA_OPTIONS_ERROR: options->version is not supported by171* this liblzma version.172* - LZMA_PROG_ERROR: Invalid options.173*/174extern LZMA_API(lzma_ret) lzma_stream_footer_encode(175const lzma_stream_flags *options, uint8_t *out)176lzma_nothrow lzma_attr_warn_unused_result;177178179/**180* \brief Decode Stream Header181*182* options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to183* help comparing Stream Flags from Stream Header and Stream Footer with184* lzma_stream_flags_compare().185*186* \note When decoding .xz files that contain multiple Streams, it may187* make sense to print "file format not recognized" only if188* decoding of the Stream Header of the \a first Stream gives189* LZMA_FORMAT_ERROR. If non-first Stream Header gives190* LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is191* probably more appropriate.192* For example, the Stream decoder in liblzma uses193* LZMA_DATA_ERROR if LZMA_FORMAT_ERROR is returned by194* lzma_stream_header_decode() when decoding non-first Stream.195*196* \param[out] options Target for the decoded Stream Header options.197* \param in Beginning of the input buffer of198* LZMA_STREAM_HEADER_SIZE bytes.199*200*201* \return Possible lzma_ret values:202* - LZMA_OK: Decoding was successful.203* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given204* buffer cannot be Stream Header.205* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header206* is corrupt.207* - LZMA_OPTIONS_ERROR: Unsupported options are present208* in the header.209*/210extern LZMA_API(lzma_ret) lzma_stream_header_decode(211lzma_stream_flags *options, const uint8_t *in)212lzma_nothrow lzma_attr_warn_unused_result;213214215/**216* \brief Decode Stream Footer217*218* \note If Stream Header was already decoded successfully, but219* decoding Stream Footer returns LZMA_FORMAT_ERROR, the220* application should probably report some other error message221* than "file format not recognized". The file likely222* is corrupt (possibly truncated). The Stream decoder in liblzma223* uses LZMA_DATA_ERROR in this situation.224*225* \param[out] options Target for the decoded Stream Footer options.226* \param in Beginning of the input buffer of227* LZMA_STREAM_HEADER_SIZE bytes.228*229* \return Possible lzma_ret values:230* - LZMA_OK: Decoding was successful.231* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given232* buffer cannot be Stream Footer.233* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer234* is corrupt.235* - LZMA_OPTIONS_ERROR: Unsupported options are present236* in Stream Footer.237*/238extern LZMA_API(lzma_ret) lzma_stream_footer_decode(239lzma_stream_flags *options, const uint8_t *in)240lzma_nothrow lzma_attr_warn_unused_result;241242243/**244* \brief Compare two lzma_stream_flags structures245*246* backward_size values are compared only if both are not247* LZMA_VLI_UNKNOWN.248*249* \param a Pointer to lzma_stream_flags structure250* \param b Pointer to lzma_stream_flags structure251*252* \return Possible lzma_ret values:253* - LZMA_OK: Both are equal. If either had backward_size set254* to LZMA_VLI_UNKNOWN, backward_size values were not255* compared or validated.256* - LZMA_DATA_ERROR: The structures differ.257* - LZMA_OPTIONS_ERROR: version in either structure is greater258* than the maximum supported version (currently zero).259* - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or260* backward_size.261*/262extern LZMA_API(lzma_ret) lzma_stream_flags_compare(263const lzma_stream_flags *a, const lzma_stream_flags *b)264lzma_nothrow lzma_attr_pure;265266267