diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 14:44:47 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-11 14:44:47 +0700 |
commit | fd335142a7a492509dda827ee2b6507a651560b8 (patch) | |
tree | 4b8895243d11a29e50ffa3c869ad1507c7358cf0 | |
parent | X509: Signature checks that return bool (diff) | |
download | BouncyCastle.NET-ed25519-fd335142a7a492509dda827ee2b6507a651560b8.tar.xz |
Platform guards for Stream code
-rw-r--r-- | crypto/src/crypto/io/CipherStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/crypto/io/DigestStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/crypto/io/MacStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/crypto/io/SignerStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/tls/TlsStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/Platform.cs | 10 | ||||
-rw-r--r-- | crypto/src/util/io/BaseInputStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/io/BaseOutputStream.cs | 6 | ||||
-rw-r--r-- | crypto/src/util/io/FilterStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/io/PushbackStream.cs | 4 | ||||
-rw-r--r-- | crypto/src/util/io/Streams.cs | 6 |
11 files changed, 53 insertions, 1 deletions
diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs index 5367640c6..3ae828664 100644 --- a/crypto/src/crypto/io/CipherStream.cs +++ b/crypto/src/crypto/io/CipherStream.cs @@ -2,7 +2,9 @@ using System; using System.Diagnostics; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.IO; @@ -61,10 +63,12 @@ namespace Org.BouncyCastle.Crypto.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(ReadSource, destination, bufferSize, cancellationToken); } +#endif public override void Flush() { diff --git a/crypto/src/crypto/io/DigestStream.cs b/crypto/src/crypto/io/DigestStream.cs index 56e674389..7508acb0f 100644 --- a/crypto/src/crypto/io/DigestStream.cs +++ b/crypto/src/crypto/io/DigestStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif using Org.BouncyCastle.Utilities.IO; @@ -47,10 +49,12 @@ namespace Org.BouncyCastle.Crypto.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(ReadSource, destination, bufferSize, cancellationToken); } +#endif public override void Flush() { diff --git a/crypto/src/crypto/io/MacStream.cs b/crypto/src/crypto/io/MacStream.cs index 49e207186..5e1c00f40 100644 --- a/crypto/src/crypto/io/MacStream.cs +++ b/crypto/src/crypto/io/MacStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif using Org.BouncyCastle.Utilities.IO; @@ -47,10 +49,12 @@ namespace Org.BouncyCastle.Crypto.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(ReadSource, destination, bufferSize, cancellationToken); } +#endif public override void Flush() { diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs index 78fa69363..24bfd305e 100644 --- a/crypto/src/crypto/io/SignerStream.cs +++ b/crypto/src/crypto/io/SignerStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif using Org.BouncyCastle.Utilities.IO; @@ -47,10 +49,12 @@ namespace Org.BouncyCastle.Crypto.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(ReadSource, destination, bufferSize, cancellationToken); } +#endif public override void Flush() { diff --git a/crypto/src/tls/TlsStream.cs b/crypto/src/tls/TlsStream.cs index d7d79a6fa..e6afd1869 100644 --- a/crypto/src/tls/TlsStream.cs +++ b/crypto/src/tls/TlsStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif using Org.BouncyCastle.Utilities.IO; @@ -39,10 +41,12 @@ namespace Org.BouncyCastle.Tls } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(this, destination, bufferSize, cancellationToken); } +#endif protected override void Dispose(bool disposing) { diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs index 25f2c62d9..e99b8483d 100644 --- a/crypto/src/util/Platform.cs +++ b/crypto/src/util/Platform.cs @@ -46,6 +46,16 @@ namespace Org.BouncyCastle.Utilities return InvariantCompareInfo.IndexOf(source, value, startIndex, CompareOptions.Ordinal); } + internal static bool Is64BitProcess + { +#if NETCOREAPP2_0_OR_GREATER || NET40_OR_GREATER || NETSTANDARD2_0_OR_GREATER + + get { return Environment.Is64BitProcess; } +#else + get { return IntPtr.Size == 8; } +#endif + } + internal static int LastIndexOf(string source, string value) { return InvariantCompareInfo.LastIndexOf(source, value, CompareOptions.Ordinal); diff --git a/crypto/src/util/io/BaseInputStream.cs b/crypto/src/util/io/BaseInputStream.cs index 8f5265fee..438583c75 100644 --- a/crypto/src/util/io/BaseInputStream.cs +++ b/crypto/src/util/io/BaseInputStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif namespace Org.BouncyCastle.Utilities.IO { @@ -19,10 +21,12 @@ namespace Org.BouncyCastle.Utilities.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(this, destination, bufferSize, cancellationToken); } +#endif public sealed override void Flush() {} public sealed override long Length { get { throw new NotSupportedException(); } } diff --git a/crypto/src/util/io/BaseOutputStream.cs b/crypto/src/util/io/BaseOutputStream.cs index 87a850c35..72234b817 100644 --- a/crypto/src/util/io/BaseOutputStream.cs +++ b/crypto/src/util/io/BaseOutputStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif namespace Org.BouncyCastle.Utilities.IO { @@ -16,11 +18,15 @@ namespace Org.BouncyCastle.Utilities.IO // TODO[api] sealed public override void CopyTo(Stream destination, int bufferSize) { throw new NotSupportedException(); } #endif + +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER // TODO[api] sealed public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { throw new NotSupportedException(); } +#endif + public override void Flush() {} public sealed override long Length { get { throw new NotSupportedException(); } } public sealed override long Position diff --git a/crypto/src/util/io/FilterStream.cs b/crypto/src/util/io/FilterStream.cs index 630bdc22f..8fb6d9df4 100644 --- a/crypto/src/util/io/FilterStream.cs +++ b/crypto/src/util/io/FilterStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif namespace Org.BouncyCastle.Utilities.IO { @@ -32,10 +34,12 @@ namespace Org.BouncyCastle.Utilities.IO Streams.CopyTo(s, destination, bufferSize); } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return Streams.CopyToAsync(s, destination, bufferSize, cancellationToken); } +#endif public override void Flush() { s.Flush(); diff --git a/crypto/src/util/io/PushbackStream.cs b/crypto/src/util/io/PushbackStream.cs index be6b26d4c..452019805 100644 --- a/crypto/src/util/io/PushbackStream.cs +++ b/crypto/src/util/io/PushbackStream.cs @@ -1,7 +1,9 @@ using System; using System.IO; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif namespace Org.BouncyCastle.Utilities.IO { @@ -28,6 +30,7 @@ namespace Org.BouncyCastle.Utilities.IO } #endif +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public override async Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { if (m_buf != -1) @@ -39,6 +42,7 @@ namespace Org.BouncyCastle.Utilities.IO await Streams.CopyToAsync(s, destination, bufferSize, cancellationToken); } +#endif public override int Read(byte[] buffer, int offset, int count) { diff --git a/crypto/src/util/io/Streams.cs b/crypto/src/util/io/Streams.cs index 69f390646..a1a2ea5d1 100644 --- a/crypto/src/util/io/Streams.cs +++ b/crypto/src/util/io/Streams.cs @@ -2,13 +2,15 @@ using System; using System.IO; using System.Runtime.InteropServices; using System.Threading; +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER using System.Threading.Tasks; +#endif namespace Org.BouncyCastle.Utilities.IO { public static class Streams { - private static readonly int MaxStackAlloc = Environment.Is64BitProcess ? 4096 : 1024; + private static readonly int MaxStackAlloc = Platform.Is64BitProcess ? 4096 : 1024; public static int DefaultBufferSize => MaxStackAlloc; @@ -37,6 +39,7 @@ namespace Org.BouncyCastle.Utilities.IO #endif } +#if NETCOREAPP1_0_OR_GREATER || NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER public static Task CopyToAsync(Stream source, Stream destination) { return CopyToAsync(source, destination, DefaultBufferSize); @@ -69,6 +72,7 @@ namespace Org.BouncyCastle.Utilities.IO } #endif } +#endif public static void Drain(Stream inStr) { |