diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crmf/CertificateRequestMessageBuilder.cs | 9 | ||||
-rw-r--r-- | crypto/test/src/cmp/test/ProtectedMessageTest.cs | 22 |
2 files changed, 18 insertions, 13 deletions
diff --git a/crypto/src/crmf/CertificateRequestMessageBuilder.cs b/crypto/src/crmf/CertificateRequestMessageBuilder.cs index 9a33fd964..38e95dfe7 100644 --- a/crypto/src/crmf/CertificateRequestMessageBuilder.cs +++ b/crypto/src/crmf/CertificateRequestMessageBuilder.cs @@ -71,9 +71,9 @@ namespace Org.BouncyCastle.Crmf return this; } - public CertificateRequestMessageBuilder SetValidity(Time notBefore, Time notAfter) + public CertificateRequestMessageBuilder SetValidity(DateTime? notBefore, DateTime? notAfter) { - _templateBuilder.SetValidity(new OptionalValidity(notBefore, notAfter)); + _templateBuilder.SetValidity(new OptionalValidity(CreateTime(notBefore), CreateTime(notAfter))); return this; } @@ -256,5 +256,10 @@ namespace Org.BouncyCastle.Crmf return new CertificateRequestMessage(CertReqMsg.GetInstance(new DerSequence(v))); } + + private static Time CreateTime(DateTime? dateTime) + { + return dateTime == null ? null : new Time(dateTime.Value); + } } } diff --git a/crypto/test/src/cmp/test/ProtectedMessageTest.cs b/crypto/test/src/cmp/test/ProtectedMessageTest.cs index 4c242d48a..b66e11bac 100644 --- a/crypto/test/src/cmp/test/ProtectedMessageTest.cs +++ b/crypto/test/src/cmp/test/ProtectedMessageTest.cs @@ -73,36 +73,36 @@ namespace Org.BouncyCastle.Cmp.Tests rsaKeyPairGenerator.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(65537), new SecureRandom(), 2048, 100)); AsymmetricCipherKeyPair rsaKeyPair = rsaKeyPairGenerator.GenerateKeyPair(); - doNotBeforeNotAfterTest(rsaKeyPair, MakeUtcDateTime(1, 1, 1, 0, 0, 1), MakeUtcDateTime(1, 1, 1, 0, 0, 10)); - doNotBeforeNotAfterTest(rsaKeyPair, DateTime.MinValue, MakeUtcDateTime(1, 1, 1, 0, 0, 10)); - doNotBeforeNotAfterTest(rsaKeyPair, MakeUtcDateTime(1, 1, 1, 0, 0, 1), DateTime.MinValue); + DoNotBeforeNotAfterTest(rsaKeyPair, MakeUtcDateTime(1, 1, 1, 0, 0, 1), MakeUtcDateTime(1, 1, 1, 0, 0, 10)); + DoNotBeforeNotAfterTest(rsaKeyPair, null, MakeUtcDateTime(1, 1, 1, 0, 0, 10)); + DoNotBeforeNotAfterTest(rsaKeyPair, MakeUtcDateTime(1, 1, 1, 0, 0, 1), null); } - private void doNotBeforeNotAfterTest(AsymmetricCipherKeyPair kp, DateTime notBefore, DateTime notAfter) + private void DoNotBeforeNotAfterTest(AsymmetricCipherKeyPair kp, DateTime? notBefore, DateTime? notAfter) { CertificateRequestMessageBuilder builder = new CertificateRequestMessageBuilder(BigInteger.One) .SetPublicKey(SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(kp.Public)) .SetProofOfPossessionSubsequentMessage(SubsequentMessage.encrCert); - builder.SetValidity(new Time(notBefore), new Time(notAfter)); + builder.SetValidity(notBefore, notAfter); CertificateRequestMessage msg = builder.Build(); - if (!notBefore.Equals(DateTime.MinValue)) + if (notBefore != null) { - IsTrue("NotBefore did not match", (notBefore.Equals(msg.GetCertTemplate().Validity.NotBefore.ToDateTime()))); + IsTrue("NotBefore did not match", notBefore.Equals(msg.GetCertTemplate().Validity.NotBefore.ToDateTime())); } else { - IsTrue("Expected NotBefore to empty.", DateTime.MinValue == msg.GetCertTemplate().Validity.NotBefore.ToDateTime()); + Assert.IsNull(msg.GetCertTemplate().Validity.NotBefore); } - if (!notAfter.Equals(DateTime.MinValue)) + if (notAfter != null) { - IsTrue("NotAfter did not match", (notAfter.Equals(msg.GetCertTemplate().Validity.NotAfter.ToDateTime()))); + IsTrue("NotAfter did not match", notAfter.Equals(msg.GetCertTemplate().Validity.NotAfter.ToDateTime())); } else { - IsTrue("Expected NotAfter to be empty.", DateTime.MinValue == msg.GetCertTemplate().Validity.NotAfter.ToDateTime()); + Assert.IsNull(msg.GetCertTemplate().Validity.NotAfter); } } |