1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* createrepo_c - Library of routines for manipulation with repodata
* Copyright (C) 2013 Tomas Mlcoch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#ifndef __C_CREATEREPOLIB_CHECKSUM_H__
#define __C_CREATEREPOLIB_CHECKSUM_H__
#include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup checksum API for checksum calculation.
* \addtogroup checksum
* @{
*/
/** Checksum context.
*/
typedef struct _cr_ChecksumCtx cr_ChecksumCtx;
/**
* Enum of supported checksum types.
* Note: SHA is just a "nickname" for the SHA1. This
* is for the compatibility with original createrepo.
*/
typedef enum {
CR_CHECKSUM_UNKNOWN, /*!< Unknown checksum */
// CR_CHECKSUM_MD2, /*!< MD2 checksum */
CR_CHECKSUM_MD5, /*!< MD5 checksum */
CR_CHECKSUM_SHA, /*!< SHA checksum */
CR_CHECKSUM_SHA1, /*!< SHA1 checksum */
CR_CHECKSUM_SHA224, /*!< SHA224 checksum */
CR_CHECKSUM_SHA256, /*!< SHA256 checksum */
CR_CHECKSUM_SHA384, /*!< SHA384 checksum */
CR_CHECKSUM_SHA512, /*!< SHA512 checksum */
CR_CHECKSUM_SENTINEL, /*!< sentinel of the list */
} cr_ChecksumType;
/** Return checksum name.
* @param type checksum type
* @return constant null terminated string with checksum name
* or NULL on error
*/
const char *cr_checksum_name_str(cr_ChecksumType type);
/** Return checksum type.
* @param name checksum name
* @return checksum type
*/
cr_ChecksumType cr_checksum_type(const char *name);
/** Compute file checksum.
* @param filename filename
* @param type type of checksum
* @param err GError **
* @return malloced null terminated string with checksum
* or NULL on error
*/
char *cr_checksum_file(const char *filename,
cr_ChecksumType type,
GError **err);
/** Create new checksum context.
* @param type Checksum algorithm of the new checksum context.
* @param err GError **
* @return cr_ChecksumCtx or NULL on error
*/
cr_ChecksumCtx *cr_checksum_new(cr_ChecksumType type, GError **err);
/** Feeds data into the checksum.
* @param ctx Checksum context.
* @param buf Pointer to the data.
* @param len Length of the data.
* @param err GError **
* @return cr_Error code.
*/
int cr_checksum_update(cr_ChecksumCtx *ctx,
const void *buf,
size_t len,
GError **err);
/** Finalize checksum calculation, return checksum string and frees
* all checksum context resources.
* @param ctx Checksum context.
* @param err GError **
* @return Checksum string or NULL on error.
*/
char *cr_checksum_final(cr_ChecksumCtx *ctx, GError **err);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* __C_CREATEREPOLIB_XML_PARSER_H__ */
|