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

Implement BIO_dump #2331

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Implement BIO_dump #2331

wants to merge 3 commits into from

Conversation

kingstjo
Copy link
Contributor

Issues:

Addresses #CryptoAlg-3030

Description of changes:

Implemented BIO_dump() function in AWS-LC, matching OpenSSL 1.1.1's functionality. This function enables hexadecimal dumping of data through the BIO interface, providing compatibility for applications that rely on this OpenSSL API.

  • Uses existing hexdump infrastructure in crypto/bio/hexdump.c
  • Maintains OpenSSL 1.1.1 API compatibility
  • Returns total bytes written to match OpenSSL behavior

Call-outs:

  • Function maintains compatibility with OpenSSL 1.1.1 API specification
  • Returns total bytes written, matching OpenSSL's behavior

Testing:

Added test in crypto/bio/bio_test.cc

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.

@kingstjo kingstjo requested a review from a team as a code owner April 11, 2025 02:03
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.80%. Comparing base (eafd940) to head (78907d6).

Files with missing lines Patch % Lines
crypto/bio/hexdump.c 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2331      +/-   ##
==========================================
+ Coverage   78.76%   78.80%   +0.04%     
==========================================
  Files         620      620              
  Lines      107861   107874      +13     
  Branches    15319    15322       +3     
==========================================
+ Hits        84953    85012      +59     
+ Misses      22252    22205      -47     
- Partials      656      657       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


// BIO_dump should return an estimate of bytes written
int ret = BIO_dump(bio.get(), data, sizeof(data));
ASSERT_GT(ret, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this assertion more specific.

ASSERT_EQ(ret, 80);

Comment on lines +1268 to +1269
ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len));
std::string output(reinterpret_cast<const char *>(contents), len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also make an assertion about the value of len. Should it return a value equal to (or greater than) the value returned above?

Comment on lines +202 to +207
if (!BIO_hexdump(bio, (const uint8_t *)data, (size_t)len, 0)) {
return -1;
}

// Return estimate of bytes written (each line is ~80 bytes)
return ((len + 15) / 16) * 80;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of needing to estimate how many bytes were written, this could be exact. Why not modify hexdump_write above to return the actual number of bytes written (just bump a counter on each of its calls to BIO_write), call hexdump_write directly instead of calling it via BIO_hexdump, then return whatever value it returns?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants