diff options
Diffstat (limited to 'crypto/src/bcpg/UserAttributeSubpacket.cs')
-rw-r--r-- | crypto/src/bcpg/UserAttributeSubpacket.cs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/crypto/src/bcpg/UserAttributeSubpacket.cs b/crypto/src/bcpg/UserAttributeSubpacket.cs index 05f60ac17..246ac0759 100644 --- a/crypto/src/bcpg/UserAttributeSubpacket.cs +++ b/crypto/src/bcpg/UserAttributeSubpacket.cs @@ -1,6 +1,7 @@ using System; using System.IO; +using Org.BouncyCastle.Crypto.Utilities; using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Bcpg @@ -43,23 +44,30 @@ namespace Org.BouncyCastle.Bcpg { int bodyLen = data.Length + 1; - if (bodyLen < 192 && !longLength) + if (longLength || 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 <= 8383 && !longLength) + else if (bodyLen < 192) { - 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)); + bodyLen -= 192; + + os.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192)); os.WriteByte((byte)bodyLen); } |