sqlite_hashes/
sha1.rs

1use sha1::Sha1;
2
3use crate::rusqlite::{Connection, Result};
4
5/// Register the `sha1` SQL function with the given `SQLite` connection.
6/// The function takes a single argument and returns the [SHA1 hash](https://en.wikipedia.org/wiki/SHA-1) (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_sha1_functions;
15/// # fn main() -> Result<()> {
16/// let db = Connection::open_in_memory()?;
17/// register_sha1_functions(&db)?;
18/// let hash: Vec<u8> = db.query_row("SELECT sha1('hello')", [], |r| r.get(0))?;
19/// let expected = b"\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f\x3b\x48\x2c\xd9\xae\xa9\x43\x4d";
20/// assert_eq!(hash, expected);
21/// # Ok(())
22/// # }
23/// ```
24pub fn register_sha1_functions(conn: &Connection) -> Result<()> {
25    crate::scalar::create_hash_fn::<Sha1>(conn, "sha1")
26}