summaryrefslogtreecommitdiffstats
path: root/vendor/digest/README.md
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/digest/README.md
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/digest/README.md')
-rw-r--r--vendor/digest/README.md44
1 files changed, 22 insertions, 22 deletions
diff --git a/vendor/digest/README.md b/vendor/digest/README.md
index 0a43d4751..9f68559cd 100644
--- a/vendor/digest/README.md
+++ b/vendor/digest/README.md
@@ -28,29 +28,29 @@ done with a minor version bump.
## Usage
-Let us demonstrate how to use crates in this repository using BLAKE2b as an
+Let us demonstrate how to use crates in this repository using Sha256 as an
example.
-First add `blake2` crate to your `Cargo.toml`:
+First add the `sha2` crate to your `Cargo.toml`:
```toml
[dependencies]
-blake2 = "0.8"
+sha2 = "0.10"
```
-`blake2` and other crates re-export `digest` crate and `Digest` trait for
+`sha2` and other crates re-export `digest` crate and `Digest` trait for
convenience, so you don't have to add `digest` crate as an explicit dependency.
Now you can write the following code:
```rust
-use blake2::{Blake2b, Digest};
+use sha2::{Sha256, Digest};
-let mut hasher = Blake2b::new();
+let mut hasher = Sha256::new();
let data = b"Hello world!";
-hasher.input(data);
+hasher.update(data);
// `input` can be called repeatedly and is generic over `AsRef<[u8]>`
-hasher.input("String data");
+hasher.update("String data");
// Note that calling `finalize()` consumes hasher
let hash = hasher.finalize();
println!("Result: {:x}", hash);
@@ -63,18 +63,18 @@ Alternatively you can use chained approach, which is equivalent to the previous
example:
```rust
-let hash = Blake2b::new()
- .chain(b"Hello world!")
- .chain("String data")
+let hash = Sha256::new()
+ .chain_update(b"Hello world!")
+ .chain_update("String data")
.finalize();
println!("Result: {:x}", hash);
```
-If the whole message is available you also can use convinience `digest` method:
+If the whole message is available you also can use convenience `digest` method:
```rust
-let hash = Blake2b::digest(b"my message");
+let hash = Sha256::digest(b"my message");
println!("Result: {:x}", hash);
```
@@ -84,11 +84,11 @@ If you want to hash data from [`Read`][3] trait (e.g. from file) you can rely on
implementation of [`Write`][4] trait (requires enabled-by-default `std` feature):
```rust
-use blake2::{Blake2b, Digest};
+use sha2::{Sha256, Digest};
use std::{fs, io};
let mut file = fs::File::open(&path)?;
-let mut hasher = Blake2b::new();
+let mut hasher = Sha256::new();
let n = io::copy(&mut file, &mut hasher)?;
let hash = hasher.finalize();
@@ -109,17 +109,17 @@ use digest::Digest;
// Instead use crates from: https://github.com/RustCrypto/password-hashing
fn hash_password<D: Digest>(password: &str, salt: &str, output: &mut [u8]) {
let mut hasher = D::new();
- hasher.input(password.as_bytes());
- hasher.input(b"$");
- hasher.input(salt.as_bytes());
+ hasher.update(password.as_bytes());
+ hasher.update(b"$");
+ hasher.update(salt.as_bytes());
output.copy_from_slice(hasher.finalize().as_slice())
}
-use blake2::Blake2b;
-use sha2::Sha256;
+let mut buf1 = [0u8; 32];
+let mut buf2 = [0u8; 64];
-hash_password::<Blake2b>("my_password", "abcd", &mut buf);
-hash_password::<Sha256>("my_password", "abcd", &mut buf);
+hash_password::<sha2::Sha256>("my_password", "abcd", &mut buf1);
+hash_password::<sha2::Sha512>("my_password", "abcd", &mut buf2);
```
If you want to use hash functions with trait objects, use `digest::DynDigest`