summary refs log tree commit diff
path: root/crypto/src/x509/store
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-26 20:47:24 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-26 20:47:24 +0700
commiteed964522f8e198a33267387942b1764018dfe1e (patch)
treec6bcead7e5e54c88845287d10bca6a1235e655e8 /crypto/src/x509/store
parentCleanup in PQC code (diff)
downloadBouncyCastle.NET-ed25519-eed964522f8e198a33267387942b1764018dfe1e.tar.xz
Replace IX509Store API with new store/selector API
- overhaul Cms, Pkix, X509 APIs
Diffstat (limited to 'crypto/src/x509/store')
-rw-r--r--crypto/src/x509/store/IX509Selector.cs15
-rw-r--r--crypto/src/x509/store/IX509Store.cs11
-rw-r--r--crypto/src/x509/store/IX509StoreParameters.cs8
-rw-r--r--crypto/src/x509/store/NoSuchStoreException.cs30
-rw-r--r--crypto/src/x509/store/X509AttrCertStoreSelector.cs16
-rw-r--r--crypto/src/x509/store/X509CertPairStoreSelector.cs14
-rw-r--r--crypto/src/x509/store/X509CertStoreSelector.cs7
-rw-r--r--crypto/src/x509/store/X509CollectionStore.cs51
-rw-r--r--crypto/src/x509/store/X509CollectionStoreParameters.cs60
-rw-r--r--crypto/src/x509/store/X509CrlStoreSelector.cs12
-rw-r--r--crypto/src/x509/store/X509StoreException.cs30
-rw-r--r--crypto/src/x509/store/X509StoreFactory.cs62
12 files changed, 17 insertions, 299 deletions
diff --git a/crypto/src/x509/store/IX509Selector.cs b/crypto/src/x509/store/IX509Selector.cs
deleted file mode 100644
index 4459903e7..000000000
--- a/crypto/src/x509/store/IX509Selector.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	public interface IX509Selector
-#if !PORTABLE
-		: ICloneable
-#endif
-	{
-#if PORTABLE
-        object Clone();
-#endif
-        bool Match(object obj);
-	}
-}
diff --git a/crypto/src/x509/store/IX509Store.cs b/crypto/src/x509/store/IX509Store.cs
deleted file mode 100644
index e5c3a462a..000000000
--- a/crypto/src/x509/store/IX509Store.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-using System.Collections;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	public interface IX509Store
-	{
-//		void Init(IX509StoreParameters parameters);
-		ICollection GetMatches(IX509Selector selector);
-	}
-}
diff --git a/crypto/src/x509/store/IX509StoreParameters.cs b/crypto/src/x509/store/IX509StoreParameters.cs
deleted file mode 100644
index aee3036c2..000000000
--- a/crypto/src/x509/store/IX509StoreParameters.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using System;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	public interface IX509StoreParameters
-	{
-	}
-}
diff --git a/crypto/src/x509/store/NoSuchStoreException.cs b/crypto/src/x509/store/NoSuchStoreException.cs
deleted file mode 100644
index 3acac536f..000000000
--- a/crypto/src/x509/store/NoSuchStoreException.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace Org.BouncyCastle.X509.Store
-{
-    [Serializable]
-    public class NoSuchStoreException
-		: X509StoreException
-	{
-		public NoSuchStoreException()
-			: base()
-		{
-		}
-
-		public NoSuchStoreException(string message)
-			: base(message)
-		{
-		}
-
-		public NoSuchStoreException(string message, Exception innerException)
-			: base(message, innerException)
-		{
-		}
-
-		protected NoSuchStoreException(SerializationInfo info, StreamingContext context)
-			: base(info, context)
-		{
-		}
-	}
-}
diff --git a/crypto/src/x509/store/X509AttrCertStoreSelector.cs b/crypto/src/x509/store/X509AttrCertStoreSelector.cs
index d60a5f23c..b25d0de19 100644
--- a/crypto/src/x509/store/X509AttrCertStoreSelector.cs
+++ b/crypto/src/x509/store/X509AttrCertStoreSelector.cs
@@ -18,11 +18,11 @@ namespace Org.BouncyCastle.X509.Store
 	* @see org.bouncycastle.x509.X509Store
 	*/
 	public class X509AttrCertStoreSelector
-		: IX509Selector
+		: ISelector<X509V2AttributeCertificate>
 	{
 		// TODO: name constraints???
 
-		private IX509AttributeCertificate attributeCert;
+		private X509V2AttributeCertificate attributeCert;
 		private DateTimeObject attributeCertificateValid;
 		private AttributeCertificateHolder holder;
 		private AttributeCertificateIssuer issuer;
@@ -49,16 +49,10 @@ namespace Org.BouncyCastle.X509.Store
 		/// <summary>
 		/// Decides if the given attribute certificate should be selected.
 		/// </summary>
-		/// <param name="obj">The attribute certificate to be checked.</param>
+		/// <param name="attrCert">The attribute certificate to be checked.</param>
 		/// <returns><code>true</code> if the object matches this selector.</returns>
-		public bool Match(
-			object obj)
+		public bool Match(X509V2AttributeCertificate attrCert)
 		{
-			if (obj == null)
-				throw new ArgumentNullException("obj");
-
-			IX509AttributeCertificate attrCert = obj as IX509AttributeCertificate;
-
 			if (attrCert == null)
 				return false;
 
@@ -160,7 +154,7 @@ namespace Org.BouncyCastle.X509.Store
 
 		/// <summary>The attribute certificate which must be matched.</summary>
 		/// <remarks>If <c>null</c> is given, any will do.</remarks>
-		public IX509AttributeCertificate AttributeCert
+		public X509V2AttributeCertificate AttributeCert
 		{
 			get { return attributeCert; }
 			set { this.attributeCert = value; }
diff --git a/crypto/src/x509/store/X509CertPairStoreSelector.cs b/crypto/src/x509/store/X509CertPairStoreSelector.cs
index 2796971c7..936da2e48 100644
--- a/crypto/src/x509/store/X509CertPairStoreSelector.cs
+++ b/crypto/src/x509/store/X509CertPairStoreSelector.cs
@@ -1,5 +1,7 @@
 using System;
 
+using Org.BouncyCastle.Utilities.Collections;
+
 namespace Org.BouncyCastle.X509.Store
 {
 	/// <remarks>
@@ -9,7 +11,7 @@ namespace Org.BouncyCastle.X509.Store
 	/// each of which, if present, must match the respective component of a pair.
 	/// </remarks>
 	public class X509CertPairStoreSelector
-		: IX509Selector
+		: ISelector<X509CertificatePair>
 	{
 		private static X509CertStoreSelector CloneSelector(
 			X509CertStoreSelector s)
@@ -59,16 +61,10 @@ namespace Org.BouncyCastle.X509.Store
 		/// <c>obj</c> is not a <code>X509CertificatePair</code>, this method
 		/// returns <code>false</code>.
 		/// </summary>
-		/// <param name="obj">The <code>X509CertificatePair</code> to be tested.</param>
+		/// <param name="pair">The <code>X509CertificatePair</code> to be tested.</param>
 		/// <returns><code>true</code> if the object matches this selector.</returns>
-		public bool Match(
-			object obj)
+		public bool Match(X509CertificatePair pair)
 		{
-			if (obj == null)
-				throw new ArgumentNullException("obj");
-
-			X509CertificatePair pair = obj as X509CertificatePair;
-
 			if (pair == null)
 				return false;
 
diff --git a/crypto/src/x509/store/X509CertStoreSelector.cs b/crypto/src/x509/store/X509CertStoreSelector.cs
index 8e22b862a..b351f1cf3 100644
--- a/crypto/src/x509/store/X509CertStoreSelector.cs
+++ b/crypto/src/x509/store/X509CertStoreSelector.cs
@@ -12,7 +12,7 @@ using Org.BouncyCastle.X509.Extension;
 namespace Org.BouncyCastle.X509.Store
 {
 	public class X509CertStoreSelector
-		: IX509Selector
+		: ISelector<X509Certificate>
 	{
 		// TODO Missing criteria?
 
@@ -160,11 +160,8 @@ namespace Org.BouncyCastle.X509.Store
 			set { subjectPublicKeyAlgID = value; }
 		}
 
-		public virtual bool Match(
-			object obj)
+		public virtual bool Match(X509Certificate c)
 		{
-			X509Certificate c = obj as X509Certificate;
-
 			if (c == null)
 				return false;
 
diff --git a/crypto/src/x509/store/X509CollectionStore.cs b/crypto/src/x509/store/X509CollectionStore.cs
deleted file mode 100644
index 92173140b..000000000
--- a/crypto/src/x509/store/X509CollectionStore.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using System;
-using System.Collections;
-
-using Org.BouncyCastle.Utilities;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	/**
-	 * A simple collection backed store.
-	 */
-	internal class X509CollectionStore
-		: IX509Store
-	{
-		private ICollection _local;
-
-		/**
-		 * Basic constructor.
-		 *
-		 * @param collection - initial contents for the store, this is copied.
-		 */
-		internal X509CollectionStore(
-			ICollection collection)
-		{
-			_local = Platform.CreateArrayList(collection);
-		}
-
-		/**
-		 * Return the matches in the collection for the passed in selector.
-		 *
-		 * @param selector the selector to match against.
-		 * @return a possibly empty collection of matching objects.
-		 */
-		public ICollection GetMatches(
-			IX509Selector selector)
-		{
-			if (selector == null)
-			{
-                return Platform.CreateArrayList(_local);
-			}
-
-            IList result = Platform.CreateArrayList();
-			foreach (object obj in _local)
-			{
-				if (selector.Match(obj))
-					result.Add(obj);
-			}
-
-			return result;
-		}
-	}
-}
diff --git a/crypto/src/x509/store/X509CollectionStoreParameters.cs b/crypto/src/x509/store/X509CollectionStoreParameters.cs
deleted file mode 100644
index 7fd047a47..000000000
--- a/crypto/src/x509/store/X509CollectionStoreParameters.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using System;
-using System.Collections;
-using System.Text;
-
-using Org.BouncyCastle.Utilities;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	/// <remarks>This class contains a collection for collection based <code>X509Store</code>s.</remarks>
-	public class X509CollectionStoreParameters
-		: IX509StoreParameters
-	{
-		private readonly IList collection;
-
-		/// <summary>
-		/// Constructor.
-		/// <p>
-		/// The collection is copied.
-		/// </p>
-		/// </summary>
-		/// <param name="collection">The collection containing X.509 object types.</param>
-		/// <exception cref="ArgumentNullException">If collection is null.</exception>
-		public X509CollectionStoreParameters(
-			ICollection collection)
-		{
-			if (collection == null)
-				throw new ArgumentNullException("collection");
-
-			this.collection = Platform.CreateArrayList(collection);
-		}
-
-		// TODO Do we need to be able to Clone() these, and should it really be shallow?
-//		/**
-//		* Returns a shallow clone. The returned contents are not copied, so adding
-//		* or removing objects will effect this.
-//		*
-//		* @return a shallow clone.
-//		*/
-//		public object Clone()
-//		{
-//			return new X509CollectionStoreParameters(collection);
-//		}
-
-		/// <summary>Returns a copy of the <code>ICollection</code>.</summary>
-		public ICollection GetCollection()
-		{
-			return Platform.CreateArrayList(collection);
-		}
-
-		/// <summary>Returns a formatted string describing the parameters.</summary>
-		public override string ToString()
-		{
-			StringBuilder sb = new StringBuilder();
-			sb.Append("X509CollectionStoreParameters: [\n");
-			sb.Append("  collection: " + collection + "\n");
-			sb.Append("]");
-			return sb.ToString();
-		}
-	}
-}
diff --git a/crypto/src/x509/store/X509CrlStoreSelector.cs b/crypto/src/x509/store/X509CrlStoreSelector.cs
index 4be2a1ef0..dcf8f8876 100644
--- a/crypto/src/x509/store/X509CrlStoreSelector.cs
+++ b/crypto/src/x509/store/X509CrlStoreSelector.cs
@@ -5,13 +5,14 @@ using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
+using Org.BouncyCastle.Utilities.Collections;
 using Org.BouncyCastle.Utilities.Date;
 using Org.BouncyCastle.X509.Extension;
 
 namespace Org.BouncyCastle.X509.Store
 {
 	public class X509CrlStoreSelector
-		: IX509Selector
+		: ISelector<X509Crl>
 	{
 		// TODO Missing criteria?
 
@@ -21,7 +22,7 @@ namespace Org.BouncyCastle.X509.Store
 		private BigInteger maxCrlNumber;
 		private BigInteger minCrlNumber;
 
-		private IX509AttributeCertificate attrCertChecking;
+		private X509V2AttributeCertificate attrCertChecking;
 		private bool completeCrlEnabled;
 		private bool deltaCrlIndicatorEnabled;
 		private byte[] issuingDistributionPoint;
@@ -98,7 +99,7 @@ namespace Org.BouncyCastle.X509.Store
 		 *             <code>null</code>)
 		 * @see #getAttrCertificateChecking()
 		 */
-		public IX509AttributeCertificate AttrCertChecking
+		public X509V2AttributeCertificate AttrCertChecking
 		{
 			get { return attrCertChecking; }
 			set { this.attrCertChecking = value; }
@@ -180,11 +181,8 @@ namespace Org.BouncyCastle.X509.Store
 			set { this.maxBaseCrlNumber = value; }
 		}
 
-		public virtual bool Match(
-			object obj)
+		public virtual bool Match(X509Crl c)
 		{
-			X509Crl c = obj as X509Crl;
-
 			if (c == null)
 				return false;
 
diff --git a/crypto/src/x509/store/X509StoreException.cs b/crypto/src/x509/store/X509StoreException.cs
deleted file mode 100644
index 0ad32c2ef..000000000
--- a/crypto/src/x509/store/X509StoreException.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-
-namespace Org.BouncyCastle.X509.Store
-{
-    [Serializable]
-    public class X509StoreException
-		: Exception
-	{
-		public X509StoreException()
-			: base()
-		{
-		}
-
-		public X509StoreException(string message)
-			: base(message)
-		{
-		}
-
-		public X509StoreException(string message, Exception innerException)
-			: base(message, innerException)
-		{
-		}
-
-		protected X509StoreException(SerializationInfo info, StreamingContext context)
-			: base(info, context)
-		{
-		}
-	}
-}
diff --git a/crypto/src/x509/store/X509StoreFactory.cs b/crypto/src/x509/store/X509StoreFactory.cs
deleted file mode 100644
index 96f22be3f..000000000
--- a/crypto/src/x509/store/X509StoreFactory.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Collections;
-
-using Org.BouncyCastle.Utilities;
-
-namespace Org.BouncyCastle.X509.Store
-{
-	public sealed class X509StoreFactory
-	{
-		private X509StoreFactory()
-		{
-		}
-
-		public static IX509Store Create(
-			string					type,
-			IX509StoreParameters	parameters)
-		{
-			if (type == null)
-				throw new ArgumentNullException("type");
-
-			string[] parts = Platform.ToUpperInvariant(type).Split('/');
-
-            if (parts.Length < 2)
-				throw new ArgumentException("type");
-
-			if (parts[1] != "COLLECTION")
-				throw new NoSuchStoreException("X.509 store type '" + type + "' not available.");
-
-			X509CollectionStoreParameters p = (X509CollectionStoreParameters) parameters;
-			ICollection coll = p.GetCollection();
-
-			switch (parts[0])
-			{
-				case "ATTRIBUTECERTIFICATE":
-					checkCorrectType(coll, typeof(IX509AttributeCertificate));
-					break;
-				case "CERTIFICATE":
-					checkCorrectType(coll, typeof(X509Certificate));
-					break;
-				case "CERTIFICATEPAIR":
-					checkCorrectType(coll, typeof(X509CertificatePair));
-					break;
-				case "CRL":
-					checkCorrectType(coll, typeof(X509Crl));
-					break;
-				default:
-					throw new NoSuchStoreException("X.509 store type '" + type + "' not available.");
-			}
-
-			return new X509CollectionStore(coll);
-		}
-
-		private static void checkCorrectType(ICollection coll, Type t)
-		{
-			foreach (object o in coll)
-			{
-				if (!t.IsInstanceOfType(o))
-					throw new InvalidCastException("Can't cast object to type: " + t.FullName);
-			}
-		}
-	}
-}