summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-08 01:46:51 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-08 01:46:51 +0700
commit89a4ead3b8bfe966f6a89eaa5ced3105529efef5 (patch)
treec202b57b6b020f114d5d51788697eaebd14326bf
parentMore span variants in randomness classes (diff)
downloadBouncyCastle.NET-ed25519-89a4ead3b8bfe966f6a89eaa5ced3105529efef5.tar.xz
Span usage in Asn1RelativeOid
-rw-r--r--crypto/src/asn1/Asn1RelativeOid.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1RelativeOid.cs b/crypto/src/asn1/Asn1RelativeOid.cs

index d3c031913..a1997864d 100644 --- a/crypto/src/asn1/Asn1RelativeOid.cs +++ b/crypto/src/asn1/Asn1RelativeOid.cs
@@ -196,7 +196,11 @@ namespace Org.BouncyCastle.Asn1 internal static void WriteField(Stream outputStream, long fieldValue) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span<byte> result = stackalloc byte[9]; +#else byte[] result = new byte[9]; +#endif int pos = 8; result[pos] = (byte)((int)fieldValue & 0x7F); while (fieldValue >= (1L << 7)) @@ -204,7 +208,11 @@ namespace Org.BouncyCastle.Asn1 fieldValue >>= 7; result[--pos] = (byte)((int)fieldValue | 0x80); } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + outputStream.Write(result[pos..]); +#else outputStream.Write(result, pos, 9 - pos); +#endif } internal static void WriteField(Stream outputStream, BigInteger fieldValue) @@ -217,14 +225,24 @@ namespace Org.BouncyCastle.Asn1 else { BigInteger tmpValue = fieldValue; +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span<byte> tmp = byteCount <= 16 + ? stackalloc byte[byteCount] + : new byte[byteCount]; +#else byte[] tmp = new byte[byteCount]; +#endif for (int i = byteCount - 1; i >= 0; i--) { tmp[i] = (byte)(tmpValue.IntValue | 0x80); tmpValue = tmpValue.ShiftRight(7); } tmp[byteCount - 1] &= 0x7F; +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + outputStream.Write(tmp); +#else outputStream.Write(tmp, 0, tmp.Length); +#endif } }