Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example of calculating the SHA-256 digest of a file using ring #257

Closed
wants to merge 2 commits into from

Conversation

Projects
None yet
2 participants
@luser
Copy link
Contributor

luser commented Jul 28, 2017

Hopefully this looks sensible! I put it in basics because I didn't know where else to put it.

@luser luser referenced this pull request Jul 28, 2017

Closed

cookbook ideas for ring crate #213

3 of 3 tasks complete
@budziq
Copy link
Collaborator

budziq left a comment

@luser that's an excellent example!
Just some minor suggestions.

@@ -773,6 +831,8 @@ fn run() -> Result<()> {
[bitflags]: https://docs.rs/bitflags/
[byteorder-badge]: https://badge-cache.kominick.com/crates/v/byteorder.svg?label=byteorder
[byteorder]: https://docs.rs/byteorder/
[data-encoding-badge]: https://badge-cache.kominick.com/crates/v/data-encoding.svg?label=data-encoding
[data-encoding]: https://github.com/ia0/data-encoding

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

please copy the same link as the one in encoding.md

@@ -553,7 +553,7 @@ fn run() -> Result<()> {
[base64-badge]: https://badge-cache.kominick.com/crates/v/base64.svg?label=base64
[base64]: https://docs.rs/base64/
[data-encoding-badge]: https://badge-cache.kominick.com/crates/v/data-encoding.svg?label=data-encoding
[data-encoding]: https://github.com/ia0/data-encoding
[data-encoding]: https://docs.rs/data-encoding/

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

👍

```rust
# #[macro_use]
# extern crate error_chain;

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

please add one more # on the begining of line here so we don't have weird empty lines in final output

use ring::digest::{Context, SHA256};
use std::fs::File;
use std::io::{BufReader, Read, Write};

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

please add one more # on the begining of line here so we don't have weird empty lines in final output

let mut reader = BufReader::new(input);
let mut context = Context::new(&SHA256);
loop {

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

Normally I would go with extracting the reading looping and digest into a yet another function taking io::Read and returning Result.
But Its perfect as it is so I'll leave it up to you.

This comment has been minimized.

@luser

luser Jul 28, 2017

Author Contributor

That's a great suggestion, I factored out a sha256_digest_from_read function which is a bit more copy-paste friendly, which I assume is part of the point of the cookbook. :)

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

Nice 👍 my thoughts exactly!

[![ring-badge]][ring] [![data-encoding-badge]][data-encoding] [![cat-filesystem-badge]][cat-filesystem]
Writes some data to a file, then calculates the SHA-256 digest of

This comment has been minimized.

@budziq

budziq Jul 28, 2017

Collaborator

I would probably changed "digest" to linked Digest.

@budziq

This comment has been minimized.

Copy link

budziq commented on src/basics.md in 4fa2a98 Jul 28, 2017

Excellent ❤️
The only change that I would make here would be to change

[digest]

to

[`Digest`]

as it is a linked identifier as opposed to normal link

But I can change it after merging (once I'm back from holidays in 2days)

@budziq

This comment has been minimized.

Copy link
Collaborator

budziq commented Jul 29, 2017

@luser nicely done. Merged with some minor edits

@budziq budziq closed this Jul 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.