forked from aws/aws-lc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor md5 tool with dgst and fix stdin behavior (aws#1766)
Our original md5 stdin behavior was acting weird. The issue seems to be that we weren't actually parsing all of the input from `stdin`. ``` ❯ echo "test" | openssl md5 (stdin)= d8e8fca2dc0f896fd7cb4cb0031ba249 ❯ echo "test" | ./test_build_dir/tool-openssl/openssl md5 (stdin)= 098f6bcd4621d373cade4e832627b4f6 ``` The original implementation used `getline` which only reads one line. This worked with the original test since the file contents were sent into `stdin` with `<`, but this doesn't work correctly with other `stdin` behaviors such as `echo test | openssl md5`. The correct and more useful way to handle `stdin` is to read it from [the `0` file descriptor.](https://en.wikipedia.org/wiki/File_descriptor) This is how OpenSSL/BoringSSL reads from files. 1. This change fixes the behavior by rebuilding `md5` onto our `dgst` implementation. This is identical to how OpenSSL factors the specific hashing tool names. `md5` now uses `dgst` under the hood and inherits the file hashing behavior we implemented for `dgst hmac`. 2. `stdin` was missing from `dgst`, so that was implemented as well. `stdin` now works for both `openssl dgst -hmac ...` and `openssl md5`. Corresponding tests have also been added to verify. 3. Code was structured so that we can easily extend new digest support for the openssl tool with just a few lines. I considered adding it along with this PR, but didn't want to muddle it with the new logic. FIxed version: ``` ❯ echo "test_fix" | openssl md5 (stdin)= 1312e69e9dc6ec31b51af24fc42ebdea ❯ echo "test_fix" | ./test_build_dir/tool-openssl/openssl md5 (stdin)= 1312e69e9dc6ec31b51af24fc42ebdea ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
- Loading branch information
1 parent
0c52b12
commit 52d1651
Showing
9 changed files
with
220 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.