summary refs log tree commit diff
path: root/crypto/src/bcpg/BcpgOutputStream.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-01-23 14:05:18 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-01-23 14:05:18 +0700
commit48919250c89e0c6c435b226f5ea1d9076a195439 (patch)
treef2c64cbe7f253f8ced04a08ee0a115f3a3d0ddc1 /crypto/src/bcpg/BcpgOutputStream.cs
parentUse System.HashCode in a few places (diff)
downloadBouncyCastle.NET-ed25519-48919250c89e0c6c435b226f5ea1d9076a195439.tar.xz
Refactor some one-byte writes
Diffstat (limited to 'crypto/src/bcpg/BcpgOutputStream.cs')
-rw-r--r--crypto/src/bcpg/BcpgOutputStream.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/crypto/src/bcpg/BcpgOutputStream.cs b/crypto/src/bcpg/BcpgOutputStream.cs
index 5b53bb28d..bbbe486ce 100644
--- a/crypto/src/bcpg/BcpgOutputStream.cs
+++ b/crypto/src/bcpg/BcpgOutputStream.cs
@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Crypto.Utilities;
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
@@ -125,11 +126,18 @@ namespace Org.BouncyCastle.Bcpg
             }
             else
             {
+#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);
+                outStr.Write(buf);
+#else
                 outStr.WriteByte(0xff);
                 outStr.WriteByte((byte)(bodyLen >> 24));
                 outStr.WriteByte((byte)(bodyLen >> 16));
                 outStr.WriteByte((byte)(bodyLen >> 8));
                 outStr.WriteByte((byte)bodyLen);
+#endif
             }
         }
 
@@ -169,11 +177,18 @@ namespace Org.BouncyCastle.Bcpg
                     }
                     else
                     {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+                        Span<byte> buf = stackalloc byte[5];
+                        buf[0] = (byte)(hdr | 0x02);
+                        Pack.UInt32_To_BE((uint)bodyLen, buf, 1);
+                        this.Write(buf);
+#else
                         this.WriteByte((byte)(hdr | 0x02));
                         this.WriteByte((byte)(bodyLen >> 24));
                         this.WriteByte((byte)(bodyLen >> 16));
                         this.WriteByte((byte)(bodyLen >> 8));
                         this.WriteByte((byte)bodyLen);
+#endif
                     }
                 }
             }