diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-06-20 18:18:26 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-06-20 18:18:26 +0400 |
commit | 01d802976fc89b97a5a67a0dacdaf414db2651ca (patch) | |
tree | 7255693399b625ff71355501a37061c4ce503c30 /source | |
parent | fb7c71383b8c21d7ded739b553e6c11f66f166df (diff) |
BLI_md5: add a utility function to 'translate' raw 16bytes digest into a nice 32chars hexadecimal string.
That kind of stuff belongs to BLI, not specialized code like thumbs.c
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_md5.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/md5.c | 17 | ||||
-rw-r--r-- | source/blender/imbuf/intern/thumbs.c | 4 |
3 files changed, 20 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_md5.h b/source/blender/blenlib/BLI_md5.h index 8ce479b1801..6a760f53e45 100644 --- a/source/blender/blenlib/BLI_md5.h +++ b/source/blender/blenlib/BLI_md5.h @@ -41,5 +41,7 @@ void *md5_buffer(const char *buffer, size_t len, void *resblock); int md5_stream(FILE *stream, void *resblock); +char *md5_to_hexdigest(void *resblock, char r_hex_digest[33]); + #endif diff --git a/source/blender/blenlib/intern/md5.c b/source/blender/blenlib/intern/md5.c index 4122f6448fd..3d1a9cdb7a4 100644 --- a/source/blender/blenlib/intern/md5.c +++ b/source/blender/blenlib/intern/md5.c @@ -389,3 +389,20 @@ void *md5_buffer(const char *buffer, size_t len, void *resblock) /* Put result in desired memory area. */ return md5_read_ctx(&ctx, resblock); } + +char *md5_to_hexdigest(void *resblock, char r_hex_digest[33]) +{ + static const char hex_map[17] = "0123456789abcdef"; + const unsigned char *p; + char *q; + short len; + + for (q = r_hex_digest, p = (const unsigned char *)resblock, len = 0; len < 16; ++p, ++len) { + const unsigned char c = *p; + *q++ = hex_map[c >> 4]; + *q++ = hex_map[c & 15]; + } + *q = '\0'; + + return r_hex_digest; +} diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 236d41078d6..41784b1e448 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -258,9 +258,7 @@ static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_len md5_buffer(uri, strlen(uri), digest); hexdigest[0] = '\0'; - to_hex_char(hexdigest, digest, 16); - hexdigest[32] = '\0'; - BLI_snprintf(thumb, thumb_len, "%s.png", hexdigest); + BLI_snprintf(thumb, thumb_len, "%s.png", md5_to_hexdigest(digest, hexdigest)); // printf("%s: '%s' --> '%s'\n", __func__, uri, thumb); } |