Last change
on this file since 50d0a72 was
1bdc669,
checked in by GitHub <noreply@…>, at 2023-02-23T23:48:10Z
|
Migrate internal users of md5.h to using GChecksum directly (#169)
- Use GChecksum directly rather than md5 wrapper
- Mark md5 functions as deprecated.
- Migrate more users of md5.h to GChecksum
|
-
Property mode set to
100644
|
File size:
1009 bytes
|
Rev | Line | |
---|
[b7d3cc34] | 1 | #include "md5.h" |
---|
| 2 | |
---|
[34afea7] | 3 | /* Creates a new GChecksum in ctx */ |
---|
| 4 | void md5_init(md5_state_t *ctx) |
---|
[bea1305] | 5 | { |
---|
[34afea7] | 6 | *ctx = g_checksum_new(G_CHECKSUM_MD5); |
---|
[bea1305] | 7 | } |
---|
| 8 | |
---|
[34afea7] | 9 | /* Wrapper for g_checksum_update */ |
---|
| 10 | void md5_append(md5_state_t *ctx, const guint8 *buf, unsigned int len) |
---|
[b7d3cc34] | 11 | { |
---|
[34afea7] | 12 | g_checksum_update(*ctx, buf, len); |
---|
[df6d1da] | 13 | } |
---|
[b7d3cc34] | 14 | |
---|
[34afea7] | 15 | /* Wrapper for g_checksum_get_digest |
---|
| 16 | * Also takes care of g_checksum_free(), since it can't be reused anyway |
---|
| 17 | * (the GChecksum is closed after get_digest) */ |
---|
| 18 | void md5_finish(md5_state_t *ctx, guint8 digest[MD5_HASH_SIZE]) |
---|
[b7d3cc34] | 19 | { |
---|
[34afea7] | 20 | gsize digest_len = MD5_HASH_SIZE; |
---|
[5ebff60] | 21 | |
---|
[34afea7] | 22 | g_checksum_get_digest(*ctx, digest, &digest_len); |
---|
| 23 | g_checksum_free(*ctx); |
---|
[b7d3cc34] | 24 | } |
---|
[df6d1da] | 25 | |
---|
[34afea7] | 26 | /* Variant of md5_finish that copies the GChecksum |
---|
| 27 | * and finishes that one instead of the original */ |
---|
| 28 | void md5_digest_keep(md5_state_t *ctx, guint8 digest[MD5_HASH_SIZE]) |
---|
[b7d3cc34] | 29 | { |
---|
[1bdc669] | 30 | gsize digest_len = MD5_HASH_SIZE; |
---|
| 31 | GChecksum *copy = g_checksum_copy(*ctx); |
---|
[5ebff60] | 32 | |
---|
[1bdc669] | 33 | g_checksum_get_digest(copy, digest, &digest_len); |
---|
| 34 | g_checksum_free(copy); |
---|
[b7d3cc34] | 35 | } |
---|
| 36 | |
---|
[34afea7] | 37 | void md5_free(md5_state_t *ctx) |
---|
[b7d3cc34] | 38 | { |
---|
[34afea7] | 39 | g_checksum_free(*ctx); |
---|
[b7d3cc34] | 40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.