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

Improve Debug impls #13

Merged
merged 1 commit into from
Nov 28, 2023
Merged

Improve Debug impls #13

merged 1 commit into from
Nov 28, 2023

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 23, 2023

For Der and AlgorithmIdentifier, emit hex bytes rather than decimal digits separated by commas. The decimal output is impossible to read and challenging to convert into a better format. For example:

[ ... 105, 103, 105, 67, 101, 114, 116, 44, 32, 73, ... ]

Also, add a Debug bound on SignatureVerificationAlgorithm. This helps upstream implement Debug in a way that can list out which SignatureVerificationAlgorithms are in use.

This copies a technique we added to rustls in rustls/rustls#1040.

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@@ -481,7 +492,7 @@ impl From<Vec<u8>> for Der<'static> {

impl fmt::Debug for Der<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Der").field(&self.as_ref()).finish()
hex(f, self.as_ref())
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider leaving the Der(..) wrapping in? Why/why not?

Copy link
Member

Choose a reason for hiding this comment

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

I left this unchanged, both options seem reasonable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It winds up with multiple layers of wrapping in the Debug output, which gets kind of noisy. For instance, since CertificateDer is:

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CertificateDer<'a>(Der<'a>);

It would output as CertificateDer ( Der ( 03040506 ) ). To most readers the inner Der wrapping is an implementation detail and not that important. But I don't feel strongly about it.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough!

src/lib.rs Outdated Show resolved Hide resolved
@cpu
Copy link
Member

cpu commented Nov 28, 2023

I pushed a commit addressing most of the review feedback that can be squash merged.

@cpu
Copy link
Member

cpu commented Nov 28, 2023

that can be squash merged.

Ah, this repo only allows the merge queue. I'll squash it manually.

For Der and AlgorithmIdentifier, emit hex bytes rather than decimal
digits separated by commas. The decimal output is impossible to read and
challenging to convert into a better format. For example:

[ ... 105, 103, 105, 67, 101, 114, 116, 44, 32, 73, ... ]

Also, add a Debug bound on SignatureVerificationAlgorithm. This helps
upstream implement Debug in a way that can list out which
SignatureVerificationAlgorithms are in use.
@cpu cpu added this pull request to the merge queue Nov 28, 2023
Merged via the queue into rustls:main with commit af0db93 Nov 28, 2023
@jsha
Copy link
Contributor Author

jsha commented Nov 28, 2023

Thanks for picking up the review changes, @cpu!

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