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

Convert.ToHexStringLower: lower variant for Convert.ToHexString #92483

Merged
merged 13 commits into from
Nov 20, 2023

Conversation

determ1ne
Copy link
Contributor

New methods:

namespace System
{
    public static class Convert
    {
        public static string ToHexStringLower(byte[] inArray);
        public static string ToHexStringLower(byte[] inArray, int offset, int length);
        public static string ToHexStringLower(ReadOnlySpan<byte> bytes);
    }
}

Close #60393.

TryToHexStringLower may be implemented after #86556 merged.

@dotnet-issue-labeler dotnet-issue-labeler bot added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners new-api-needs-documentation labels Sep 22, 2023
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Sep 22, 2023
@determ1ne
Copy link
Contributor Author

@dotnet-policy-service agree

@stephentoub
Copy link
Member

It'd be good to include in this PR updates to places elsewhere in the repo we can switch to using the new public API, e.g.

return HexConverter.ToString(hashBuffer.Slice(0, written), HexConverter.Casing.Lower);

@vcsjones
Copy link
Member

vcsjones commented Sep 22, 2023

The final approved API has additional overloads. See @bartonjs's comment here: #60393 (comment). It would be good to get TryToHexStringLower with the rest of them.

Nevermind I see that is addressed here:

TryToHexStringLower may be implemented after #86556 merged.

@vcsjones vcsjones added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 22, 2023
@ghost
Copy link

ghost commented Sep 22, 2023

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

New methods:

namespace System
{
    public static class Convert
    {
        public static string ToHexStringLower(byte[] inArray);
        public static string ToHexStringLower(byte[] inArray, int offset, int length);
        public static string ToHexStringLower(ReadOnlySpan<byte> bytes);
    }
}

Close #60393.

TryToHexStringLower may be implemented after #86556 merged.

Author: determ1ne
Assignees: -
Labels:

area-System.Runtime, new-api-needs-documentation, community-contribution

Milestone: -

@buyaa-n
Copy link
Contributor

buyaa-n commented Oct 22, 2023

It'd be good to include in this PR updates to places elsewhere in the repo we can switch to using the new public API, e.g.

return HexConverter.ToString(hashBuffer.Slice(0, written), HexConverter.Casing.Lower);

@determ1ne could you apply the feedback? In addition to above case, I see 5 hits in:

return new ActivityTraceId(HexConverter.ToString(idData, HexConverter.Casing.Lower));
and one hit in:

Otherwise, the PR looks good, thank you!

@adamsitnik adamsitnik added the needs-author-action An issue or pull request that requires more info or actions from the author. label Oct 27, 2023
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Oct 28, 2023
@determ1ne
Copy link
Contributor Author

@stephentoub, @buyaa-n I tried to patch all HexConverter.ToString to Convert.ToHexString or Convert.ToHexStringLower, please check if the new commit is appropriate.

@buyaa-n
Copy link
Contributor

buyaa-n commented Oct 30, 2023

@stephentoub, @buyaa-n I tried to patch all HexConverter.ToString to Convert.ToHexString or Convert.ToHexStringLower, please check if the new commit is appropriate.

Thanks, looks good to me, you have got a conflict in src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicTlsSecret.cs

Close #60393.

TryToHexStringLower may be implemented after #86556 merged.

This should be contributing to #60393 not closing, should be closed when TryToHexStringLower implemented

@adamsitnik adamsitnik added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 2, 2023
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 14, 2023
@determ1ne
Copy link
Contributor Author

@buyaa-n I've implemented Convert.TryToHexStringLower and the commits were rebased.

Comment on lines +723 to +733
#if NET5_0_OR_GREATER
internal static string EncodeHexString(byte[] sArray)
{
return Convert.ToHexString(sArray);
}
#else
internal static string EncodeHexString(byte[] sArray)
{
return HexConverter.ToString(sArray);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem need an if-def, it was added same time as Convert.ToHexString(...) added, was it failing in other builds?

Suggested change
#if NET5_0_OR_GREATER
internal static string EncodeHexString(byte[] sArray)
{
return Convert.ToHexString(sArray);
}
#else
internal static string EncodeHexString(byte[] sArray)
{
return HexConverter.ToString(sArray);
}
#endif
internal static string EncodeHexString(byte[] sArray)
{
return Convert.ToHexString(sArray);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From nuget the System.Security.Cryptography.Xml 8.0.0 package is still targeting .net framework, while Convert.ToHexString is added in net5.0, so I'm not sure if it will build (or works).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please check the CI result https://github.com/dotnet/runtime/pull/92483/checks?check_run_id=18807551051 , removing the if-def will fail the build.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for checking, the file doesn't included in .netframework build, probably failing on netstandard

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

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

LGMT, thank you @determ1ne ,

The failure unrelated and known.

@buyaa-n buyaa-n merged commit b80a4fd into dotnet:main Nov 20, 2023
174 of 176 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add lowercase support for Convert.ToHexString
6 participants