summary refs log tree commit diff
path: root/crypto/src/asn1/tsp
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 16:55:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 16:55:26 +0700
commit3eb93b423abeefbdc03f0ecc38751d76428ba23e (patch)
treef364f857c54f65eb59462560b1f282b896eecf8b /crypto/src/asn1/tsp
parentPort LinkedCertificate from bc-java (diff)
downloadBouncyCastle.NET-ed25519-3eb93b423abeefbdc03f0ecc38751d76428ba23e.tar.xz
Refactoring
Diffstat (limited to 'crypto/src/asn1/tsp')
-rw-r--r--crypto/src/asn1/tsp/Accuracy.cs29
-rw-r--r--crypto/src/asn1/tsp/TSTInfo.cs47
-rw-r--r--crypto/src/asn1/tsp/TimeStampReq.cs40
-rw-r--r--crypto/src/asn1/tsp/TimeStampResp.cs17
4 files changed, 42 insertions, 91 deletions
diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs
index 9f2c7e8cc..c5a5ca119 100644
--- a/crypto/src/asn1/tsp/Accuracy.cs
+++ b/crypto/src/asn1/tsp/Accuracy.cs
@@ -126,26 +126,13 @@ namespace Org.BouncyCastle.Asn1.Tsp
 		 *             }
 		 * </pre>
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			Asn1EncodableVector v = new Asn1EncodableVector();
-
-			if (seconds != null)
-			{
-				v.Add(seconds);
-			}
-
-			if (millis != null)
-			{
-				v.Add(new DerTaggedObject(false, 0, millis));
-			}
-
-			if (micros != null)
-			{
-				v.Add(new DerTaggedObject(false, 1, micros));
-			}
-
-			return new DerSequence(v);
-		}
+        public override Asn1Object ToAsn1Object()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector();
+            v.AddOptional(seconds);
+            v.AddOptionalTagged(false, 0, millis);
+            v.AddOptionalTagged(false, 1, micros);
+            return new DerSequence(v);
+        }
 	}
 }
diff --git a/crypto/src/asn1/tsp/TSTInfo.cs b/crypto/src/asn1/tsp/TSTInfo.cs
index 89f3e8b38..ee4dd67f1 100644
--- a/crypto/src/asn1/tsp/TSTInfo.cs
+++ b/crypto/src/asn1/tsp/TSTInfo.cs
@@ -214,37 +214,20 @@ namespace Org.BouncyCastle.Asn1.Tsp
 		 *
 		 * </pre>
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			Asn1EncodableVector v = new Asn1EncodableVector(
-				version, tsaPolicyId, messageImprint, serialNumber, genTime);
-
-			if (accuracy != null)
-			{
-				v.Add(accuracy);
-			}
-
-			if (ordering != null && ordering.IsTrue)
-			{
-				v.Add(ordering);
-			}
-
-			if (nonce != null)
-			{
-				v.Add(nonce);
-			}
-
-			if (tsa != null)
-			{
-				v.Add(new DerTaggedObject(true, 0, tsa));
-			}
-
-			if (extensions != null)
-			{
-				v.Add(new DerTaggedObject(false, 1, extensions));
-			}
-
-			return new DerSequence(v);
-		}
+        public override Asn1Object ToAsn1Object()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector(version, tsaPolicyId, messageImprint, serialNumber, genTime);
+            v.AddOptional(accuracy);
+
+            if (ordering != null && ordering.IsTrue)
+            {
+                v.Add(ordering);
+            }
+
+            v.AddOptional(nonce);
+            v.AddOptionalTagged(true, 0, tsa);
+            v.AddOptionalTagged(false, 1, extensions);
+            return new DerSequence(v);
+        }
 	}
 }
diff --git a/crypto/src/asn1/tsp/TimeStampReq.cs b/crypto/src/asn1/tsp/TimeStampReq.cs
index 5b05f3369..b71fe83ab 100644
--- a/crypto/src/asn1/tsp/TimeStampReq.cs
+++ b/crypto/src/asn1/tsp/TimeStampReq.cs
@@ -134,32 +134,18 @@ namespace Org.BouncyCastle.Asn1.Tsp
 		 * }
 		 * </pre>
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			Asn1EncodableVector v = new Asn1EncodableVector(
-				version, messageImprint);
-
-			if (tsaPolicy != null)
-			{
-				v.Add(tsaPolicy);
-			}
-
-			if (nonce != null)
-			{
-				v.Add(nonce);
-			}
-
-			if (certReq != null && certReq.IsTrue)
-			{
-				v.Add(certReq);
-			}
-
-			if (extensions != null)
-			{
-				v.Add(new DerTaggedObject(false, 0, extensions));
-			}
-
-			return new DerSequence(v);
-		}
+        public override Asn1Object ToAsn1Object()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector(version, messageImprint);
+            v.AddOptional(tsaPolicy, nonce);
+
+            if (certReq != null && certReq.IsTrue)
+            {
+                v.Add(certReq);
+            }
+
+            v.AddOptionalTagged(false, 0, extensions);
+            return new DerSequence(v);
+        }
 	}
 }
diff --git a/crypto/src/asn1/tsp/TimeStampResp.cs b/crypto/src/asn1/tsp/TimeStampResp.cs
index b91026064..f5186ca4f 100644
--- a/crypto/src/asn1/tsp/TimeStampResp.cs
+++ b/crypto/src/asn1/tsp/TimeStampResp.cs
@@ -65,16 +65,11 @@ namespace Org.BouncyCastle.Asn1.Tsp
 		 *   timeStampToken          TimeStampToken     OPTIONAL  }
 		 * </pre>
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			Asn1EncodableVector v = new Asn1EncodableVector(pkiStatusInfo);
-
-			if (timeStampToken != null)
-			{
-				v.Add(timeStampToken);
-			}
-
-			return new DerSequence(v);
-		}
+        public override Asn1Object ToAsn1Object()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector(pkiStatusInfo);
+            v.AddOptional(timeStampToken);
+            return new DerSequence(v);
+        }
 	}
 }