crypt3-sys 0.1.0

musl crypt3
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 105.82 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 479.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 27s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • pldubouilh/crypt3-sys
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pldubouilh

crypt3-sys

statically linkable bindings against locally pulled crypt(3) from musl.

crate.io

use std::ffi::{CString, CStr};

fn main() {
    let password = "mypassword";
    let sha256_setting = "$5$";
    let salt = "rDxsrps6AeTwJLRK";
    let settings = format!("{sha256_setting}{salt}");

    let mut output = vec![0_i8; 256];

    let ret_str = unsafe {
        let csetting = CString::new(settings).unwrap();
        let cpassword = CString::new(password).unwrap();

        let _ret = crypt3_sys::crypt_r(cpassword.as_ptr(), csetting.as_ptr(), output.as_mut_ptr());

        let ret_cstr = CStr::from_ptr(output.as_ptr());
        ret_cstr.to_str().unwrap()
    };

    // mkpasswd -m sha256crypt "mypassword"
    // $5$rDxsrps6AeTwJLRK$CHafsXkpg6bi5Z.kdTYhlWzmhqe9Q.RRPm0LWi/bckC

    let ret_assumed = format!(
        "{}{}${}",
        sha256_setting, salt, "CHafsXkpg6bi5Z.kdTYhlWzmhqe9Q.RRPm0LWi/bckC"
    );
    assert!(ret_str == ret_assumed);

    println!("ret_str {ret_str:?}");
}