1 个不稳定版本
新 0.1.1 | 2024 年 8 月 21 日 |
---|---|
0.1.0 |
|
#8 in #community
205 个月下载量
23KB
391 代码行数,不包括注释
社区 ALTCHA Rust 库
Altcha 库的 Rust 社区实现,用于您自己的服务器应用程序创建和验证挑战和响应。
有关 ALTCHA 的更多信息,请访问 https://altcha.org/docs
设置
[dependencies]
altcha-lib-rs = { version = "0", features = ["json"] }
示例
use altcha_lib_rs::{create_challenge, verify_json_solution,
Payload, Challenge, ChallengeOptions};
// create a challenge
let challenge = create_challenge(ChallengeOptions {
hmac_key: "super-secret",
expires: Some(Utc::now() + chrono::TimeDelta::minutes(1)),
..Default::default()
}).expect("should be ok");
// transmit the challenge to the client and let the clint solve it
let res = solve_challenge(&challenge.challenge, &challenge.salt, None, None, 0)
.expect("need to be solved");
// pack the solution into a json string
let payload = Payload {
algorithm: challenge.algorithm,
challenge: challenge.challenge,
number: res,
salt: challenge.salt,
signature: challenge.signature,
took: None,
};
let string_payload = serde_json::to_string(&payload).unwrap();
// receive the solution from the client and verify it
verify_json_solution(&string_payload, "super-secret", true).expect("should be verified");
查看 示例服务器
依赖项
~2–3MB
~61K SLoC