#verify #passport #sign #vouchers

wd_passport

发行和验证凭证

4个版本 (2个破坏性更新)

0.3.1 2023年3月27日
0.3.0 2023年3月27日
0.2.0 2023年2月13日
0.1.0 2023年2月7日

#34 in #sign

MIT/Apache

20MB
806

包含 (ELF库, 18MB) cdylib/libwd_passport.so, (Mach-o库, 2.5MB) cdylib/libwd_passport.dylib

护照

发行和验证凭证

示例

fn main() {
    let start = std::time::Instant::now();
    let result = call_dynamic().expect("运行出错");
    let use_time = start.elapsed();
    println!("success :{} 总用时:{}毫秒", result, use_time.as_millis());
}

fn call_dynamic() -> Result<u32, Box<dyn std::error::Error>> {
    unsafe {
        let start = std::time::Instant::now();
        let lib = libloading::Library::new("./src/libwd_passport.dylib")?;
        let sign_func: libloading::Symbol<
            unsafe extern "C" fn(
                data: *const c_char,
                timestamp: c_longlong,
                sign: *const c_char,
            ) -> c_int,
        > = lib.get(b"sign")?;
        let verify_func: libloading::Symbol<
            unsafe extern "C" fn(
                data: *const c_char,
                sign: *const c_char,
                timestamp: c_longlong,
            ) -> c_int,
        > = lib.get(b"verify")?;
        let use_time = start.elapsed();
        println!("启动用时:{}微秒", use_time.as_micros());

        let start = std::time::Instant::now();
        let data = CString::from_vec_unchecked(Vec::from("hello world"));
        let sign = CString::from_vec_unchecked(vec![1; 128]);
        let result = sign_func(data.as_ptr(), 1866248975, sign.as_ptr());
        assert_ne!(result,-1,"签名失败");
        let use_time = start.elapsed();
        println!("签名用时:{}微秒", use_time.as_micros());

        let start = std::time::Instant::now();
        let result = verify_func(data.as_ptr(), sign.as_ptr(), 1866248975);
        assert_ne!(result,-1,"验签失败");
        let use_time = start.elapsed();
        println!("验证用时:{}微秒", use_time.as_micros());

        return Ok(0);
    }
}

依赖项

~8MB
~135K SLoC