Crate sqlite_hashes
source ·Expand description
sqlite-hashes
Use this crate to add various hash functions to SQLite, including MD5, SHA1, SHA256, and SHA512.
This crate uses rusqlite to add user-defined scalar functions using static linking. Eventually this crate may also support dynamic extension loading (PRs welcome).
Usage
use sqlite_hashes::{register_sha256_function, rusqlite::Connection};
fn main() {
let db = Connection::open_in_memory().unwrap();
register_sha256_function(&db).unwrap();
let sql = "SELECT hex(sha256('password'))";
let hash: String = db.query_row_and_then(&sql, [], |r| r.get(0)).unwrap();
assert_eq!(hash, "5E884898DA28047151D0E56F8DC6292773603D0D6AABBDD62A11EF721D1542D8");
}Features
By default, this crate will compile with all hash functions. You can enable just the ones you need to reduce compile time.
[dependencies]
sqlite-hashes = { version = "0.1", default-features = false, features = ["sha256"] }
Development
- This project is easier to develop with just, a modern alternative to
make. Install it withcargo install just. - On
git push, it will run a few validations, includingcargo fmt,cargo clippy, andcargo test. Usegit push --no-verifyto skip these checks.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Re-exports
pub use rusqlite;
Functions
- Register the
md5SQL function with the givenSQLiteconnection. The function takes a single argument and returns the MD5 hash (blob) of that argument. The argument can be either a string or a blob. If the argument isNULL, the result isNULL. - Register the
sha1SQL function with the givenSQLiteconnection. The function takes a single argument and returns the SHA1 hash (blob) of that argument. The argument can be either a string or a blob. If the argument isNULL, the result isNULL. - Register the
sha256SQL function with the givenSQLiteconnection. The function takes a single argument and returns the SHA256 hash (blob) of that argument. The argument can be either a string or a blob. If the argument isNULL, the result isNULL. - Register the
sha512SQL function with the givenSQLiteconnection. The function takes a single argument and returns the SHA512 hash (blob) of that argument. The argument can be either a string or a blob. If the argument isNULL, the result isNULL.