Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd an example of calculating the SHA-256 digest of a file using ring #257
Conversation
budziq
added
easy
example
claimed
labels
Jul 28, 2017
budziq
requested changes
Jul 28, 2017
| @@ -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.
This comment has been minimized.
| @@ -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.
This comment has been minimized.
| ```rust | ||
| # #[macro_use] | ||
| # extern crate error_chain; | ||
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
| [![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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
budziq
commented on src/basics.md in 4fa2a98
Jul 28, 2017
|
Excellent [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) |
This comment has been minimized.
This comment has been minimized.
|
@luser nicely done. Merged with some minor edits |
luser commentedJul 28, 2017
Hopefully this looks sensible! I put it in basics because I didn't know where else to put it.