diff --git a/crypto/src/asn1/ocsp/BasicOCSPResponse.cs b/crypto/src/asn1/ocsp/BasicOCSPResponse.cs
index e6aa1f86b..45dadba4f 100644
--- a/crypto/src/asn1/ocsp/BasicOCSPResponse.cs
+++ b/crypto/src/asn1/ocsp/BasicOCSPResponse.cs
@@ -123,15 +123,9 @@ namespace Org.BouncyCastle.Asn1.Ocsp
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(
- tbsResponseData, signatureAlgorithm, signature);
-
- if (certs != null)
- {
- v.Add(new DerTaggedObject(true, 0, certs));
- }
-
- return new DerSequence(v);
+ Asn1EncodableVector v = new Asn1EncodableVector(tbsResponseData, signatureAlgorithm, signature);
+ v.AddOptionalTagged(true, 0, certs);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/CrlID.cs b/crypto/src/asn1/ocsp/CrlID.cs
index cfb3d6fcb..3b3869a7a 100644
--- a/crypto/src/asn1/ocsp/CrlID.cs
+++ b/crypto/src/asn1/ocsp/CrlID.cs
@@ -60,23 +60,10 @@ namespace Org.BouncyCastle.Asn1.Ocsp
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector();
-
- if (crlUrl != null)
- {
- v.Add(new DerTaggedObject(true, 0, crlUrl));
- }
-
- if (crlNum != null)
- {
- v.Add(new DerTaggedObject(true, 1, crlNum));
- }
-
- if (crlTime != null)
- {
- v.Add(new DerTaggedObject(true, 2, crlTime));
- }
-
- return new DerSequence(v);
+ v.AddOptionalTagged(true, 0, crlUrl);
+ v.AddOptionalTagged(true, 1, crlNum);
+ v.AddOptionalTagged(true, 2, crlTime);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/OCSPRequest.cs b/crypto/src/asn1/ocsp/OCSPRequest.cs
index 2407678b4..6ecd29cae 100644
--- a/crypto/src/asn1/ocsp/OCSPRequest.cs
+++ b/crypto/src/asn1/ocsp/OCSPRequest.cs
@@ -77,13 +77,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(tbsRequest);
-
- if (optionalSignature != null)
- {
- v.Add(new DerTaggedObject(true, 0, optionalSignature));
- }
-
- return new DerSequence(v);
+ v.AddOptionalTagged(true, 0, optionalSignature);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/OCSPResponse.cs b/crypto/src/asn1/ocsp/OCSPResponse.cs
index 9477b61c0..649172947 100644
--- a/crypto/src/asn1/ocsp/OCSPResponse.cs
+++ b/crypto/src/asn1/ocsp/OCSPResponse.cs
@@ -78,13 +78,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(responseStatus);
-
- if (responseBytes != null)
- {
- v.Add(new DerTaggedObject(true, 0, responseBytes));
- }
-
- return new DerSequence(v);
+ v.AddOptionalTagged(true, 0, responseBytes);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/Request.cs b/crypto/src/asn1/ocsp/Request.cs
index 26e81ba70..21121cb28 100644
--- a/crypto/src/asn1/ocsp/Request.cs
+++ b/crypto/src/asn1/ocsp/Request.cs
@@ -79,13 +79,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(reqCert);
-
- if (singleRequestExtensions != null)
- {
- v.Add(new DerTaggedObject(true, 0, singleRequestExtensions));
- }
-
- return new DerSequence(v);
+ v.AddOptionalTagged(true, 0, singleRequestExtensions);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/ResponseData.cs b/crypto/src/asn1/ocsp/ResponseData.cs
index 70620cbc3..a5769c0fa 100644
--- a/crypto/src/asn1/ocsp/ResponseData.cs
+++ b/crypto/src/asn1/ocsp/ResponseData.cs
@@ -140,19 +140,14 @@ namespace Org.BouncyCastle.Asn1.Ocsp
{
Asn1EncodableVector v = new Asn1EncodableVector();
- if (versionPresent || !version.Equals(V1))
- {
- v.Add(new DerTaggedObject(true, 0, version));
- }
-
- v.Add(responderID, producedAt, responses);
-
- if (responseExtensions != null)
+ if (versionPresent || !version.Equals(V1))
{
- v.Add(new DerTaggedObject(true, 1, responseExtensions));
+ v.Add(new DerTaggedObject(true, 0, version));
}
- return new DerSequence(v);
+ v.Add(responderID, producedAt, responses);
+ v.AddOptionalTagged(true, 1, responseExtensions);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/RevokedInfo.cs b/crypto/src/asn1/ocsp/RevokedInfo.cs
index ee9e55429..c67be0678 100644
--- a/crypto/src/asn1/ocsp/RevokedInfo.cs
+++ b/crypto/src/asn1/ocsp/RevokedInfo.cs
@@ -83,14 +83,9 @@ namespace Org.BouncyCastle.Asn1.Ocsp
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(revocationTime);
-
- if (revocationReason != null)
- {
- v.Add(new DerTaggedObject(true, 0, revocationReason));
- }
-
- return new DerSequence(v);
+ Asn1EncodableVector v = new Asn1EncodableVector(revocationTime);
+ v.AddOptionalTagged(true, 0, revocationReason);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/ServiceLocator.cs b/crypto/src/asn1/ocsp/ServiceLocator.cs
index 4ba252be3..c6a9514ae 100644
--- a/crypto/src/asn1/ocsp/ServiceLocator.cs
+++ b/crypto/src/asn1/ocsp/ServiceLocator.cs
@@ -83,13 +83,8 @@ namespace Org.BouncyCastle.Asn1.Ocsp
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(issuer);
-
- if (locator != null)
- {
- v.Add(locator);
- }
-
- return new DerSequence(v);
+ v.AddOptional(locator);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/Signature.cs b/crypto/src/asn1/ocsp/Signature.cs
index d6b4ccfbf..c6f149d62 100644
--- a/crypto/src/asn1/ocsp/Signature.cs
+++ b/crypto/src/asn1/ocsp/Signature.cs
@@ -101,15 +101,9 @@ namespace Org.BouncyCastle.Asn1.Ocsp
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(
- signatureAlgorithm, signatureValue);
-
- if (certs != null)
- {
- v.Add(new DerTaggedObject(true, 0, certs));
- }
-
- return new DerSequence(v);
+ Asn1EncodableVector v = new Asn1EncodableVector(signatureAlgorithm, signatureValue);
+ v.AddOptionalTagged(true, 0, certs);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/SingleResponse.cs b/crypto/src/asn1/ocsp/SingleResponse.cs
index 544232abe..ecdf3dab0 100644
--- a/crypto/src/asn1/ocsp/SingleResponse.cs
+++ b/crypto/src/asn1/ocsp/SingleResponse.cs
@@ -118,20 +118,10 @@ namespace Org.BouncyCastle.Asn1.Ocsp
*/
public override Asn1Object ToAsn1Object()
{
- Asn1EncodableVector v = new Asn1EncodableVector(
- certID, certStatus, thisUpdate);
-
- if (nextUpdate != null)
- {
- v.Add(new DerTaggedObject(true, 0, nextUpdate));
- }
-
- if (singleExtensions != null)
- {
- v.Add(new DerTaggedObject(true, 1, singleExtensions));
- }
-
- return new DerSequence(v);
+ Asn1EncodableVector v = new Asn1EncodableVector(certID, certStatus, thisUpdate);
+ v.AddOptionalTagged(true, 0, nextUpdate);
+ v.AddOptionalTagged(true, 1, singleExtensions);
+ return new DerSequence(v);
}
}
}
diff --git a/crypto/src/asn1/ocsp/TBSRequest.cs b/crypto/src/asn1/ocsp/TBSRequest.cs
index 1ad8649f8..0166c5342 100644
--- a/crypto/src/asn1/ocsp/TBSRequest.cs
+++ b/crypto/src/asn1/ocsp/TBSRequest.cs
@@ -124,28 +124,19 @@ namespace Org.BouncyCastle.Asn1.Ocsp
{
Asn1EncodableVector v = new Asn1EncodableVector();
- //
- // if default don't include - unless explicitly provided. Not strictly correct
- // but required for some requests
- //
- if (!version.Equals(V1) || versionSet)
- {
- v.Add(new DerTaggedObject(true, 0, version));
- }
-
- if (requestorName != null)
+ //
+ // if default don't include - unless explicitly provided. Not strictly correct
+ // but required for some requests
+ //
+ if (!version.Equals(V1) || versionSet)
{
- v.Add(new DerTaggedObject(true, 1, requestorName));
- }
-
- v.Add(requestList);
-
- if (requestExtensions != null)
- {
- v.Add(new DerTaggedObject(true, 2, requestExtensions));
+ v.Add(new DerTaggedObject(true, 0, version));
}
- return new DerSequence(v);
+ v.AddOptionalTagged(true, 1, requestorName);
+ v.Add(requestList);
+ v.AddOptionalTagged(true, 2, requestExtensions);
+ return new DerSequence(v);
}
}
}
|