sqlite_hashes/
sha224.rs

1use sha2::Sha224;
2
3use crate::rusqlite::{Connection, Result};
4
5/// Register the `sha224` SQL function with the given `SQLite` connection.
6/// The function takes a single argument and returns the [SHA224 hash](https://en.wikipedia.org/wiki/SHA-2) (blob) of that argument.
7/// The argument can be either a string or a blob.
8/// If the argument is `NULL`, the result is `NULL`.
9///
10/// # Example
11///
12/// ```
13/// # use sqlite_hashes::rusqlite::{Connection, Result};
14/// # use sqlite_hashes::register_sha224_functions;
15/// # fn main() -> Result<()> {
16/// let db = Connection::open_in_memory()?;
17/// register_sha224_functions(&db)?;
18/// let hash: Vec<u8> = db.query_row("SELECT sha224('hello')", [], |r| r.get(0))?;
19/// let expected = b"\xea\x09\xae\x9c\xc6\x76\x8c\x50\xfc\xee\x90\x3e\xd0\x54\x55\x6e\x5b\xfc\x83\x47\x90\x7f\x12\x59\x8a\xa2\x41\x93";
20/// assert_eq!(hash, expected);
21/// # Ok(())
22/// # }
23/// ```
24pub fn register_sha224_functions(conn: &Connection) -> Result<()> {
25    crate::scalar::create_hash_fn::<Sha224>(conn, "sha224")
26}