From 7699428eb4416a52ae9a529c133839b2fd989903 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 5 Oct 2022 15:44:48 +0700 Subject: Various span usages --- crypto/src/openpgp/PgpPublicKey.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crypto/src/openpgp') diff --git a/crypto/src/openpgp/PgpPublicKey.cs b/crypto/src/openpgp/PgpPublicKey.cs index 09c8b9743..6d5f35018 100644 --- a/crypto/src/openpgp/PgpPublicKey.cs +++ b/crypto/src/openpgp/PgpPublicKey.cs @@ -507,7 +507,17 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { ECPublicBcpgKey ecK = (ECPublicBcpgKey)publicPk.Key; X9ECParameters x9 = ECKeyPairGenerator.FindECCurveByOid(ecK.CurveOid); - ECPoint q = x9.Curve.DecodePoint(BigIntegers.AsUnsignedByteArray(ecK.EncodedPoint)); + BigInteger encodedPoint = ecK.EncodedPoint; + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + int encodingLength = BigIntegers.GetUnsignedByteLength(encodedPoint); + Span encoding = stackalloc byte[encodingLength]; + BigIntegers.AsUnsignedByteArray(encodedPoint, encoding); + ECPoint q = x9.Curve.DecodePoint(encoding); +#else + ECPoint q = x9.Curve.DecodePoint(BigIntegers.AsUnsignedByteArray(encodedPoint)); +#endif + return new ECPublicKeyParameters(algorithm, q, ecK.CurveOid); } -- cgit 1.4.1