From 5f094eb098767afcf461b03a9a783957c7da69db Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 28 Jan 2023 20:06:19 +0700 Subject: Refactor X509CertificatePair --- crypto/test/src/test/TestUtilities.cs | 142 ------------------------ crypto/test/src/test/X509CertificatePairTest.cs | 26 ----- 2 files changed, 168 deletions(-) (limited to 'crypto/test/src') diff --git a/crypto/test/src/test/TestUtilities.cs b/crypto/test/src/test/TestUtilities.cs index 5835784e9..be983637c 100644 --- a/crypto/test/src/test/TestUtilities.cs +++ b/crypto/test/src/test/TestUtilities.cs @@ -109,147 +109,5 @@ namespace Org.BouncyCastle.Tests return crlGen.Generate(new Asn1SignatureFactory("SHA256WithRSAEncryption", caKey, null)); } - - public static X509Certificate CreateExceptionCertificate( - bool exceptionOnEncode) - { - return new ExceptionCertificate(exceptionOnEncode); - } - - private class ExceptionCertificate - : X509Certificate - { - private bool _exceptionOnEncode; - - public ExceptionCertificate( - bool exceptionOnEncode) - { - _exceptionOnEncode = exceptionOnEncode; - } - - public override void CheckValidity() - { - throw new CertificateNotYetValidException(); - } - - public override void CheckValidity( - DateTime date) - { - throw new CertificateExpiredException(); - } - - public override int Version - { - get { return 0; } - } - - public override BigInteger SerialNumber - { - get { return null; } - } - - public override X509Name IssuerDN - { - get { return null; } - } - - public override X509Name SubjectDN - { - get { return null; } - } - - public override DateTime NotBefore - { - get { return DateTime.MaxValue; } - } - - public override DateTime NotAfter - { - get { return DateTime.MinValue; } - } - - public override byte[] GetTbsCertificate() - { - throw new CertificateEncodingException(); - } - - public override byte[] GetSignature() - { - return new byte[0]; - } - - public override string SigAlgName - { - get { return null; } - } - - public override string SigAlgOid - { - get { return null; } - } - - public override byte[] GetSigAlgParams() - { - return new byte[0]; - } - - public override DerBitString IssuerUniqueID - { - get { return null; } - } - - public override DerBitString SubjectUniqueID - { - get { return null; } - } - - public override bool[] GetKeyUsage() - { - return new bool[0]; - } - - public override int GetBasicConstraints() - { - return 0; - } - - public override byte[] GetEncoded() - { - if (_exceptionOnEncode) - throw new CertificateEncodingException(); - - return new byte[0]; - } - - public override void Verify(AsymmetricKeyParameter key) - { - throw new CertificateException(); - } - - public override string ToString() - { - return null; - } - - public override AsymmetricKeyParameter GetPublicKey() - { - return null; - } - - public override ISet GetCriticalExtensionOids() - { - return null; - } - - public override ISet GetNonCriticalExtensionOids() - { - return null; - } - - public override Asn1OctetString GetExtensionValue(DerObjectIdentifier oid) - { - return null; - } - } } } diff --git a/crypto/test/src/test/X509CertificatePairTest.cs b/crypto/test/src/test/X509CertificatePairTest.cs index ac6966150..71a0887f3 100644 --- a/crypto/test/src/test/X509CertificatePairTest.cs +++ b/crypto/test/src/test/X509CertificatePairTest.cs @@ -99,32 +99,6 @@ namespace Org.BouncyCastle.Tests { Fail("encoding check"); } - - pair4 = new X509CertificatePair(rootCert, TestUtilities.CreateExceptionCertificate(false)); - - try - { - pair4.GetEncoded(); - - Fail("no exception on bad GetEncoded()"); - } - catch (CertificateEncodingException) - { - // expected - } - - pair4 = new X509CertificatePair(rootCert, TestUtilities.CreateExceptionCertificate(true)); - - try - { - pair4.GetEncoded(); - - Fail("no exception on exception GetEncoded()"); - } - catch (CertificateEncodingException) - { - // expected - } } public override string Name -- cgit 1.4.1