未验证 提交 3b1a36e5 编写于 作者: K Kevin Jones 提交者: GitHub

Small performance cleanups in S.S.Cryptography

上级 d940a01a
......@@ -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();
}
......
......@@ -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);
}
......
......@@ -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.
......@@ -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()));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册