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

IP address support: Address code review comments #21

Merged
merged 5 commits into from
Jan 1, 2023

Conversation

ereslibre
Copy link
Contributor

  • Mimic std names IpAddr::V4, IpAddr::V6 for owned addresses, as well as IpAddrRef::V4, IpAddrRef::V6 for referenced ones. Also mimic the exception name, now named AddrParseError instead of InvalidIpAddressError.

  • Update copyright header on name.rs.

  • Reduce the number of allocations on ipv6_to_uncompressed_string used to print IPv6 addresses in their uncompressed form.

Other minor changes.

This addresses most of the feedback provided in #5 (review).

@ereslibre ereslibre mentioned this pull request Dec 30, 2022
3 tasks
@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2022

Codecov Report

Merging #21 (327e47f) into feat-ip-address (7573333) will decrease coverage by 0.32%.
The diff coverage is 88.29%.

@@                 Coverage Diff                 @@
##           feat-ip-address      #21      +/-   ##
===================================================
- Coverage            86.40%   86.07%   -0.33%     
===================================================
  Files                   15       15              
  Lines                 2375     2349      -26     
===================================================
- Hits                  2052     2022      -30     
- Misses                 323      327       +4     
Impacted Files Coverage Δ
src/lib.rs 100.00% <ø> (ø)
src/name/name.rs 29.62% <35.29%> (-0.38%) ⬇️
src/name/ip_address.rs 98.29% <92.54%> (-1.71%) ⬇️
src/name/verify.rs 34.00% <95.83%> (-2.24%) ⬇️
src/end_entity.rs 52.17% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ereslibre ereslibre changed the title Address code review comments IP address support: Address code review comments Dec 30, 2022
.map(|octet| format!("{:02x?}{:02x?}", octet[0], octet[1]))
.collect::<Vec<String>>()
.join(":")
format!(
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this is a fine solution. I might have gone with pre-allocating a String::with_capacity() and then using .write_fmt() to write into it in a loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no strong opinion on this one.

Copy link
Contributor Author

@ereslibre ereslibre Dec 30, 2022

Choose a reason for hiding this comment

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

What would you do with the Result when using write_fmt? ipv6_to_uncompressed_string is meant to be used on an impl From, so it cannot fail.

Copy link
Member

Choose a reason for hiding this comment

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

Just unwrap() it -- after all, format!() is actually doing the same thing and also doing something like unwrapping.

Copy link
Contributor Author

@ereslibre ereslibre Dec 31, 2022

Choose a reason for hiding this comment

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

Addressed in 81837a8bf2862df71a8e35f6f8d91dc4e2f5110f

cert.inner().subject_alt_name,
Err(Error::CertNotValidForName),
&|name| {
#[allow(clippy::single_match)]
Copy link
Member

Choose a reason for hiding this comment

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

Why not do if let GeneralName::IpAddress(presented_id) = name instead of the match with #[allow(clippy::single_match)]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

- Mimic std names `IpAddr::V4`, `IpAddr::V6` for owned addresses, as
well as `IpAddrRef::V4`, `IpAddrRef::V6` for referenced ones. Also
mimic the exception name, now named `AddrParseError` instead of
`InvalidIpAddressError`.

- Update copyright header on `name.rs`.

- Reduce the number of allocations on `ipv6_to_uncompressed_string`
used to print IPv6 addresses in their uncompressed form.

Other minor changes.
- Rename `DnsNameOrIpRef` to `SubjectNameRef`
- Rename `InvalidDnsNameOrIpError` to `InvalidSubjectNameError`
@ereslibre ereslibre force-pushed the rustls-feat-ip-address branch 2 times, most recently from f1b6d66 to fba17e2 Compare December 30, 2022 19:14
@ereslibre ereslibre requested a review from djc December 30, 2022 19:15
if dot_count != 3 {
return Err(AddrParseError);
}
Ok(IpAddrRef::V4(ip_address_, ipv4_octets(ip_address_)?))
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, no, I don't think this quite makes sense. Now we still have a routine that's parsing the data separately from the validation. The idea is that we accumulate the output as we validate it, so that the output accumulates from the validated data itself. So for example, in the same place where you currently move to the next octet, write into the output array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 541bc2b5826354db63292fff15bf7bb3b5a2827a.

src/name/name.rs Outdated
subject_name,
ip_address::ipv6_octets(subject_name).map_err(|_| InvalidSubjectNameError)?,
)));
if let Ok(ip_address) = ip_address::parse_ipv6_address(subject_name) {
Copy link
Member

Choose a reason for hiding this comment

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

Can do else if here.

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's a return-on-first-match situation, no need for it, but I will add it nevertheless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 416976f

@ereslibre ereslibre force-pushed the rustls-feat-ip-address branch 2 times, most recently from 1b24841 to 81837a8 Compare December 31, 2022 12:06
Parse, don't validate
Use `write_fmt` in order to reduce repetition of arguments when
formatting an IPv6 address.
Comment on lines 320 to 322
octets[octet] =
TryInto::<u8>::try_into(radix10_to_octet(&current_octet[..current_size]))
.expect("invalid character");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm adding these TryInto due to clippy being executed with -D clippy::as-conversions. If there is a better/more idiomatic way to shape this code I'm happy adapting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment applies to the rest of TryInto conversions in this commit.

@ctz ctz merged this pull request into rustls:feat-ip-address Jan 1, 2023
@ereslibre ereslibre deleted the rustls-feat-ip-address branch January 4, 2023 20:24
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.

4 participants