summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-07 17:19:28 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-07 17:19:28 +0700
commitd4978555b33327c750d59dc2cf2aa9874d122964 (patch)
tree17db33a8f9afdab5e2de187fd0b8616679849715
parentFix serial number comparison (diff)
downloadBouncyCastle.NET-ed25519-d4978555b33327c750d59dc2cf2aa9874d122964.tar.xz
Misc. refactoring
-rw-r--r--crypto/src/asn1/x509/OtherName.cs27
-rw-r--r--crypto/src/crypto/engines/DesEdeEngine.cs11
-rw-r--r--crypto/src/crypto/engines/RC4Engine.cs8
-rw-r--r--crypto/src/pkix/PkixCertPathValidatorUtilities.cs2
-rw-r--r--crypto/src/x509/X509Crl.cs10
-rw-r--r--crypto/test/src/tls/test/NetworkStream.cs2
-rw-r--r--crypto/test/src/tls/test/PipedStream.cs2
7 files changed, 25 insertions, 37 deletions
diff --git a/crypto/src/asn1/x509/OtherName.cs b/crypto/src/asn1/x509/OtherName.cs
index 3e6a61499..bd80fe9ec 100644
--- a/crypto/src/asn1/x509/OtherName.cs
+++ b/crypto/src/asn1/x509/OtherName.cs
@@ -13,9 +13,6 @@ namespace Org.BouncyCastle.Asn1.X509
     public class OtherName
         : Asn1Encodable
     {
-        private readonly DerObjectIdentifier typeID;
-        private readonly Asn1Encodable value;
-
         /**
          * OtherName factory method.
          * @param obj the object used to construct an instance of <code>
@@ -29,13 +26,21 @@ namespace Org.BouncyCastle.Asn1.X509
          */
         public static OtherName GetInstance(object obj)
         {
-            if (obj is OtherName)
-                return (OtherName)obj;
             if (obj == null)
                 return null;
+            if (obj is OtherName otherName)
+                return otherName;
             return new OtherName(Asn1Sequence.GetInstance(obj));
         }
 
+        public static OtherName GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
+
+        private readonly DerObjectIdentifier typeID;
+        private readonly Asn1Encodable value;
+
         /**
          * Base constructor.
          * @param typeID the type of the other name.
@@ -50,18 +55,12 @@ namespace Org.BouncyCastle.Asn1.X509
         private OtherName(Asn1Sequence seq)
         {
             this.typeID = DerObjectIdentifier.GetInstance(seq[0]);
-            this.value = DerTaggedObject.GetInstance(seq[1]).GetObject(); // explicitly tagged
+            this.value = Asn1Utilities.GetExplicitContextBaseObject(Asn1TaggedObject.GetInstance(seq[1]), tagNo: 0);
         }
 
-        public virtual DerObjectIdentifier TypeID
-        {
-            get { return typeID; }
-        }
+        public virtual DerObjectIdentifier TypeID => typeID;
 
-        public Asn1Encodable Value
-        {
-            get { return value; }
-        }
+        public Asn1Encodable Value => value;
 
         public override Asn1Object ToAsn1Object()
         {
diff --git a/crypto/src/crypto/engines/DesEdeEngine.cs b/crypto/src/crypto/engines/DesEdeEngine.cs
index a9185d295..58b9d5090 100644
--- a/crypto/src/crypto/engines/DesEdeEngine.cs
+++ b/crypto/src/crypto/engines/DesEdeEngine.cs
@@ -21,14 +21,13 @@ namespace Org.BouncyCastle.Crypto.Engines
         * @exception ArgumentException if the parameters argument is
         * inappropriate.
         */
-        public override void Init(
-            bool				forEncryption,
-            ICipherParameters	parameters)
+        public override void Init(bool forEncryption, ICipherParameters parameters)
         {
-            if (!(parameters is KeyParameter))
-                throw new ArgumentException("invalid parameter passed to DESede init - " + Platform.GetTypeName(parameters));
+            if (!(parameters is KeyParameter keyParameter))
+                throw new ArgumentException(
+                    "invalid parameter passed to DESede init - " + Platform.GetTypeName(parameters));
 
-            byte[] keyMaster = ((KeyParameter)parameters).GetKey();
+            byte[] keyMaster = keyParameter.GetKey();
             if (keyMaster.Length != 24 && keyMaster.Length != 16)
                 throw new ArgumentException("key size must be 16 or 24 bytes.");
 
diff --git a/crypto/src/crypto/engines/RC4Engine.cs b/crypto/src/crypto/engines/RC4Engine.cs
index fe9594e10..5b2ffb238 100644
--- a/crypto/src/crypto/engines/RC4Engine.cs
+++ b/crypto/src/crypto/engines/RC4Engine.cs
@@ -28,18 +28,16 @@ namespace Org.BouncyCastle.Crypto.Engines
         * @exception ArgumentException if the parameters argument is
         * inappropriate.
         */
-        public virtual void Init(
-            bool				forEncryption,
-            ICipherParameters	parameters)
+        public virtual void Init(bool forEncryption, ICipherParameters parameters)
         {
-            if (parameters is KeyParameter)
+            if (parameters is KeyParameter keyParameter)
             {
                 /*
                 * RC4 encryption and decryption is completely
                 * symmetrical, so the 'forEncryption' is
                 * irrelevant.
                 */
-                workingKey = ((KeyParameter)parameters).GetKey();
+                workingKey = keyParameter.GetKey();
                 SetKey(workingKey);
 
                 return;
diff --git a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
index 23c5e4205..7128ab833 100644
--- a/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
+++ b/crypto/src/pkix/PkixCertPathValidatorUtilities.cs
@@ -720,7 +720,7 @@ namespace Org.BouncyCastle.Pkix
 			//        if (dp.getDistributionPoint() != null)
 			//        {
 			//            // look for nameRelativeToCRLIssuer
-			//            if (dp.getDistributionPoint().getType() == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER)
+			//            if (dp.getDistributionPoint().Type == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER)
 			//            {
 			//                // append fragment to issuer, only one
 			//                // issuer can be there, if this is given
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index a3f08a0ed..3780d277a 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -404,15 +404,7 @@ namespace Org.BouncyCastle.X509
 		 * @return true if the given certificate is on this CRL,
 		 * false otherwise.
 		 */
-//		public bool IsRevoked(
-//			Certificate cert)
-//		{
-//			if (!cert.getType().Equals("X.509"))
-//			{
-//				throw new RuntimeException("X.509 CRL used with non X.509 Cert");
-//			}
-		public virtual bool IsRevoked(
-			X509Certificate cert)
+		public virtual bool IsRevoked(X509Certificate cert)
 		{
 			CrlEntry[] certs = c.GetRevokedCertificates();
 
diff --git a/crypto/test/src/tls/test/NetworkStream.cs b/crypto/test/src/tls/test/NetworkStream.cs
index ed1b21014..013c27a12 100644
--- a/crypto/test/src/tls/test/NetworkStream.cs
+++ b/crypto/test/src/tls/test/NetworkStream.cs
@@ -97,7 +97,7 @@ namespace Org.BouncyCastle.Tls.Tests
             lock (this)
             {
                 if (m_closed)
-                    throw new ObjectDisposedException(this.GetType().Name);
+                    throw new ObjectDisposedException(GetType().FullName);
             }
         }
     }
diff --git a/crypto/test/src/tls/test/PipedStream.cs b/crypto/test/src/tls/test/PipedStream.cs
index 95c3de465..82cd352af 100644
--- a/crypto/test/src/tls/test/PipedStream.cs
+++ b/crypto/test/src/tls/test/PipedStream.cs
@@ -126,7 +126,7 @@ namespace Org.BouncyCastle.Tls.Tests
         private void CheckOpen()
         {
             if (m_closed)
-                throw new ObjectDisposedException(this.GetType().Name);
+                throw new ObjectDisposedException(GetType().FullName);
         }
 
         private void WaitForData()