memsafe
A cross-platform Rust library for securely wrapping data in memory.
memsafe locks sensitive data in memory, restricts access, and ensures secure cleanup—built from the ground up with simplicity and security in mind.
Usage
use MemSafe;
let mut secret = new.unwrap;
secret.push_str;
println!;
Features
- Memory Locking: Prevents swapping to disk using
mlock(Unix) orVirtualLock(Windows). - Access Restriction: Defaults to no-access mode, with temporary read/write windows.
- Secure Cleanup: Zeroes memory on drop.
- Cross-Platform: Supports Unix (via
libc) and Windows (viawinapi) with optional dependencies.
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
For Windows support only:
[]
= { = "0.1.0", = false, = ["windows"] }
Milestones
The journey to create memsafe involved several key steps:
- Secure Memory Wrapper: Developed a Rust struct (
MemSafe) usingmprotect,mlock, andmadviseon Unix, andVirtualProtect,VirtualLockon Windows, ensuring data stays locked and inaccessible by default. - Naming the Crate: Brainstormed names like
MemVault,LockMem, and settled onmemsafefor its simplicity and clarity. - Cross-Platform Support: Made
libcandwinapioptional dependencies withunixandwindowsfeatures, defaulting to Unix for broad compatibility. - Licensing: Chose the MIT License to require attribution (
Copyright (c) 2025 Pouyan) while keeping it permissive. - SSH Configuration: Set up an SSH config using
pouyan.keyfor GitHub (github.com/po0uyan/memsafe), with a catch-all for other connections. - Publishing: Created the crate, initialized a Git repo, and published to crates.io with a streamlined workflow.
See the full story in the GitHub repository.
Repository
License
Licensed under the MIT License. See LICENSE for details.