2 * Copyright (c) 2008-2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
25 unsigned char result[64];
34 solv_chksum_create(Id type)
37 h = solv_calloc(1, sizeof(*h));
41 case REPOKEY_TYPE_MD5:
42 solv_MD5_Init(&h->c.md5);
44 case REPOKEY_TYPE_SHA1:
45 solv_SHA1_Init(&h->c.sha1);
47 case REPOKEY_TYPE_SHA256:
48 solv_SHA256_Init(&h->c.sha256);
58 solv_chksum_create_clone(void *handle)
63 h = solv_calloc(1, sizeof(*h));
64 *h = *(struct ctxhandle *)handle;
69 solv_chksum_len(Id type)
73 case REPOKEY_TYPE_MD5:
75 case REPOKEY_TYPE_SHA1:
77 case REPOKEY_TYPE_SHA256:
85 solv_chksum_create_from_bin(Id type, const unsigned char *buf)
88 int l = solv_chksum_len(type);
89 if (buf == 0 || l == 0)
91 h = solv_calloc(1, sizeof(*h));
94 memcpy(h->result, buf, l);
99 solv_chksum_add(void *handle, const void *data, int len)
101 struct ctxhandle *h = handle;
106 case REPOKEY_TYPE_MD5:
107 solv_MD5_Update(&h->c.md5, (void *)data, len);
109 case REPOKEY_TYPE_SHA1:
110 solv_SHA1_Update(&h->c.sha1, data, len);
112 case REPOKEY_TYPE_SHA256:
113 solv_SHA256_Update(&h->c.sha256, data, len);
120 const unsigned char *
121 solv_chksum_get(void *handle, int *lenp)
123 struct ctxhandle *h = handle;
127 *lenp = solv_chksum_len(h->type);
132 case REPOKEY_TYPE_MD5:
133 solv_MD5_Final(h->result, &h->c.md5);
138 case REPOKEY_TYPE_SHA1:
139 solv_SHA1_Final(&h->c.sha1, h->result);
144 case REPOKEY_TYPE_SHA256:
145 solv_SHA256_Final(h->result, &h->c.sha256);
158 solv_chksum_get_type(void *handle)
160 struct ctxhandle *h = handle;
165 solv_chksum_isfinished(void *handle)
167 struct ctxhandle *h = handle;
172 solv_chksum_type2str(Id type)
176 case REPOKEY_TYPE_MD5:
178 case REPOKEY_TYPE_SHA1:
180 case REPOKEY_TYPE_SHA256:
188 solv_chksum_str2type(const char *str)
190 if (!strcasecmp(str, "md5"))
191 return REPOKEY_TYPE_MD5;
192 if (!strcasecmp(str, "sha") || !strcasecmp(str, "sha1"))
193 return REPOKEY_TYPE_SHA1;
194 if (!strcasecmp(str, "sha256"))
195 return REPOKEY_TYPE_SHA256;
200 solv_chksum_free(void *handle, unsigned char *cp)
204 const unsigned char *res;
206 res = solv_chksum_get(handle, &l);