Skip to content

Commit

Permalink
docs: mark readme examples as Rust snippets (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored Aug 30, 2024
1 parent 825c886 commit ea22878
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ challenge_response = "0"
If you are using a YubiKey, you can configure the HMAC-SHA1 Challenge-Response
with the [Yubikey Personalization GUI](https://developers.yubico.com/yubikey-personalization-gui/).

```rust
```rust,ignore
extern crate challenge_response;
extern crate hex;
Expand Down Expand Up @@ -99,7 +99,7 @@ fn main() {
Note, please read about the [initial configuration](https://wiki.archlinux.org/index.php/yubikey#Initial_configuration)
Alternatively you can configure the yubikey with the official [Yubikey Personalization GUI](https://developers.yubico.com/yubikey-personalization-gui/).

```ignore
```rust,ignore
extern crate challenge_response;
extern crate rand;
Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,38 @@ impl ChallengeResponse {
Ok(block)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_find_device() {
let mut cr_client = match ChallengeResponse::new() {
Ok(c) => c,
Err(e) => {
eprintln!("{:?}", e);
return;
}
};

if let Err(e) = cr_client.find_device() {
assert!(matches!(e, ChallengeResponseError::DeviceNotFound));
};
}

#[test]
fn test_find_all_devices() {
let mut cr_client = match ChallengeResponse::new() {
Ok(c) => c,
Err(e) => {
eprintln!("{:?}", e);
return;
}
};

if let Err(e) = cr_client.find_all_devices() {
assert!(matches!(e, ChallengeResponseError::DeviceNotFound));
};
}
}

0 comments on commit ea22878

Please sign in to comment.