Rusqlcipher

Travis Build Status AppVeyor Build Status Latest Version

Rusqlcipher is an ergonomic wrapper for using SQLCipher from Rust. It attempts to expose an interface similar to rust-postgres. View the full API documentation.

```rust extern crate rusqlcipher; extern crate time;

use time::Timespec; use rusqlcipher::Connection;

[derive(Debug)]

struct Person { id: i32, name: String, time_created: Timespec, data: Option> }

fn main() { let conn = Connection::openinmemory().unwrap();

conn.execute("CREATE TABLE person (
              id              INTEGER PRIMARY KEY,
              name            TEXT NOT NULL,
              time_created    TEXT NOT NULL,
              data            BLOB
              )", &[]).unwrap();
let me = Person {
    id: 0,
    name: "Steven".to_string(),
    time_created: time::get_time(),
    data: None
};
conn.execute("INSERT INTO person (name, time_created, data)
              VALUES (?1, ?2, ?3)",
             &[&me.name, &me.time_created, &me.data]).unwrap();

let mut stmt = conn.prepare("SELECT id, name, time_created, data FROM person").unwrap();
let person_iter = stmt.query_map(&[], |row| {
    Person {
        id: row.get(0),
        name: row.get(1),
        time_created: row.get(2),
        data: row.get(3)
    }
}).unwrap();

for person in person_iter {
    println!("Found person {:?}", person.unwrap());
}

} ```

SQLCipher

This work is based on rusqlite and SQLCipher. This package has precompiled SQLCipher to use OpenSSL 1.1.0 or newer and replaces the following three files in libsqlite-sys/sqlite3/: sqlite3.c, sqlite3.h, sqlite3ext.h. See openssl-sys for information on compiling openssl. SQLCipher has been modified to use HMAC-SHA256 instead of the default HMAC-SHA1.

Supported SQLite Versions

The base rusqlcipher package supports SQLite version 3.6.8 or newer. If you need support for older versions, please file an issue. Some cargo features require a newer SQLite version; see details below.

Optional Features

Rusqlite provides several features that are behind Cargo features. They are:

Notes on building rusqlcipher and libsqlite3-sys

libsqlite3-sys is a separate crate from rusqlcipher that provides the Rust declarations for SQLite's C API. By default, libsqlite3-sys attempts to find a SQLite library that already exists on your system using pkg-config, or a Vcpkg installation for MSVC ABI builds. rusqlcipher also depends on OpenSSL version 1.1.0 or above.

You can adjust this behavior in a number of ways:

Binding generation

We use bindgen to generate the Rust declarations from SQLite's C header file. bindgen recommends running this as part of the build process of libraries that used this. We tried this briefly (rusqlite 0.10.0, specifically), but it had some annoyances:

As of rusqlcipher 0.1.0, we avoid running bindgen at build-time by shipping pregenerated bindings for several versions of SQLite. When compiling rusqlite, we use your selected Cargo features to pick the bindings for the minimum SQLite version that supports your chosen features. If you are using libsqlite3-sys directly, you can use the same features to choose which pregenerated bindings are chosen:

If you use the bundled feature, you will get pregenerated bindings for the bundled version of SQLite. If you need other specific pregenerated binding versions, please file an issue. If you want to run bindgen at buildtime to produce your own bindings, use the buildtime_bindgen Cargo feature.

Author

Michael Lodder, redmike7@gmail.com

Original Author

John Gallagher, johnkgallagher@gmail.com

License

Rusqlcipher is available under the Apache Version 2 license. See the LICENSE file for more info. Rusqlite is available under the MIT license. See the ORIGLICENSE file for more info.