summary refs log tree commit diff
path: root/crypto/src/crypto/io/SignerStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crypto/io/SignerStream.cs')
-rw-r--r--crypto/src/crypto/io/SignerStream.cs31
1 files changed, 23 insertions, 8 deletions
diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs
index e527e5450..78fa69363 100644
--- a/crypto/src/crypto/io/SignerStream.cs
+++ b/crypto/src/crypto/io/SignerStream.cs
@@ -1,5 +1,9 @@
 using System;
 using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Crypto.IO
 {
@@ -39,17 +43,15 @@ namespace Org.BouncyCastle.Crypto.IO
 #if NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
         public override void CopyTo(Stream destination, int bufferSize)
         {
-            if (m_readSigner == null)
-            {
-                m_stream.CopyTo(destination, bufferSize);
-            }
-            else
-            {
-                base.CopyTo(destination, bufferSize);
-            }
+            Streams.CopyTo(ReadSource, destination, bufferSize);
         }
 #endif
 
+        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
+        {
+            return Streams.CopyToAsync(ReadSource, destination, bufferSize, cancellationToken);
+        }
+
         public override void Flush()
         {
             m_stream.Flush();
@@ -90,6 +92,11 @@ namespace Org.BouncyCastle.Crypto.IO
 
             return n;
         }
+
+        public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
+        {
+            return Streams.ReadAsync(ReadSource, buffer, cancellationToken);
+        }
 #endif
 
         public override int ReadByte()
@@ -134,6 +141,11 @@ namespace Org.BouncyCastle.Crypto.IO
                 m_writeSigner.BlockUpdate(buffer);
             }
         }
+
+        public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
+        {
+            return Streams.WriteAsync(WriteDestination, buffer, cancellationToken);
+        }
 #endif
 
         public override void WriteByte(byte value)
@@ -154,5 +166,8 @@ namespace Org.BouncyCastle.Crypto.IO
             }
             base.Dispose(disposing);
         }
+
+        private Stream ReadSource => m_readSigner == null ? m_stream : this;
+        private Stream WriteDestination => m_writeSigner == null ? m_stream : this;
     }
 }