| Crates.io | safebrowsing-db-redb |
| lib.rs | safebrowsing-db-redb |
| version | 0.1.0 |
| created_at | 2025-08-07 17:09:51.711383+00 |
| updated_at | 2025-08-07 17:09:51.711383+00 |
| description | Redb-based persistent database backend for Safe Browsing API |
| homepage | |
| repository | https://github.com/JadedBlueEyes/safebrowsing-rs |
| max_upload_size | |
| id | 1785568 |
| size | 110,044 |
A persistent database backend for the Safe Browsing API using redb.
This crate provides a RedbDatabase implementation that stores Google Safe Browsing threat lists persistently on disk using the redb embedded database. Unlike the in-memory databases, this implementation:
Database trait from safebrowsing-dbuse safebrowsing_db_redb::RedbDatabase;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create database in default system cache location
let mut db = RedbDatabase::default();
// Or specify a custom path
let mut db = RedbDatabase::new("/path/to/database.redb")?;
// Use with Safe Browsing API
// (Database trait methods available)
Ok(())
}
use safebrowsing::{Config, DatabaseType, SafeBrowser};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config {
api_key: "your-api-key".to_string(),
database_type: Some(DatabaseType::Redb),
..Default::default()
};
let mut sb = SafeBrowser::new(config).await?;
// Database will be automatically stored in system cache
Ok(())
}
The sblookup tool supports the redb backend:
# Use persistent redb database
sblookup --database-type redb --api-key YOUR_API_KEY example.com
# Database will be stored in:
# - Linux: ~/.cache/safebrowsing/database.redb
# - macOS: ~/Library/Caches/safebrowsing/database.redb
# - Windows: %LOCALAPPDATA%/safebrowsing/database.redb
By default, the database is stored in the system cache directory:
~/.cache/safebrowsing/database.redb~/Library/Caches/safebrowsing/database.redb%LOCALAPPDATA%\safebrowsing\database.redbYou can override this by providing a custom path to RedbDatabase::new().
The redb database uses three tables:
threat_lists: Stores serialized threat list entries with hash prefixesmetadata: Stores database metadata (last update time, initialization status, etc.)hashes: Reserved for future use (direct hash lookups)The RedbDatabase is thread-safe and supports concurrent reads and writes through redb's ACID transaction system. Multiple processes can safely access the same database file.
The implementation maps redb errors to DatabaseError types:
DatabaseError::IoError - File system or permission errorsDatabaseError::DecodeError - Serialization/deserialization errorsDatabaseError::Stale - Database needs updatingDatabaseError::NotReady - Database not initializedredb - Embedded database enginedirs - System directory detectionserde - Serialization frameworktokio - Async runtimesafebrowsing-* - Safe Browsing API componentsLicensed under either of Apache License, Version 2.0 or MIT license at your option.