Skip to content

Conversation

@nhatnghiho
Copy link
Contributor

Description of changes:

Implement enc CLI with the following options:

  • e
  • d
  • aes-128-cbc
  • K
  • in
  • out
  • iv

Testing:

Unit tests

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.

@nhatnghiho nhatnghiho requested a review from a team as a code owner December 3, 2025 17:38
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

uint8_t inbuf[1024];
bssl::UniquePtr<uint8_t> outbuf(
(uint8_t *)OPENSSL_zalloc(1024 + EVP_CIPHER_block_size(cipher)));
int inlen, outlen;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'inlen' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int inlen, outlen;
int inlen = 0, outlen;

uint8_t inbuf[1024];
bssl::UniquePtr<uint8_t> outbuf(
(uint8_t *)OPENSSL_zalloc(1024 + EVP_CIPHER_block_size(cipher)));
int inlen, outlen;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: variable 'outlen' is not initialized [cppcoreguidelines-init-variables]

Suggested change
int inlen, outlen;
int inlen, outlen = 0;

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2025

Codecov Report

❌ Patch coverage is 78.20513% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.21%. Comparing base (d6298ee) to head (4b0d8e6).

Files with missing lines Patch % Lines
tool-openssl/enc_test.cc 75.00% 33 Missing ⚠️
tool-openssl/enc.cc 82.35% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2877      +/-   ##
==========================================
- Coverage   78.22%   78.21%   -0.01%     
==========================================
  Files         683      685       +2     
  Lines      117441   117675     +234     
  Branches    16502    16537      +35     
==========================================
+ Hits        91870    92043     +173     
- Misses      24683    24745      +62     
+ Partials      888      887       -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.

Comment on lines +121 to +122
unsigned int iv_length = EVP_CIPHER_iv_length(cipher);
bssl::UniquePtr<uint8_t[]> iv((uint8_t *)OPENSSL_zalloc(EVP_MAX_IV_LENGTH));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you unconditionally allocate EVP_MAX_IV_LENGTH, why not make iv a stack value?

Comment on lines +171 to +174
uint8_t inbuf[BUF_SIZE];
bssl::UniquePtr<uint8_t[]> outbuf(
(uint8_t *)OPENSSL_zalloc(BUF_SIZE + EVP_CIPHER_block_size(cipher)));
int inlen = 0, outlen = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

NP: You could also keep outbuf on the stack as long as you assume a large enough block size. (I believe 16 is the largest block size we support.)

}
}

bssl::UniquePtr<uint8_t[]> key((uint8_t *)OPENSSL_zalloc(EVP_MAX_KEY_LENGTH));
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here, key can be a stack value if you're always allocating a constant size, EVP_MAX_KEY_LENGTH.

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