summary refs log tree commit diff
path: root/crypto/src/x509/PrincipalUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/x509/PrincipalUtil.cs')
-rw-r--r--crypto/src/x509/PrincipalUtil.cs62
1 files changed, 15 insertions, 47 deletions
diff --git a/crypto/src/x509/PrincipalUtil.cs b/crypto/src/x509/PrincipalUtil.cs
index 0edc4a395..733da1dca 100644
--- a/crypto/src/x509/PrincipalUtil.cs
+++ b/crypto/src/x509/PrincipalUtil.cs
@@ -7,64 +7,32 @@ using Org.BouncyCastle.Security.Certificates;
 
 namespace Org.BouncyCastle.X509
 {
-	/// <remarks>
-	/// A utility class that will extract X509Principal objects from X.509 certificates.
-	/// <p>
-	/// Use this in preference to trying to recreate a principal from a string, not all
-	/// DNs are what they should be, so it's best to leave them encoded where they
-	/// can be.</p>
-	/// </remarks>
-	public class PrincipalUtilities
+    /// <remarks>
+    /// A utility class that will extract X509Principal objects from X.509 certificates.
+    /// <p>
+    /// Use this in preference to trying to recreate a principal from a string, not all
+    /// DNs are what they should be, so it's best to leave them encoded where they
+    /// can be.</p>
+    /// </remarks>
+    // TODO[api] Make static
+    public class PrincipalUtilities
 	{
 		/// <summary>Return the issuer of the given cert as an X509Principal.</summary>
-		public static X509Name GetIssuerX509Principal(
-			X509Certificate cert)
+		public static X509Name GetIssuerX509Principal(X509Certificate cert)
 		{
-			try
-			{
-				TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance(
-					Asn1Object.FromByteArray(cert.GetTbsCertificate()));
-
-				return tbsCert.Issuer;
-			}
-			catch (Exception e)
-			{
-				throw new CertificateEncodingException("Could not extract issuer", e);
-			}
+            return cert.CertificateStructure.TbsCertificate.Issuer;
 		}
 
 		/// <summary>Return the subject of the given cert as an X509Principal.</summary>
-		public static X509Name GetSubjectX509Principal(
-			X509Certificate cert)
+		public static X509Name GetSubjectX509Principal(X509Certificate cert)
 		{
-			try
-			{
-				TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance(
-					Asn1Object.FromByteArray(cert.GetTbsCertificate()));
-
-				return tbsCert.Subject;
-			}
-			catch (Exception e)
-			{
-				throw new CertificateEncodingException("Could not extract subject", e);
-			}
+            return cert.CertificateStructure.TbsCertificate.Subject;
 		}
 
 		/// <summary>Return the issuer of the given CRL as an X509Principal.</summary>
-		public static X509Name GetIssuerX509Principal(
-			X509Crl crl)
+		public static X509Name GetIssuerX509Principal(X509Crl crl)
 		{
-			try
-			{
-				TbsCertificateList tbsCertList = TbsCertificateList.GetInstance(
-					Asn1Object.FromByteArray(crl.GetTbsCertList()));
-
-				return tbsCertList.Issuer;
-			}
-			catch (Exception e)
-			{
-				throw new CrlException("Could not extract issuer", e);
-			}
+			return crl.CertificateList.TbsCertList.Issuer;
 		}
 	}
 }