Skip to content

Commit

Permalink
Small performance cleanups in S.S.Cryptography
Browse files Browse the repository at this point in the history
  • Loading branch information
vcsjones authored Jun 17, 2022
1 parent d940a01 commit 3b1a36e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
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),
new AsnEncodedData(oid, rsa.ExportRSAPublicKey()));
}

Expand Down

0 comments on commit 3b1a36e

Please sign in to comment.