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

Small performance cleanup in S.S.Cryptography #70847

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
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 @@ -31,7 +31,7 @@ public virtual void DecodeX509KeyUsageExtension(byte[] encoded, out X509KeyUsage

try
{
AsnReader reader = new AsnReader(encoded, AsnEncodingRules.BER);
AsnValueReader reader = new AsnValueReader(encoded, AsnEncodingRules.BER);
keyUsagesAsn = reader.ReadNamedBitListValue<KeyUsageFlagsAsn>();
reader.ThrowIfNotEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected override AsymmetricAlgorithm LoadKey(ReadOnlyMemory<byte> pkcs8)

if (bytesRead != pkcs8.Length)
{
key.Dispose();
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected override PublicKey BuildPublicKey()
internal static PublicKey BuildPublicKey(RSA rsa)
{
Oid oid = Oids.RsaOid;
ReadOnlySpan<byte> asnNull = new byte[] { 0x05, 0x00 };

// The OID is being passed to everything here because that's what
// X509Certificate2.PublicKey does.
Expand All @@ -39,7 +40,7 @@ internal static PublicKey BuildPublicKey(RSA rsa)
//
// This is due to one version of the ASN.1 not including OPTIONAL, and that was
// the version that got predominately implemented for RSA. Now it's convention.
new AsnEncodedData(oid, stackalloc byte[] { 0x05, 0x00 }),
new AsnEncodedData(oid, asnNull),
bartonjs marked this conversation as resolved.
Show resolved Hide resolved
new AsnEncodedData(oid, rsa.ExportRSAPublicKey()));
}

Expand Down