Skip to content

Commit

Permalink
Fix issue rust-lang-nursery#573 - hmac example (rust-lang-nursery#574)
Browse files Browse the repository at this point in the history
* Update hmac example for ring v. ^0.16.9

* Update hmac example for ring v. ^0.16.9

* Update hmac example for ring v. ^0.16.9

* Update to ring 0.16.11 in Cargo.toml

* Update to SHA256 - sect. 4.1 explicit threads

* Update all to SHA256, including comments
  • Loading branch information
quaesaevum authored Mar 1, 2020
1 parent dddb1a9 commit 05b2fcb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rand = "0.6"
rayon = "1.0"
regex = "1.0"
reqwest = "0.9"
ring = "0.13.0-alpha"
ring = "0.16.11"
rusqlite = { version = "0.16", features = ["chrono"] }
same-file = "1.0"
select = "0.4"
Expand Down
10 changes: 5 additions & 5 deletions src/concurrency/thread/threadpool-walk.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Calculate SHA1 sum of iso files concurrently
## Calculate SHA256 sum of iso files concurrently

[![threadpool-badge]][threadpool] [![num_cpus-badge]][num_cpus] [![walkdir-badge]][walkdir] [![ring-badge]][ring] [![cat-concurrency-badge]][cat-concurrency][![cat-filesystem-badge]][cat-filesystem]

This example calculates the SHA1 for every file with iso extension in the
This example calculates the SHA256 for every file with iso extension in the
current directory. A threadpool generates threads equal to the number of cores
present in the system found with [`num_cpus::get`]. [`Walkdir::new`] iterates
the current directory and calls [`execute`] to perform the operations of reading
and computing SHA1 hash.
and computing SHA256 hash.

```rust,no_run
extern crate walkdir;
Expand All @@ -20,7 +20,7 @@ use std::io::{BufReader, Read, Error};
use std::path::Path;
use threadpool::ThreadPool;
use std::sync::mpsc::channel;
use ring::digest::{Context, Digest, SHA1};
use ring::digest::{Context, Digest, SHA256};
# // Verify the iso extension
# fn is_iso(entry: &Path) -> bool {
Expand All @@ -32,7 +32,7 @@ use ring::digest::{Context, Digest, SHA1};
fn compute_digest<P: AsRef<Path>>(filepath: P) -> Result<(Digest, P), Error> {
let mut buf_reader = BufReader::new(File::open(&filepath)?);
let mut context = Context::new(&SHA1);
let mut context = Context::new(&SHA256);
let mut buffer = [0; 1024];
loop {
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/hashing/hmac.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Uses [`ring::hmac`] to creates a [`hmac::Signature`] of a string then verifies t
```rust
extern crate ring;

use ring::{digest, hmac, rand};
use ring::{hmac, rand};
use ring::rand::SecureRandom;
use ring::error::Unspecified;

fn main() -> Result<(), Unspecified> {
let mut key_value = [0u8; 48];
let rng = rand::SystemRandom::new();
rng.fill(&mut key_value)?;
let key = hmac::SigningKey::new(&digest::SHA256, &key_value);
let key = hmac::Key::new(hmac::HMAC_SHA256, &key_value);

let message = "Legitimate and important message.";
let signature = hmac::sign(&key, message.as_bytes());
hmac::verify_with_own_key(&key, message.as_bytes(), signature.as_ref())?;
hmac::verify(&key, message.as_bytes(), signature.as_ref())?;

Ok(())
}
Expand Down

0 comments on commit 05b2fcb

Please sign in to comment.