summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-21 00:48:58 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-21 00:48:58 +0700
commita86c8ebc95aa0757ae20c6d5f850158bf588d3f0 (patch)
tree22f0a14234768db88ea00be6b435d6bfeea307ab
parentFix missing Dispose(s) of BcpgOutputStream (diff)
downloadBouncyCastle.NET-ed25519-a86c8ebc95aa0757ae20c6d5f850158bf588d3f0.tar.xz
Refactoring
-rw-r--r--crypto/src/asn1/pkcs/EncryptionScheme.cs32
-rw-r--r--crypto/src/asn1/x509/NameConstraints.cs6
-rw-r--r--crypto/src/bcpg/SecretKeyPacket.cs4
-rw-r--r--crypto/src/crypto/generators/DesEdeKeyGenerator.cs4
-rw-r--r--crypto/src/crypto/parameters/DesEdeParameters.cs5
-rw-r--r--crypto/src/crypto/parameters/DesParameters.cs2
6 files changed, 23 insertions, 30 deletions
diff --git a/crypto/src/asn1/pkcs/EncryptionScheme.cs b/crypto/src/asn1/pkcs/EncryptionScheme.cs
index 34d26e172..a073f8c17 100644
--- a/crypto/src/asn1/pkcs/EncryptionScheme.cs
+++ b/crypto/src/asn1/pkcs/EncryptionScheme.cs
@@ -1,13 +1,24 @@
-using System;
-
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Pkcs
 {
     public class EncryptionScheme
         : AlgorithmIdentifier
     {
+        public new static EncryptionScheme GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is EncryptionScheme encryptionScheme)
+                return encryptionScheme;
+            return new EncryptionScheme(Asn1Sequence.GetInstance(obj));
+        }
+
+        public new static EncryptionScheme GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
+
         public EncryptionScheme(
             DerObjectIdentifier	objectID)
             : base(objectID)
@@ -27,21 +38,6 @@ namespace Org.BouncyCastle.Asn1.Pkcs
         {
         }
 
-		public new static EncryptionScheme GetInstance(object obj)
-		{
-			if (obj is EncryptionScheme)
-			{
-				return (EncryptionScheme)obj;
-			}
-
-			if (obj is Asn1Sequence)
-			{
-				return new EncryptionScheme((Asn1Sequence)obj);
-			}
-
-			throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj");
-		}
-
 		public Asn1Object Asn1Object
 		{
 			get { return Parameters.ToAsn1Object(); }
diff --git a/crypto/src/asn1/x509/NameConstraints.cs b/crypto/src/asn1/x509/NameConstraints.cs
index 031b71ceb..87db1e534 100644
--- a/crypto/src/asn1/x509/NameConstraints.cs
+++ b/crypto/src/asn1/x509/NameConstraints.cs
@@ -6,7 +6,7 @@ namespace Org.BouncyCastle.Asn1.X509
     public class NameConstraints
 		: Asn1Encodable
 	{
-		private Asn1Sequence m_permitted, m_excluded;
+		private readonly Asn1Sequence m_permitted, m_excluded;
 
 		public static NameConstraints GetInstance(object obj)
 		{
@@ -53,12 +53,12 @@ namespace Org.BouncyCastle.Asn1.X509
 		{
 			if (permitted != null)
 			{
-				this.m_permitted = CreateSequence(permitted);
+				m_permitted = CreateSequence(permitted);
 			}
 
 			if (excluded != null)
 			{
-				this.m_excluded = CreateSequence(excluded);
+				m_excluded = CreateSequence(excluded);
 			}
 		}
 
diff --git a/crypto/src/bcpg/SecretKeyPacket.cs b/crypto/src/bcpg/SecretKeyPacket.cs
index 9b9ae93a4..15b89b404 100644
--- a/crypto/src/bcpg/SecretKeyPacket.cs
+++ b/crypto/src/bcpg/SecretKeyPacket.cs
@@ -1,12 +1,10 @@
-using System;
 using System.IO;
-using System.Linq;
 
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Bcpg
 {
-	/// <remarks>Basic packet for a PGP secret key.</remarks>
+    /// <remarks>Basic packet for a PGP secret key.</remarks>
     public class SecretKeyPacket
         : ContainedPacket //, PublicKeyAlgorithmTag
     {
diff --git a/crypto/src/crypto/generators/DesEdeKeyGenerator.cs b/crypto/src/crypto/generators/DesEdeKeyGenerator.cs
index 9e14702d1..2b3fe702b 100644
--- a/crypto/src/crypto/generators/DesEdeKeyGenerator.cs
+++ b/crypto/src/crypto/generators/DesEdeKeyGenerator.cs
@@ -10,7 +10,7 @@ namespace Org.BouncyCastle.Crypto.Generators
 		public DesEdeKeyGenerator()
 		{
 		}
-
+            
 		internal DesEdeKeyGenerator(
 			int defaultStrength)
 			: base(defaultStrength)
@@ -58,7 +58,7 @@ namespace Org.BouncyCastle.Crypto.Generators
                 random.NextBytes(newKey);
                 DesEdeParameters.SetOddParity(newKey);
             }
-            while (DesEdeParameters.IsWeakKey(newKey, 0, newKey.Length) || !DesEdeParameters.IsRealEdeKey(newKey, 0));
+            while (DesEdeParameters.IsWeakKey(newKey) || !DesEdeParameters.IsRealEdeKey(newKey, 0));
 
             return newKey;
         }
diff --git a/crypto/src/crypto/parameters/DesEdeParameters.cs b/crypto/src/crypto/parameters/DesEdeParameters.cs
index 19150c6bb..3185f6665 100644
--- a/crypto/src/crypto/parameters/DesEdeParameters.cs
+++ b/crypto/src/crypto/parameters/DesEdeParameters.cs
@@ -74,13 +74,12 @@ namespace Org.BouncyCastle.Crypto.Parameters
          * @param key bytes making up the key
          * @param offset offset into the byte array the key starts at
          */
-        public static new bool IsWeakKey(byte[]	key, int offset)
+        public static new bool IsWeakKey(byte[] key, int offset)
         {
             return IsWeakKey(key, offset, key.Length - offset);
         }
 
-		public static new bool IsWeakKey(
-			byte[] key)
+		public static new bool IsWeakKey(byte[] key)
 		{
 			return IsWeakKey(key, 0, key.Length);
 		}
diff --git a/crypto/src/crypto/parameters/DesParameters.cs b/crypto/src/crypto/parameters/DesParameters.cs
index dd575604c..6e6f5c62a 100644
--- a/crypto/src/crypto/parameters/DesParameters.cs
+++ b/crypto/src/crypto/parameters/DesParameters.cs
@@ -67,7 +67,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
         * @return true if the given DES key material is weak or semi-weak,
         *     false otherwise.
         */
-        public static bool IsWeakKey(byte[]	key, int offset)
+        public static bool IsWeakKey(byte[] key, int offset)
         {
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
             return IsWeakKey(key.AsSpan(offset));