sqlite_hashes/sha512.rs
1use sha2::Sha512;
2
3use crate::rusqlite::{Connection, Result};
4
5/// Register the `sha512` SQL function with the given `SQLite` connection.
6/// The function takes a single argument and returns the [SHA512 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_sha512_functions;
15/// # fn main() -> Result<()> {
16/// let db = Connection::open_in_memory()?;
17/// register_sha512_functions(&db)?;
18/// let hash: Vec<u8> = db.query_row("SELECT sha512('hello')", [], |r| r.get(0))?;
19/// let expected = b"\x9b\x71\xd2\x24\xbd\x62\xf3\x78\x5d\x96\xd4\x6a\xd3\xea\x3d\x73\x31\x9b\xfb\xc2\x89\x0c\xaa\xda\xe2\xdf\xf7\x25\x19\x67\x3c\xa7\x23\x23\xc3\xd9\x9b\xa5\xc1\x1d\x7c\x7a\xcc\x6e\x14\xb8\xc5\xda\x0c\x46\x63\x47\x5c\x2e\x5c\x3a\xde\xf4\x6f\x73\xbc\xde\xc0\x43";
20/// assert_eq!(hash, expected);
21/// # Ok(())
22/// # }
23/// ```
24pub fn register_sha512_functions(conn: &Connection) -> Result<()> {
25 crate::scalar::create_hash_fn::<Sha512>(conn, "sha512")
26}