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

Avoid allocating an array in AppleCertificatePal #55109

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Internal.Cryptography.Pal
internal sealed partial class AppleCertificatePal : ICertificatePal
{
// Byte representation of "-----BEGIN "
private static byte[] pemBegin = new byte[] { 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20 };
private static ReadOnlySpan<byte> PemBegin => new byte[] { 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20 };

internal delegate bool DerCallback(ReadOnlySpan<byte> derData, X509ContentType contentType);

Expand All @@ -30,7 +30,7 @@ internal static bool TryDecodePem(ReadOnlySpan<byte> rawData, DerCallback derCal
// Look for the PEM marker. This doesn't guarantee it will be a valid PEM since we don't check whether
// the marker is at the beginning of line or whether the line is a complete marker. It's just a quick
// check to avoid conversion from bytes to characters if the content is DER encoded.
if (rawData.IndexOf(pemBegin) < 0)
if (rawData.IndexOf(PemBegin) < 0)
{
return false;
}
Expand Down