mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-01-03 14:56:34 -05:00
Feature: Added digest_algo_id2str() and digest_algo_length_bytes()
This commit is contained in:
parent
9560620c02
commit
29c5bd8d85
55
src/digest.c
55
src/digest.c
@ -302,6 +302,52 @@ static inline size_t sha3_read(digest_t *digest, void *buf, size_t len)
|
||||
}
|
||||
|
||||
|
||||
const char *digest_algo_id2str(digest_algo_t algo)
|
||||
{
|
||||
switch (algo) {
|
||||
|
||||
case DIGEST_ALGO_MD5:
|
||||
return "MD5";
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_224:
|
||||
return "SHA3-224";
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_256:
|
||||
return "SHA3-256";
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_384:
|
||||
return "SHA3-384";
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_512:
|
||||
return "SHA3-512";
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
ssize_t digest_algo_length_bytes(digest_algo_t algo)
|
||||
{
|
||||
switch (algo) {
|
||||
case DIGEST_ALGO_MD5:
|
||||
return 16;
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_224:
|
||||
return 224/8;
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_256:
|
||||
return 256/8;
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_384:
|
||||
return 384/8;
|
||||
break;
|
||||
case DIGEST_ALGO_SHA3_512:
|
||||
return 512/8;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
digest_t * digest_new(digest_algo_t algo)
|
||||
{
|
||||
digest_t *digest = refobject_new__new(digest_t, NULL, NULL, NULL);
|
||||
@ -400,12 +446,5 @@ ssize_t digest_length_bytes(digest_t *digest)
|
||||
if (!digest)
|
||||
return -1;
|
||||
|
||||
switch (digest->algo) {
|
||||
case DIGEST_ALGO_MD5:
|
||||
return 16;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
return digest_algo_length_bytes(digest->algo);
|
||||
}
|
||||
|
11
src/digest.h
11
src/digest.h
@ -21,11 +21,14 @@ typedef enum {
|
||||
DIGEST_ALGO_SHA3_512
|
||||
} digest_algo_t;
|
||||
|
||||
digest_t * digest_new(digest_algo_t algo);
|
||||
ssize_t digest_write(digest_t *digest, const void *data, size_t len);
|
||||
ssize_t digest_read(digest_t *digest, void *buf, size_t len);
|
||||
const char *digest_algo_id2str(digest_algo_t algo);
|
||||
ssize_t digest_algo_length_bytes(digest_algo_t algo);
|
||||
|
||||
digest_t * digest_new(digest_algo_t algo);
|
||||
ssize_t digest_write(digest_t *digest, const void *data, size_t len);
|
||||
ssize_t digest_read(digest_t *digest, void *buf, size_t len);
|
||||
|
||||
/* Returns the digest size in bytes */
|
||||
ssize_t digest_length_bytes(digest_t *digest);
|
||||
ssize_t digest_length_bytes(digest_t *digest);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user