-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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]: PemEncoding.WriteString #65144
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue DetailsBackground and motivationFor a reason I no longer recall,
When implementing the PEM exports, this pretty much meant every time I would have preferred to use API ProposalSince we can't change the return type... namespace System.Security.Cryptography {
public static class PemEncoding {
public string WriteString(ReadOnlySpan<char> label, ReadOnlySpan<byte> data);
}
} API UsageUsing Lines 1156 to 1168 in cf35d12
Would become: public string ExportCertificatePem()
{
return PemEncoding.WriteString(PemLabels.X509Certificate, RawDataMemory.Span);
} Alternative DesignsNo response RisksNo response
|
Branch with implementation main...vcsjones:writestring-impl |
Looks good as proposed namespace System.Security.Cryptography {
public static class PemEncoding {
public static string WriteString(ReadOnlySpan<char> label, ReadOnlySpan<byte> data);
}
} |
Background and motivation
For a reason I no longer recall,
PemEncoding.Write
returnschar[]
. I think nearly all of the time, folks that choose to use the allocating version (as apposed toTryWrite
) want a string, not achar[]
. That meansPemEncoding.Write(...)
to benew string(PemEncoding.Write(...))
.ReadOnlySpan<byte>
of data, getting aReadOnlySpan<T>
into the callback ofstring.Create
currently requires unsafe code, so this starts becoming a little more than trivial. So developers don't have an easy way to do just the allocation once.When implementing the PEM exports, this pretty much meant every time I would have preferred to use
Write
meant I actually had to useTryWrite
in combination withGetEncodedSize
andstring.Create
.API Proposal
Since we can't change the return type...
API Usage
Using
ExportCertificatePem
as an example:runtime/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs
Lines 1156 to 1168 in cf35d12
Would become:
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: