From 95f157f9bd915d652dea06730b36391c19b60e87 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Wed, 27 Aug 2014 10:18:03 -0400 Subject: Fix remaining compile errors --- crypto/src/asn1/BEROctetStringGenerator.cs | 23 ++++++++++-------- crypto/src/asn1/DerGeneralizedTime.cs | 12 ++-------- crypto/src/asn1/util/Dump.cs | 2 ++ crypto/src/cms/CMSCompressedDataGenerator.cs | 2 +- crypto/src/cms/CMSCompressedDataStreamGenerator.cs | 2 +- crypto/src/cms/CMSProcessableFile.cs | 4 +++- crypto/src/crypto/prng/CryptoApiRandomGenerator.cs | 2 +- crypto/src/crypto/prng/ThreadedSeedGenerator.cs | 28 ++++++++++++---------- crypto/src/openpgp/PgpCompressedDataGenerator.cs | 14 +++++++---- crypto/src/openpgp/PgpLiteralDataGenerator.cs | 2 ++ crypto/src/openpgp/PgpUtilities.cs | 2 ++ crypto/src/util/Platform.cs | 7 +++--- 12 files changed, 56 insertions(+), 44 deletions(-) diff --git a/crypto/src/asn1/BEROctetStringGenerator.cs b/crypto/src/asn1/BEROctetStringGenerator.cs index 7468a6b0b..6d7d1b66e 100644 --- a/crypto/src/asn1/BEROctetStringGenerator.cs +++ b/crypto/src/asn1/BEROctetStringGenerator.cs @@ -102,16 +102,19 @@ namespace Org.BouncyCastle.Asn1 } } - public override void Close() - { - if (_off != 0) - { - DerOctetString.Encode(_derOut, _buf, 0, _off); - } - - _gen.WriteBerEnd(); - base.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (_off != 0) + { + DerOctetString.Encode(_derOut, _buf, 0, _off); + } + + _gen.WriteBerEnd(); + } + base.Dispose(disposing); + } } } } diff --git a/crypto/src/asn1/DerGeneralizedTime.cs b/crypto/src/asn1/DerGeneralizedTime.cs index 548a268e1..9a125ff3b 100644 --- a/crypto/src/asn1/DerGeneralizedTime.cs +++ b/crypto/src/asn1/DerGeneralizedTime.cs @@ -259,19 +259,11 @@ namespace Org.BouncyCastle.Asn1 private DateTime ParseDateString(string s, string format, bool makeUniversal) { - /* - * NOTE: DateTime.Kind and DateTimeStyles.AssumeUniversal not available in .NET 1.1 - */ DateTimeStyles style = DateTimeStyles.None; if (format.EndsWith("Z")) { - try - { - style = (DateTimeStyles)Enum.Parse(typeof(DateTimeStyles), "AssumeUniversal"); - } - catch (Exception) - { - } + style = DateTimeStyles.AssumeUniversal; + style |= DateTimeStyles.AdjustToUniversal; } diff --git a/crypto/src/asn1/util/Dump.cs b/crypto/src/asn1/util/Dump.cs index 27c87f127..164ed982f 100644 --- a/crypto/src/asn1/util/Dump.cs +++ b/crypto/src/asn1/util/Dump.cs @@ -1,3 +1,4 @@ +#if !PCL using Org.BouncyCastle.Asn1; using System; @@ -26,3 +27,4 @@ namespace Org.BouncyCastle.Asn1.Utilities } } } +#endif diff --git a/crypto/src/cms/CMSCompressedDataGenerator.cs b/crypto/src/cms/CMSCompressedDataGenerator.cs index 00e2a3df4..f147bb7ea 100644 --- a/crypto/src/cms/CMSCompressedDataGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataGenerator.cs @@ -45,7 +45,7 @@ namespace Org.BouncyCastle.Cms content.Write(zOut); - zOut.Close(); + zOut.Dispose(); comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid)); comOcts = new BerOctetString(bOut.ToArray()); diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs index b817d3ae1..c5a4afa1c 100644 --- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs @@ -128,7 +128,7 @@ namespace Org.BouncyCastle.Cms { if (disposing) { - _out.Close(); + _out.Dispose(); // TODO Parent context(s) should really be be closed explicitly diff --git a/crypto/src/cms/CMSProcessableFile.cs b/crypto/src/cms/CMSProcessableFile.cs index cbc74f44b..3a3229b4f 100644 --- a/crypto/src/cms/CMSProcessableFile.cs +++ b/crypto/src/cms/CMSProcessableFile.cs @@ -1,3 +1,4 @@ +#if !PCL using System; using System.IO; @@ -41,7 +42,7 @@ namespace Org.BouncyCastle.Cms { Stream inStr = GetInputStream(); Streams.PipeAll(inStr, zOut); - inStr.Close(); + inStr.Dispose(); } /// The file handle @@ -52,3 +53,4 @@ namespace Org.BouncyCastle.Cms } } } +#endif \ No newline at end of file diff --git a/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs b/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs index e1a0d4012..d815656f6 100644 --- a/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs +++ b/crypto/src/crypto/prng/CryptoApiRandomGenerator.cs @@ -1,4 +1,4 @@ -#if !NETCF_1_0 +#if !NETCF_1_0 && !PCL using System; using System.Security.Cryptography; diff --git a/crypto/src/crypto/prng/ThreadedSeedGenerator.cs b/crypto/src/crypto/prng/ThreadedSeedGenerator.cs index c29ad2c9a..a6c1a4ad3 100644 --- a/crypto/src/crypto/prng/ThreadedSeedGenerator.cs +++ b/crypto/src/crypto/prng/ThreadedSeedGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using System.Threading.Tasks; namespace Org.BouncyCastle.Crypto.Prng { @@ -65,19 +66,22 @@ namespace Org.BouncyCastle.Crypto.Prng for (int i = 0; i < end; i++) { - while (this.counter == last) - { - try - { - Thread.Sleep(1); - } - catch (Exception) - { - // ignore - } - } + using (var mre = new ManualResetEvent(false)) + { + while (this.counter == last) + { + try + { + mre.WaitOne(1); + } + catch (Exception) + { + // ignore + } + } + } - last = this.counter; + last = this.counter; if (fast) { diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs index f5626ee1a..732b941e7 100644 --- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs +++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs @@ -191,11 +191,15 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { } - public override void Close() - { - Finish(); - End(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + Finish(); + End(); + } + base.Dispose(disposing); + } } } } diff --git a/crypto/src/openpgp/PgpLiteralDataGenerator.cs b/crypto/src/openpgp/PgpLiteralDataGenerator.cs index 3b1f2fe74..20c670689 100644 --- a/crypto/src/openpgp/PgpLiteralDataGenerator.cs +++ b/crypto/src/openpgp/PgpLiteralDataGenerator.cs @@ -141,6 +141,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp return new WrappedGeneratorStream(this, pkOut); } +#if !PCL /// ///

/// Open a literal data packet for the passed in FileInfo object, returning @@ -162,6 +163,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { return Open(outStr, format, file.Name, file.Length, file.LastWriteTime); } +#endif ///

/// Close the literal data packet - this is equivalent to calling Close() diff --git a/crypto/src/openpgp/PgpUtilities.cs b/crypto/src/openpgp/PgpUtilities.cs index 32e37b819..cd53cc029 100644 --- a/crypto/src/openpgp/PgpUtilities.cs +++ b/crypto/src/openpgp/PgpUtilities.cs @@ -307,6 +307,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp return MakeKey(algorithm, keyBytes); } +#if !PCL /// Write out the passed in file as a literal data packet. public static void WriteFileToLiteralData( Stream output, @@ -344,6 +345,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp pOut.Close(); inputStream.Close(); } +#endif private const int ReadAhead = 60; diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs index 99d3982ea..17c278690 100644 --- a/crypto/src/util/Platform.cs +++ b/crypto/src/util/Platform.cs @@ -33,7 +33,7 @@ namespace Org.BouncyCastle.Utilities internal static int CompareIgnoreCase(string a, string b) { #if SILVERLIGHT - return String.Compare(a, b, StringComparison.InvariantCultureIgnoreCase); + return String.Compare(a, b, StringComparison.OrdinalIgnoreCase); #else return String.Compare(a, b, true); #endif @@ -165,12 +165,13 @@ namespace Org.BouncyCastle.Utilities internal static string ToLowerInvariant(string s) { - return s.ToLower(CultureInfo.InvariantCulture); + + return s.ToLowerInvariant(); } internal static string ToUpperInvariant(string s) { - return s.ToUpper(CultureInfo.InvariantCulture); + return s.ToUpperInvariant(); } internal static readonly string NewLine = GetNewLine(); -- cgit 1.4.1