sqlite_hashes/sha384.rs
1use sha2::Sha384;
2
3use crate::rusqlite::{Connection, Result};
4
5/// Register the `sha384` SQL function with the given `SQLite` connection.
6/// The function takes a single argument and returns the [SHA384 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_sha384_functions;
15/// # fn main() -> Result<()> {
16/// let db = Connection::open_in_memory()?;
17/// register_sha384_functions(&db)?;
18/// let hash: Vec<u8> = db.query_row("SELECT sha384('hello')", [], |r| r.get(0))?;
19/// let expected = b"\x59\xe1\x74\x87\x77\x44\x8c\x69\xde\x6b\x80\x0d\x7a\x33\xbb\xfb\x9f\xf1\xb4\x63\xe4\x43\x54\xc3\x55\x3b\xcd\xb9\xc6\x66\xfa\x90\x12\x5a\x3c\x79\xf9\x03\x97\xbd\xf5\xf6\xa1\x3d\xe8\x28\x68\x4f";
20/// assert_eq!(hash, expected);
21/// # Ok(())
22/// # }
23/// ```
24pub fn register_sha384_functions(conn: &Connection) -> Result<()> {
25 crate::scalar::create_hash_fn::<Sha384>(conn, "sha384")
26}