-
-
Notifications
You must be signed in to change notification settings - Fork 125
Generate enum rhash_ids from macro so that same macro can generate helper functions #194
Copy link
Copy link
Closed
Labels
Description
I've got a trivial wrapper for LibRHash: https://github.com/offscale/libacquire/blob/92f6921/libacquire/acquire_librhash.h
bool sha256(const char *filename, const char *gold_hash) {
char gen_hash[130], digest[64];
return hash_file(filename, RHASH_SHA256, RHPR_HEX, digest, gen_hash) < 0 ?
false : strcmp(gen_hash, gold_hash) == 0;
}Thought I might as well generate a function per hash:
https://github.com/rhash/RHash/blob/23b71fd/librhash/rhash.h#L25-L55
Considering it's just two things that need to change: RHASH_SHA256 and sha256 (name of function).
So something like this:
#define comma ,
#define HASHES \
X(crc32, RHASH_CRC32, comma) \
X(md4, RHASH_MD4, comma) \
X(md5, RHASH_MD5, comma) \
X(tiger, RHASH_TIGER, comma) \
X(tth, RHASH_TTH, comma) \
X(btih, RHASH_BTIH, comma) \
X(ed2k, RHASH_ED2K, comma) \
X(aich, RHASH_AICH, comma) \
X(whirlpool, RHASH_WHIRLPOOL, comma) \
X(ripemd160, RHASH_RIPEMD160, comma) \
X(gost94, RHASH_GOST94, comma) \
X(gost94_cryptopro, RHASH_GOST94_CRYPTOPRO, comma) \
X(has160, RHASH_HAS160, comma) \
X(gost12_256, RHASH_GOST12_256, comma) \
X(gost12_512, RHASH_GOST12_512, comma) \
X(sha224, RHASH_SHA224, comma) \
X(sha256, RHASH_SHA256, comma) \
X(sha384, RHASH_SHA384, comma) \
X(sha512, RHASH_SHA512, comma) \
X(edonr256, RHASH_EDONR256, comma) \
X(edonr512, RHASH_EDONR512, comma) \
X(sha3_224, RHASH_SHA3_224, comma) \
X(sha3_256, RHASH_SHA3_256, comma) \
X(sha3_384, RHASH_SHA3_384, comma) \
X(sha3_512, RHASH_SHA3_512, comma) \
X(crc32c, RHASH_CRC32C, comma) \
X(snefru128, RHASH_SNEFRU128, comma) \
X(snefru256, RHASH_SNEFRU256,)
enum hash_bits {
#define X(unused, hash, comma) hash##_bit comma
HASHES
#undef X
};
enum hash_ids {
#define X(unused, hash, comma) hash = 1 << hash##_bit comma
HASHES
#undef X
};What do you think, would you accept such a PR?
Reactions are currently unavailable