#sha-1 #hash #macro #compile-time #computing #hex #byte

macro sha1-macros

Macros for computing SHA1 hashes at compile-time

1 stable release

1.0.0 Apr 7, 2024

#673 in Procedural macros

Download history 102/week @ 2024-04-02 24/week @ 2024-04-09

126 downloads per month

GPL-3.0-only

6KB
57 lines

SHA1 macros

The sha1-macros crate allows you to compute SHA1 hashes at compile-time.

assert_eq!(sha1_hex!("this is a test"), "fa26be19de6bff93f70bc2308434e4a440bbad02");
assert_eq!(sha1_bytes!("this is a test"), hex!("fa26be19de6bff93f70bc2308434e4a440bbad02"));

Why macros and not const fn?

Simple answer: It is not yet possible to create a &'static str at compile-time using const fn. By providing macros, we remove the need to encode your hash digest into hex or base64 at runtime. Note that this has the limitation that the input of sha1_* macros must be either a string ("value") or a byte (b"value") literal. It cannot be a const value.


lib.rs:

Macros for computing SHA1 hashes at compile-time

Examples

assert_eq!(sha1_hex!("this is a test"), "fa26be19de6bff93f70bc2308434e4a440bbad02");
assert_eq!(sha1_bytes!("this is a test"), hex!("fa26be19de6bff93f70bc2308434e4a440bbad02"));

Dependencies

~1–1.5MB
~33K SLoC