diff options
Diffstat (limited to 'crypto/src/bcpg/SignatureSubpacket.cs')
-rw-r--r-- | crypto/src/bcpg/SignatureSubpacket.cs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/crypto/src/bcpg/SignatureSubpacket.cs b/crypto/src/bcpg/SignatureSubpacket.cs index f7f82b2a6..12c74bd6e 100644 --- a/crypto/src/bcpg/SignatureSubpacket.cs +++ b/crypto/src/bcpg/SignatureSubpacket.cs @@ -1,5 +1,7 @@ +using System; using System.IO; +using Org.BouncyCastle.Crypto.Utilities; using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Bcpg @@ -50,35 +52,31 @@ namespace Org.BouncyCastle.Bcpg { int bodyLen = data.Length + 1; - if (isLongLength) + if (isLongLength || bodyLen > 8383) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span<byte> buf = stackalloc byte[5]; + buf[0] = 0xFF; + Pack.UInt32_To_BE((uint)bodyLen, buf, 1); + os.Write(buf); +#else os.WriteByte(0xff); os.WriteByte((byte)(bodyLen >> 24)); os.WriteByte((byte)(bodyLen >> 16)); os.WriteByte((byte)(bodyLen >> 8)); os.WriteByte((byte)bodyLen); +#endif + } + else if (bodyLen < 192) + { + os.WriteByte((byte)bodyLen); } else { - if (bodyLen < 192) - { - os.WriteByte((byte)bodyLen); - } - else if (bodyLen <= 8383) - { - bodyLen -= 192; - - os.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192)); - os.WriteByte((byte)bodyLen); - } - else - { - os.WriteByte(0xff); - os.WriteByte((byte)(bodyLen >> 24)); - os.WriteByte((byte)(bodyLen >> 16)); - os.WriteByte((byte)(bodyLen >> 8)); - os.WriteByte((byte)bodyLen); - } + bodyLen -= 192; + + os.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192)); + os.WriteByte((byte)bodyLen); } if (critical) |