mirror of
https://github.com/jmic/altcha-lib-rs.git
synced 2026-01-25 04:16:40 +00:00
add readme
This commit is contained in:
@@ -5,6 +5,7 @@ edition = "2021"
|
||||
authors = ["jmic <jmic@users.noreply.github.com>"]
|
||||
description = "Community implementation of the Altcha library in Rust for your own server applications to create and validate challenges and responses."
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
44
README.md
Normal file
44
README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Community ALTCHA Rust Library   [](https://github.com/jmic/altcha-lib-rs/actions/workflows/build-and-test.yml)
|
||||
|
||||
**Community implementation of the Altcha library in Rust for your
|
||||
own server applications to create and validate challenges and responses.**
|
||||
|
||||
---
|
||||
|
||||
## Setup
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
altcha-lib-rs = { version = "1.0", features = ["json"] }
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```rust
|
||||
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");
|
||||
```
|
||||
Reference in New Issue
Block a user