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_from_bin(Id type, const unsigned char *buf)
61 int l = solv_chksum_len(type);
62 if (buf == 0 || l == 0)
64 h = solv_calloc(1, sizeof(*h));
67 memcpy(h->result, buf, l);
72 solv_chksum_add(void *handle, const void *data, int len)
74 struct ctxhandle *h = handle;
79 case REPOKEY_TYPE_MD5:
80 solv_MD5_Update(&h->c.md5, (void *)data, len);
82 case REPOKEY_TYPE_SHA1:
83 solv_SHA1_Update(&h->c.sha1, data, len);
85 case REPOKEY_TYPE_SHA256:
86 solv_SHA256_Update(&h->c.sha256, data, len);
94 solv_chksum_get(void *handle, int *lenp)
96 struct ctxhandle *h = handle;
100 *lenp = solv_chksum_len(h->type);
105 case REPOKEY_TYPE_MD5:
106 solv_MD5_Final(h->result, &h->c.md5);
111 case REPOKEY_TYPE_SHA1:
112 solv_SHA1_Final(&h->c.sha1, h->result);
117 case REPOKEY_TYPE_SHA256:
118 solv_SHA256_Final(h->result, &h->c.sha256);
131 solv_chksum_get_type(void *handle)
133 struct ctxhandle *h = handle;
138 solv_chksum_isfinished(void *handle)
140 struct ctxhandle *h = handle;
145 solv_chksum_type2str(Id type)
149 case REPOKEY_TYPE_MD5:
151 case REPOKEY_TYPE_SHA1:
153 case REPOKEY_TYPE_SHA256:
161 solv_chksum_str2type(const char *str)
163 if (!strcasecmp(str, "md5"))
164 return REPOKEY_TYPE_MD5;
165 if (!strcasecmp(str, "sha") || !strcasecmp(str, "sha1"))
166 return REPOKEY_TYPE_SHA1;
167 if (!strcasecmp(str, "sha256"))
168 return REPOKEY_TYPE_SHA256;
173 solv_chksum_free(void *handle, unsigned char *cp)
177 const unsigned char *res;
179 res = solv_chksum_get(handle, &l);