Skip to content

Commit

Permalink
docs: reformat the config example (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored Feb 24, 2024
1 parent 2744ff6 commit 00e28a3
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,40 @@ fn main() {
}
};

if let Ok(device) = cr_client.find_device() {
println!(
"Vendor ID: {:?} Product ID {:?}",
device.vendor_id, device.product_id
);
let device = match cr_client.find_device() {
Ok(d) => d,
Err(e) => {
eprintln!("Device not found: {}", e.to_string());
return;
}
};

let config = Config::new_from(device).set_command(Command::Configuration2);
println!(
"Vendor ID: {:?} Product ID {:?}",
device.vendor_id, device.product_id
);

let mut rng = thread_rng();
let config = Config::new_from(device)
.set_command(Command::Configuration2);

// Secret must have 20 bytes
// Used rand here, but you can set your own secret: let secret: &[u8; 20] = b"my_awesome_secret_20";
let secret: Vec<u8> = rng.sample_iter(&Alphanumeric).take(20).collect();
let hmac_key: HmacKey = HmacKey::from_slice(&secret);
let mut rng = thread_rng();

let mut device_config = DeviceModeConfig::default();
device_config.challenge_response_hmac(&hmac_key, false, false);
// Secret must have 20 bytes
// Used rand here, but you can set your own secret:
// let secret: &[u8; 20] = b"my_awesome_secret_20";
let secret: Vec<u8> =
rng.sample_iter(&Alphanumeric).take(20).collect();
let hmac_key: HmacKey = HmacKey::from_slice(&secret);

if let Err(err) = cr_client.write_config(config, &mut device_config) {
println!("{:?}", err);
} else {
println!("Device configured");
}
let mut device_config = DeviceModeConfig::default();
device_config.challenge_response_hmac(&hmac_key, false, false);

if let Err(err) =
cr_client.write_config(config, &mut device_config)
{
println!("{:?}", err);
} else {
println!("Device not found");
println!("Device configured");
}
}
```
Expand Down

0 comments on commit 00e28a3

Please sign in to comment.