memsafe 0.1.4

A cross-platform Rust library for securely wrapping data in memory
Documentation

memsafe

A cross-platform Rust library for securely wrapping data in memory.

Crates.io License: MIT

memsafe locks sensitive data in memory, restricts access, and ensures secure cleanup—built from the ground up with simplicity and security in mind. 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::MemSafe;
let mut secret = MemSafe::new(String::from("secret")).unwrap();
secret.push_str(" data");
println!("Secure data: {}", secret);

Features

  • Memory Locking: Prevents swapping to disk using mlock (Unix) or VirtualLock (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 (via winapi) with optional dependencies.

Installation

Add to your Cargo.toml:

[dependencies]
memsafe = "0.1.4"

For Windows support only:

[dependencies]
memsafe = { version = "0.1.4", default-features = false, features = ["windows"] }

Milestones

The journey to create memsafe involved several key steps:

  1. Secure Memory Wrapper: Developed a Rust struct (MemSafe) using mprotect, mlock, and madvise on Unix, and VirtualProtect, VirtualLock on Windows, ensuring data stays locked and inaccessible by default.
  2. Naming the Crate: Brainstormed names like MemVault, LockMem, and settled on memsafe for its simplicity and clarity.
  3. Cross-Platform Support: Made libc and winapi optional dependencies with unix and windows features, defaulting to Unix for broad compatibility.
  4. Licensing: Chose the MIT License to require attribution (Copyright (c) 2025 Pouyan) while keeping it permissive.
  5. SSH Configuration: Set up an SSH config using pouyan.key for GitHub (github.com/po0uyan/memsafe), with a catch-all for other connections.
  6. 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.

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.