Thanks !
The output matches with sha256sum lorem_ipsum.txt
Edit:
var hashed_writer: std.Io.Writer.Hashing(std.crypto.hash.sha2.Sha256) = .init(&buf); also works.
Whats the use case of .initHasher ?
Thanks !
The output matches with sha256sum lorem_ipsum.txt
Edit:
var hashed_writer: std.Io.Writer.Hashing(std.crypto.hash.sha2.Sha256) = .init(&buf); also works.
Whats the use case of .initHasher ?
.init is implemented like this:
pub fn init(buffer: []u8) @This() {
return .initHasher(.init(.{}), buffer);
}
So itās initializing the underlying hasher with default options (.{}). Some hashers support extra options to configure the behavior; if you want to use one of those with different options, you would need .initHasher.
Apologies is this is obvious / barking up the wrong tree. Your echo and printf commands are hashing the file name, not the file contents. You probably want something like cat lorem_ipsum.txt | sha256sum.
Just sha256sum lorem_ipsum.txt is enough. Thatās how Iām confirming my functions work
Yes, absolutely. I was just pointing out the difference between echoing / printfing a file name, which give you just the name, and cating a file name, which gives you the contents.
That was an oversight - I ran the program first, followed by sha256sum on the file, and after seeing that their outputs didnāt match, I ran echo and printf (because bad decision making) to see if their output matches.
(I also ran echo without -n which gave a different hash, but didnāt post the output here).
sha256sum lorem_ipsum.txt and cat lorem_ipsum.txt | sha256sum are right.
Small aside: options to echo are non-portable (see the POSIX specification for the echo utility, which doesnāt mandate any options). Always use printf when you need anything fancier than the base ārepeat the arguments to stdoutā functionality.
Adding to this: use printf "%s" "THE THING YOU WANT PRINTED", otherwise you risk the thing youāre trying to print having % formatting escape sequences.