memsafe
A cross-platform Rust library for securely wrapping data in memory.
This is the official memsafe repository, hosted at https://github.com/po0uyan/memsafe, and published on crates.io at https://crates.io/crates/memsafe.
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.4"
For Windows support only:
[]
= { = "0.1.4", = 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
Security Notice
Please note that while memsafe is designed with security best practices in mind, it has not undergone a formal security audit yet. We encourage users to perform their own security assessment for their specific use cases. We are committed to maintaining and improving the security of this library.
License
Licensed under the MIT License. See LICENSE for details.
Contributing
Issues and pull requests are welcome at https://github.com/po0uyan/memsafe. I'll be more than happy to merge enhancements! security updates and any steps towards making software world a better place for everyone.