-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: System.Security.Cryptography.Oid should have a ToString() implementation #109366
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
There are some edge cases here that probably need to be considered. First, it is possible to have an using System;
using System.Security.Cryptography;
#pragma warning disable CA1416 // Validate platform compatibility
using ECDiffieHellmanCng ecdh = new(ECCurve.CreateFromFriendlyName("Curve25519"));
ECParameters p = ecdh.ExportParameters(false);
Console.WriteLine(p.Curve.Oid.FriendlyName);
Console.WriteLine(p.Curve.Oid.Value); On Windows, Curve25519 is a named-only curve and has no Value. Or more simply, just doing We could do something like this: public override string ToString()
{
return (Value, FriendlyName) switch
{
(string v, string f) => $"{v} ({f})",
(string v, null) => v,
(null, string f) => f,
(null, null) => string.Empty
};
} But it has a certain amount of ambiguity to the output that I don't love. Second, and this might be fixed now, is that touching |
Given that there are 4 possible output formats (as demonstrated by @vcsjones)... what are you hoping to do with this information? Basically, any runtime ToString() of this type is going to be problematic. A calling application/library should be looking at the constituent parts and handling |
This issue has been marked |
This issue has been automatically marked |
Background and motivation
The
ToString()
method of theOid
class currently always printsSystem.Security.Cryptography.Oid
which is pretty much useless.A nicer implementation would display the oid value and the friendly name if available.
API Proposal
API Usage
Alternative Designs
Not applicable.
Risks
Probably very low.
The text was updated successfully, but these errors were encountered: