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)
60 return solv_memdup(handle, sizeof(struct ctxhandle));
64 solv_chksum_len(Id type)
68 case REPOKEY_TYPE_MD5:
70 case REPOKEY_TYPE_SHA1:
72 case REPOKEY_TYPE_SHA256:
80 solv_chksum_create_from_bin(Id type, const unsigned char *buf)
83 int l = solv_chksum_len(type);
84 if (buf == 0 || l == 0)
86 h = solv_calloc(1, sizeof(*h));
89 memcpy(h->result, buf, l);
94 solv_chksum_add(void *handle, const void *data, int len)
96 struct ctxhandle *h = handle;
101 case REPOKEY_TYPE_MD5:
102 solv_MD5_Update(&h->c.md5, (void *)data, len);
104 case REPOKEY_TYPE_SHA1:
105 solv_SHA1_Update(&h->c.sha1, data, len);
107 case REPOKEY_TYPE_SHA256:
108 solv_SHA256_Update(&h->c.sha256, data, len);
115 const unsigned char *
116 solv_chksum_get(void *handle, int *lenp)
118 struct ctxhandle *h = handle;
122 *lenp = solv_chksum_len(h->type);
127 case REPOKEY_TYPE_MD5:
128 solv_MD5_Final(h->result, &h->c.md5);
133 case REPOKEY_TYPE_SHA1:
134 solv_SHA1_Final(&h->c.sha1, h->result);
139 case REPOKEY_TYPE_SHA256:
140 solv_SHA256_Final(h->result, &h->c.sha256);
153 solv_chksum_get_type(void *handle)
155 struct ctxhandle *h = handle;
160 solv_chksum_isfinished(void *handle)
162 struct ctxhandle *h = handle;
167 solv_chksum_type2str(Id type)
171 case REPOKEY_TYPE_MD5:
173 case REPOKEY_TYPE_SHA1:
175 case REPOKEY_TYPE_SHA256:
183 solv_chksum_str2type(const char *str)
185 if (!strcasecmp(str, "md5"))
186 return REPOKEY_TYPE_MD5;
187 if (!strcasecmp(str, "sha") || !strcasecmp(str, "sha1"))
188 return REPOKEY_TYPE_SHA1;
189 if (!strcasecmp(str, "sha256"))
190 return REPOKEY_TYPE_SHA256;
195 solv_chksum_free(void *handle, unsigned char *cp)
199 const unsigned char *res;
201 res = solv_chksum_get(handle, &l);