summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/bzip2/src/CBZip2OutputStream.cs6
-rw-r--r--crypto/src/asn1/DerGeneralizedTime.cs2
-rw-r--r--crypto/src/asn1/cmp/CertResponse.cs3
-rw-r--r--crypto/src/asn1/cmp/ErrorMsgContent.cs3
-rw-r--r--crypto/src/asn1/crmf/CertReqMsg.cs3
-rw-r--r--crypto/src/asn1/util/FilterStream.cs1
-rw-r--r--crypto/src/asn1/x509/AlgorithmIdentifier.cs64
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs1
-rw-r--r--crypto/src/crypto/io/CipherStream.cs1
-rw-r--r--crypto/src/crypto/io/DigestStream.cs1
-rw-r--r--crypto/src/crypto/io/MacStream.cs1
-rw-r--r--crypto/src/crypto/io/SignerStream.cs3
-rw-r--r--crypto/src/crypto/operators/Asn1Signature.cs16
-rw-r--r--crypto/src/crypto/tls/ByteQueueStream.cs14
-rw-r--r--crypto/src/crypto/tls/TlsStream.cs1
-rw-r--r--crypto/src/openpgp/PgpCompressedDataGenerator.cs2
-rw-r--r--crypto/src/util/io/BaseInputStream.cs1
-rw-r--r--crypto/src/util/io/BaseOutputStream.cs1
-rw-r--r--crypto/src/util/io/FilterStream.cs1
-rw-r--r--crypto/src/util/io/TeeInputStream.cs1
-rw-r--r--crypto/src/util/io/TeeOutputStream.cs1
-rw-r--r--crypto/src/util/zlib/ZDeflaterOutputStream.cs1
-rw-r--r--crypto/src/util/zlib/ZInflaterInputStream.cs1
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs21
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs5
-rw-r--r--crypto/src/x509/X509V3CertificateGenerator.cs9
-rw-r--r--crypto/test/src/asn1/test/GenerationTest.cs18
-rw-r--r--crypto/test/src/asn1/test/TimeTest.cs4
-rw-r--r--crypto/test/src/util/test/SimpleTest.cs18
29 files changed, 92 insertions, 112 deletions
diff --git a/crypto/bzip2/src/CBZip2OutputStream.cs b/crypto/bzip2/src/CBZip2OutputStream.cs
index 80b054c29..ffac073fb 100644
--- a/crypto/bzip2/src/CBZip2OutputStream.cs
+++ b/crypto/bzip2/src/CBZip2OutputStream.cs
@@ -402,15 +402,15 @@ namespace Org.BouncyCastle.Apache.Bzip2
         }
 #else
         public override void Close() {
-            if (closed) {
+            if (closed)
                 return;
-            }
 
             Finish();
 
             closed = true;
-            base.Close();
             Platform.Dispose(this.bsStream);
+
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/asn1/DerGeneralizedTime.cs b/crypto/src/asn1/DerGeneralizedTime.cs
index 6700b9016..152596678 100644
--- a/crypto/src/asn1/DerGeneralizedTime.cs
+++ b/crypto/src/asn1/DerGeneralizedTime.cs
@@ -267,7 +267,7 @@ namespace Org.BouncyCastle.Asn1
             {
                 try
                 {
-                    style = (DateTimeStyles)Enum.Parse(typeof(DateTimeStyles), "AssumeUniversal");
+                    style = (DateTimeStyles)Enums.GetEnumValue(typeof(DateTimeStyles), "AssumeUniversal");
                 }
                 catch (Exception)
                 {
diff --git a/crypto/src/asn1/cmp/CertResponse.cs b/crypto/src/asn1/cmp/CertResponse.cs
index 246b8ce70..80813b8b7 100644
--- a/crypto/src/asn1/cmp/CertResponse.cs
+++ b/crypto/src/asn1/cmp/CertResponse.cs
@@ -107,8 +107,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(certReqId, status);
-			v.AddOptional(certifiedKeyPair);
-			v.AddOptional(rspInfo);
+			v.AddOptional(certifiedKeyPair, rspInfo);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/ErrorMsgContent.cs b/crypto/src/asn1/cmp/ErrorMsgContent.cs
index f4dc584ea..2d6353b65 100644
--- a/crypto/src/asn1/cmp/ErrorMsgContent.cs
+++ b/crypto/src/asn1/cmp/ErrorMsgContent.cs
@@ -86,8 +86,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(pkiStatusInfo);
-			v.AddOptional(errorCode);
-			v.AddOptional(errorDetails);
+			v.AddOptional(errorCode, errorDetails);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/crmf/CertReqMsg.cs b/crypto/src/asn1/crmf/CertReqMsg.cs
index 2ca319a57..20fd4179a 100644
--- a/crypto/src/asn1/crmf/CertReqMsg.cs
+++ b/crypto/src/asn1/crmf/CertReqMsg.cs
@@ -98,8 +98,7 @@ namespace Org.BouncyCastle.Asn1.Crmf
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(certReq);
-            v.AddOptional(popo);
-            v.AddOptional(regInfo);
+            v.AddOptional(popo, regInfo);
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/util/FilterStream.cs b/crypto/src/asn1/util/FilterStream.cs
index 79aa883d0..0c38c5b6e 100644
--- a/crypto/src/asn1/util/FilterStream.cs
+++ b/crypto/src/asn1/util/FilterStream.cs
@@ -47,6 +47,7 @@ namespace Org.BouncyCastle.Asn1.Utilities
         public override void Close()
         {
             Platform.Dispose(s);
+            base.Close();
         }
 #endif
         public override void Flush()
diff --git a/crypto/src/asn1/x509/AlgorithmIdentifier.cs b/crypto/src/asn1/x509/AlgorithmIdentifier.cs
index c6f4af5bf..00e7ad8bc 100644
--- a/crypto/src/asn1/x509/AlgorithmIdentifier.cs
+++ b/crypto/src/asn1/x509/AlgorithmIdentifier.cs
@@ -5,9 +5,8 @@ namespace Org.BouncyCastle.Asn1.X509
     public class AlgorithmIdentifier
         : Asn1Encodable
     {
-        private readonly DerObjectIdentifier	objectID;
+        private readonly DerObjectIdentifier	algorithm;
         private readonly Asn1Encodable			parameters;
-        private readonly bool					parametersDefined;
 
         public static AlgorithmIdentifier GetInstance(
             Asn1TaggedObject	obj,
@@ -19,39 +18,32 @@ namespace Org.BouncyCastle.Asn1.X509
         public static AlgorithmIdentifier GetInstance(
             object obj)
         {
-            if (obj == null || obj is AlgorithmIdentifier)
-                return (AlgorithmIdentifier) obj;
-
-            // TODO: delete
-            if (obj is DerObjectIdentifier)
-                return new AlgorithmIdentifier((DerObjectIdentifier) obj);
-
-            // TODO: delete
-            if (obj is string)
-                return new AlgorithmIdentifier((string) obj);
-
+            if (obj == null)
+                return null;
+            if (obj is AlgorithmIdentifier)
+                return (AlgorithmIdentifier)obj;
             return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj));
         }
 
         public AlgorithmIdentifier(
-            DerObjectIdentifier objectID)
+            DerObjectIdentifier algorithm)
         {
-            this.objectID = objectID;
+            this.algorithm = algorithm;
         }
 
+        [Obsolete("Use version taking a DerObjectIdentifier")]
         public AlgorithmIdentifier(
-            string objectID)
+            string algorithm)
         {
-            this.objectID = new DerObjectIdentifier(objectID);
+            this.algorithm = new DerObjectIdentifier(algorithm);
         }
 
         public AlgorithmIdentifier(
-            DerObjectIdentifier	objectID,
+            DerObjectIdentifier algorithm,
             Asn1Encodable		parameters)
         {
-            this.objectID = objectID;
+            this.algorithm = algorithm;
             this.parameters = parameters;
-            this.parametersDefined = true;
         }
 
         internal AlgorithmIdentifier(
@@ -60,13 +52,8 @@ namespace Org.BouncyCastle.Asn1.X509
             if (seq.Count < 1 || seq.Count > 2)
                 throw new ArgumentException("Bad sequence size: " + seq.Count);
 
-            this.objectID = DerObjectIdentifier.GetInstance(seq[0]);
-            this.parametersDefined = (seq.Count == 2);
-
-            if (parametersDefined)
-            {
-                this.parameters = seq[1];
-            }
+            this.algorithm = DerObjectIdentifier.GetInstance(seq[0]);
+            this.parameters = seq.Count < 2 ? null : seq[1];
         }
 
         /// <summary>
@@ -74,18 +61,19 @@ namespace Org.BouncyCastle.Asn1.X509
         /// </summary>
 		public virtual DerObjectIdentifier Algorithm
 		{
-			get { return objectID; }
+			get { return algorithm; }
 		}
 
+        [Obsolete("Use 'Algorithm' property instead")]
         public virtual DerObjectIdentifier ObjectID
         {
-            get { return objectID; }
+            get { return algorithm; }
         }
 
         /// <summary>
         /// Return the parameters structure in the Parameters entry of this identifier.
         /// </summary>
-        public Asn1Encodable Parameters
+        public virtual Asn1Encodable Parameters
         {
             get { return parameters; }
         }
@@ -100,20 +88,8 @@ namespace Org.BouncyCastle.Asn1.X509
          */
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(objectID);
-
-            if (parametersDefined)
-            {
-                if (parameters != null)
-                {
-                    v.Add(parameters);
-                }
-                else
-                {
-                    v.Add(DerNull.Instance);
-                }
-            }
-
+            Asn1EncodableVector v = new Asn1EncodableVector(algorithm);
+            v.AddOptional(parameters);
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
index f2dc340df..a135cdd11 100644
--- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -289,6 +289,7 @@ namespace Org.BouncyCastle.Cms
 
 				authGen.Close();
 				cGen.Close();
+                base.Close();
 			}
 #endif
 		}
diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs
index 4128b70f2..bfce386a7 100644
--- a/crypto/src/crypto/io/CipherStream.cs
+++ b/crypto/src/crypto/io/CipherStream.cs
@@ -227,6 +227,7 @@ namespace Org.BouncyCastle.Crypto.IO
 				stream.Flush();
 			}
             Platform.Dispose(stream);
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/crypto/io/DigestStream.cs b/crypto/src/crypto/io/DigestStream.cs
index eadd7f684..dce875792 100644
--- a/crypto/src/crypto/io/DigestStream.cs
+++ b/crypto/src/crypto/io/DigestStream.cs
@@ -125,6 +125,7 @@ namespace Org.BouncyCastle.Crypto.IO
 		public override void Close()
 		{
             Platform.Dispose(stream);
+            base.Close();
 		}
 #endif
 
diff --git a/crypto/src/crypto/io/MacStream.cs b/crypto/src/crypto/io/MacStream.cs
index 6d306f9c5..d9b8323b5 100644
--- a/crypto/src/crypto/io/MacStream.cs
+++ b/crypto/src/crypto/io/MacStream.cs
@@ -124,6 +124,7 @@ namespace Org.BouncyCastle.Crypto.IO
         public override void Close()
         {
             Platform.Dispose(stream);
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs
index 7a7d8ea82..1e37c8d34 100644
--- a/crypto/src/crypto/io/SignerStream.cs
+++ b/crypto/src/crypto/io/SignerStream.cs
@@ -125,10 +125,11 @@ namespace Org.BouncyCastle.Crypto.IO
         public override void Close()
         {
             Platform.Dispose(stream);
+            base.Close();
         }
 #endif
 
-        public override  void Flush()
+        public override void Flush()
 		{
 			stream.Flush();
 		}
diff --git a/crypto/src/crypto/operators/Asn1Signature.cs b/crypto/src/crypto/operators/Asn1Signature.cs
index 968ee0fad..3a20e4bff 100644
--- a/crypto/src/crypto/operators/Asn1Signature.cs
+++ b/crypto/src/crypto/operators/Asn1Signature.cs
@@ -303,21 +303,7 @@ namespace Org.BouncyCastle.Crypto.Operators
 			set { throw new NotImplementedException (); }
 		}
 
-#if PORTABLE
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-                return;
-
-            base.Dispose(disposing);
-        }
-#else
-        public override void Close()
-		{
-		}
-#endif
-
-		public override  void Flush()
+        public override void Flush()
 		{
 		}
 
diff --git a/crypto/src/crypto/tls/ByteQueueStream.cs b/crypto/src/crypto/tls/ByteQueueStream.cs
index 1fc8a5d29..249e6099b 100644
--- a/crypto/src/crypto/tls/ByteQueueStream.cs
+++ b/crypto/src/crypto/tls/ByteQueueStream.cs
@@ -33,20 +33,6 @@ namespace Org.BouncyCastle.Crypto.Tls
             get { return true; }
         }
 
-#if PORTABLE
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing)
-                return;
-
-            base.Dispose(disposing);
-        }
-#else
-        public override void Close()
-        {
-        }
-#endif
-
         public override void Flush()
         {
         }
diff --git a/crypto/src/crypto/tls/TlsStream.cs b/crypto/src/crypto/tls/TlsStream.cs
index e11091c85..bfd80edf2 100644
--- a/crypto/src/crypto/tls/TlsStream.cs
+++ b/crypto/src/crypto/tls/TlsStream.cs
@@ -41,6 +41,7 @@ namespace Org.BouncyCastle.Crypto.Tls
         public override void Close()
         {
             handler.Close();
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
index 2d20601f0..51b645279 100644
--- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
@@ -179,6 +179,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                 if (disposing)
                 {
 				    Finish();
+                    return;
                 }
                 base.Dispose(disposing);
             }
@@ -204,6 +205,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                 {
 				    Finish();
 				    End();
+                    return;
                 }
                 base.Dispose(disposing);
             }
diff --git a/crypto/src/util/io/BaseInputStream.cs b/crypto/src/util/io/BaseInputStream.cs
index 0a6e19307..a5613d801 100644
--- a/crypto/src/util/io/BaseInputStream.cs
+++ b/crypto/src/util/io/BaseInputStream.cs
@@ -25,6 +25,7 @@ namespace Org.BouncyCastle.Utilities.IO
 		public override void Close()
         {
             closed = true;
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/util/io/BaseOutputStream.cs b/crypto/src/util/io/BaseOutputStream.cs
index 0b6daa6a5..a0608d111 100644
--- a/crypto/src/util/io/BaseOutputStream.cs
+++ b/crypto/src/util/io/BaseOutputStream.cs
@@ -25,6 +25,7 @@ namespace Org.BouncyCastle.Utilities.IO
         public override void Close()
         {
             closed = true;
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/util/io/FilterStream.cs b/crypto/src/util/io/FilterStream.cs
index fe359de90..a92dee3e5 100644
--- a/crypto/src/util/io/FilterStream.cs
+++ b/crypto/src/util/io/FilterStream.cs
@@ -42,6 +42,7 @@ namespace Org.BouncyCastle.Utilities.IO
         public override void Close()
         {
             Platform.Dispose(s);
+            base.Close();
         }
 #endif
         public override void Flush()
diff --git a/crypto/src/util/io/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs
index e5fc10157..6996f3fbb 100644
--- a/crypto/src/util/io/TeeInputStream.cs
+++ b/crypto/src/util/io/TeeInputStream.cs
@@ -33,6 +33,7 @@ namespace Org.BouncyCastle.Utilities.IO
 		{
             Platform.Dispose(input);
             Platform.Dispose(tee);
+            base.Close();
 		}
 #endif
 
diff --git a/crypto/src/util/io/TeeOutputStream.cs b/crypto/src/util/io/TeeOutputStream.cs
index 82407d9fa..a6c7fd5b5 100644
--- a/crypto/src/util/io/TeeOutputStream.cs
+++ b/crypto/src/util/io/TeeOutputStream.cs
@@ -33,6 +33,7 @@ namespace Org.BouncyCastle.Utilities.IO
 		{
             Platform.Dispose(output);
             Platform.Dispose(tee);
+            base.Close();
 		}
 #endif
 
diff --git a/crypto/src/util/zlib/ZDeflaterOutputStream.cs b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
index 99a4ebfbe..d0f0bcb8d 100644
--- a/crypto/src/util/zlib/ZDeflaterOutputStream.cs
+++ b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
@@ -164,6 +164,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
                 Platform.Dispose(outp);
                 outp=null;
             }
+            base.Close();
         }
 #endif
     }
diff --git a/crypto/src/util/zlib/ZInflaterInputStream.cs b/crypto/src/util/zlib/ZInflaterInputStream.cs
index 0f0999e86..ef742bb00 100644
--- a/crypto/src/util/zlib/ZInflaterInputStream.cs
+++ b/crypto/src/util/zlib/ZInflaterInputStream.cs
@@ -127,6 +127,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
         public override void Close()
         {
             Platform.Dispose(inp);
+            base.Close();
         }
 #endif
 
diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs
index ee19af587..4b7351555 100644
--- a/crypto/src/util/zlib/ZInputStream.cs
+++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -98,22 +98,23 @@ namespace Org.BouncyCastle.Utilities.Zlib
         {
             if (disposing)
             {
-			    if (!closed)
-			    {
-				    closed = true;
-                    Platform.Dispose(input);
-			    }
+			    if (closed)
+                    return;
+
+                closed = true;
+                Platform.Dispose(input);
             }
             base.Dispose(disposing);
         }
 #else
         public override void Close()
 		{
-			if (!closed)
-			{
-				closed = true;
-                Platform.Dispose(input);
-			}
+            if (closed)
+                return;
+
+            closed = true;
+            Platform.Dispose(input);
+            base.Close();
 		}
 #endif
 
diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs
index ede557135..d9f005f69 100644
--- a/crypto/src/util/zlib/ZOutputStream.cs
+++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -100,7 +100,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
         {
             if (disposing)
             {
-			    if (this.closed)
+			    if (closed)
 				    return;
 
                 DoClose();
@@ -110,10 +110,11 @@ namespace Org.BouncyCastle.Utilities.Zlib
 #else
 		public override void Close()
 		{
-			if (this.closed)
+			if (closed)
 				return;
 
             DoClose();
+            base.Close();
 		}
 #endif
 
diff --git a/crypto/src/x509/X509V3CertificateGenerator.cs b/crypto/src/x509/X509V3CertificateGenerator.cs
index 51488bd2a..bc619c37b 100644
--- a/crypto/src/x509/X509V3CertificateGenerator.cs
+++ b/crypto/src/x509/X509V3CertificateGenerator.cs
@@ -1,15 +1,14 @@
 using System;
 using System.Collections;
-using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
-using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Security.Certificates;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.X509.Extension;
 
 namespace Org.BouncyCastle.X509
@@ -318,11 +317,11 @@ namespace Org.BouncyCastle.X509
 
 			byte[] encoded = tbsCert.GetDerEncoded();
 
-			streamCalculator.Stream.Write (encoded, 0, encoded.Length);
+			streamCalculator.Stream.Write(encoded, 0, encoded.Length);
 
-            streamCalculator.Stream.Close ();
+            Platform.Dispose(streamCalculator.Stream);
 
-			return GenerateJcaObject(tbsCert, (AlgorithmIdentifier)signatureCalculatorFactory.AlgorithmDetails, ((IBlockResult)streamCalculator.GetResult()).Collect());
+            return GenerateJcaObject(tbsCert, (AlgorithmIdentifier)signatureCalculatorFactory.AlgorithmDetails, ((IBlockResult)streamCalculator.GetResult()).Collect());
 		}
 
 		private X509Certificate GenerateJcaObject(
diff --git a/crypto/test/src/asn1/test/GenerationTest.cs b/crypto/test/src/asn1/test/GenerationTest.cs
index 5acf8e149..862e66d22 100644
--- a/crypto/test/src/asn1/test/GenerationTest.cs
+++ b/crypto/test/src/asn1/test/GenerationTest.cs
@@ -53,8 +53,8 @@ namespace Org.BouncyCastle.Asn1.Tests
         private void TbsV1CertGenerate()
         {
 			V1TbsCertificateGenerator gen = new V1TbsCertificateGenerator();
-            DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 1);
-            DateTime endDate = new DateTime(1970, 1, 1, 0, 0, 12);
+            DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1);
+            DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 12);
 
             gen.SetSerialNumber(new DerInteger(1));
 
@@ -106,8 +106,8 @@ namespace Org.BouncyCastle.Asn1.Tests
 		private void TbsV3CertGenerate()
         {
 			V3TbsCertificateGenerator gen = new V3TbsCertificateGenerator();
-			DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 1);
-			DateTime endDate = new DateTime(1970, 1, 1, 0, 0, 2);
+            DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1);
+            DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 2);
 
 			gen.SetSerialNumber(new DerInteger(2));
 
@@ -166,8 +166,8 @@ namespace Org.BouncyCastle.Asn1.Tests
 		private void TbsV3CertGenWithNullSubject()
 		{
 			V3TbsCertificateGenerator gen = new V3TbsCertificateGenerator();
-			DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 1);
-			DateTime endDate = new DateTime(1970, 1, 1, 0, 0, 2);
+            DateTime startDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 1);
+            DateTime endDate = MakeUtcDateTime(1970, 1, 1, 0, 0, 2);
 
 			gen.SetSerialNumber(new DerInteger(2));
 
@@ -243,11 +243,11 @@ namespace Org.BouncyCastle.Asn1.Tests
 
             gen.SetIssuer(new X509Name("CN=AU,O=Bouncy Castle"));
 
-            gen.AddCrlEntry(new DerInteger(1), new Time(new DateTime(1970, 1, 1, 0, 0, 1)), ReasonFlags.AACompromise);
+            gen.AddCrlEntry(new DerInteger(1), new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 1)), ReasonFlags.AACompromise);
 
-            gen.SetNextUpdate(new Time(new DateTime(1970, 1, 1, 0, 0, 2)));
+            gen.SetNextUpdate(new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 2)));
 
-            gen.SetThisUpdate(new Time(new DateTime(1970, 1, 1, 0, 0, 0, 500)));
+            gen.SetThisUpdate(new Time(MakeUtcDateTime(1970, 1, 1, 0, 0, 0, 500)));
 
             gen.SetSignature(new AlgorithmIdentifier(PkcsObjectIdentifiers.Sha1WithRsaEncryption, DerNull.Instance));
 
diff --git a/crypto/test/src/asn1/test/TimeTest.cs b/crypto/test/src/asn1/test/TimeTest.cs
index 6f6bd6f2c..04dac3c9e 100644
--- a/crypto/test/src/asn1/test/TimeTest.cs
+++ b/crypto/test/src/asn1/test/TimeTest.cs
@@ -15,9 +15,9 @@ namespace Org.BouncyCastle.Asn1.Tests
 			DateTime now = DateTime.UtcNow;
 
 			// Time classes only have a resolution of seconds
-			now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
+			now = SimpleTest.MakeUtcDateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
 
-			Org.BouncyCastle.Asn1.Cms.Time cmsTime = new Org.BouncyCastle.Asn1.Cms.Time(now);
+            Org.BouncyCastle.Asn1.Cms.Time cmsTime = new Org.BouncyCastle.Asn1.Cms.Time(now);
 			Org.BouncyCastle.Asn1.X509.Time x509Time = new Org.BouncyCastle.Asn1.X509.Time(now);
 
 //			Assert.AreEqual(cmsTime.Date, x509Time.ToDateTime());
diff --git a/crypto/test/src/util/test/SimpleTest.cs b/crypto/test/src/util/test/SimpleTest.cs
index be846e20f..84a7ce02b 100644
--- a/crypto/test/src/util/test/SimpleTest.cs
+++ b/crypto/test/src/util/test/SimpleTest.cs
@@ -160,5 +160,23 @@ namespace Org.BouncyCastle.Utilities.Test
 		internal static readonly string NewLine = GetNewLine();
 
 		public abstract void PerformTest();
+
+        public static DateTime MakeUtcDateTime(int year, int month, int day, int hour, int minute, int second)
+        {
+#if PORTABLE
+            return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc);
+#else
+            return new DateTime(year, month, day, hour, minute, second);
+#endif
+        }
+
+        public static DateTime MakeUtcDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
+        {
+#if PORTABLE
+            return new DateTime(year, month, day, hour, minute, second, millisecond, DateTimeKind.Utc);
+#else
+            return new DateTime(year, month, day, hour, minute, second, millisecond);
+#endif
+        }
     }
 }