summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-24 11:49:55 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-24 11:49:55 +0700
commit33e4b035e8dc3721cd311956227ad29c0f8a97d0 (patch)
tree61afd296ddc5e40bad9a72c3c7976a16e2796e42
parentSimplify attributes (diff)
downloadBouncyCastle.NET-ed25519-33e4b035e8dc3721cd311956227ad29c0f8a97d0.tar.xz
Some modern syntax updates
-rw-r--r--crypto/src/asn1/ASN1StreamParser.cs4
-rw-r--r--crypto/src/asn1/Asn1InputStream.cs15
-rw-r--r--crypto/src/asn1/Asn1TaggedObject.cs16
-rw-r--r--crypto/src/math/ec/multiplier/FixedPointUtilities.cs2
-rw-r--r--crypto/src/math/ec/multiplier/WTauNafMultiplier.cs4
5 files changed, 19 insertions, 22 deletions
diff --git a/crypto/src/asn1/ASN1StreamParser.cs b/crypto/src/asn1/ASN1StreamParser.cs
index f805f68a5..490b20ccf 100644
--- a/crypto/src/asn1/ASN1StreamParser.cs
+++ b/crypto/src/asn1/ASN1StreamParser.cs
@@ -235,9 +235,9 @@ namespace Org.BouncyCastle.Asn1
 
 		private void Set00Check(bool enabled)
 		{
-			if (_in is IndefiniteLengthInputStream)
+			if (_in is IndefiniteLengthInputStream indef)
 			{
-				((IndefiniteLengthInputStream)_in).SetEofOn00(enabled);
+				indef.SetEofOn00(enabled);
 			}
 		}
 	}
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs
index 33e7b0e0c..1df6a0206 100644
--- a/crypto/src/asn1/Asn1InputStream.cs
+++ b/crypto/src/asn1/Asn1InputStream.cs
@@ -21,17 +21,14 @@ namespace Org.BouncyCastle.Asn1
 
         internal static int FindLimit(Stream input)
         {
-            if (input is LimitedInputStream)
-                return ((LimitedInputStream)input).Limit;
+            if (input is LimitedInputStream limited)
+                return limited.Limit;
 
-            if (input is Asn1InputStream)
-                return ((Asn1InputStream)input).Limit;
+            if (input is Asn1InputStream asn1)
+                return asn1.Limit;
 
-            if (input is MemoryStream)
-            {
-                MemoryStream mem = (MemoryStream)input;
-                return (int)(mem.Length - mem.Position);
-            }
+            if (input is MemoryStream memory)
+                return (int)(memory.Length - memory.Position);
 
             return int.MaxValue;
         }
diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs
index cba199fb3..46aa137a8 100644
--- a/crypto/src/asn1/Asn1TaggedObject.cs
+++ b/crypto/src/asn1/Asn1TaggedObject.cs
@@ -26,17 +26,17 @@ namespace Org.BouncyCastle.Asn1
                 return (Asn1TaggedObject)obj;
             }
             //else if (obj is Asn1TaggedObjectParser)
-            else if (obj is IAsn1Convertible)
+            else if (obj is IAsn1Convertible asn1Convertible)
             {
-                Asn1Object asn1Object = ((IAsn1Convertible)obj).ToAsn1Object();
-                if (asn1Object is Asn1TaggedObject)
-                    return (Asn1TaggedObject)asn1Object;
+                Asn1Object asn1Object = asn1Convertible.ToAsn1Object();
+                if (asn1Object is Asn1TaggedObject taggedObject)
+                    return taggedObject;
             }
-            else if (obj is byte[])
+            else if (obj is byte[] byteArray)
             {
                 try
                 {
-                    return CheckedCast(FromByteArray((byte[])obj));
+                    return CheckedCast(FromByteArray(byteArray));
                 }
                 catch (IOException e)
                 {
@@ -313,8 +313,8 @@ namespace Org.BouncyCastle.Asn1
                 return universalType.FromImplicitConstructed(RebuildConstructed(baseObject));
             case ParsedImplicit:
             {
-                if (baseObject is Asn1Sequence)
-                    return universalType.FromImplicitConstructed((Asn1Sequence)baseObject);
+                if (baseObject is Asn1Sequence asn1Sequence)
+                    return universalType.FromImplicitConstructed(asn1Sequence);
 
                 return universalType.FromImplicitPrimitive((DerOctetString)baseObject);
             }
diff --git a/crypto/src/math/ec/multiplier/FixedPointUtilities.cs b/crypto/src/math/ec/multiplier/FixedPointUtilities.cs
index 88f178e24..fd158fae9 100644
--- a/crypto/src/math/ec/multiplier/FixedPointUtilities.cs
+++ b/crypto/src/math/ec/multiplier/FixedPointUtilities.cs
@@ -34,7 +34,7 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
 
             public PreCompInfo Precompute(PreCompInfo existing)
             {
-                FixedPointPreCompInfo existingFP = (existing is FixedPointPreCompInfo) ? (FixedPointPreCompInfo)existing : null;
+                FixedPointPreCompInfo existingFP = existing as FixedPointPreCompInfo;
 
                 ECCurve c = m_p.Curve;
                 int bits = FixedPointUtilities.GetCombSize(c);
diff --git a/crypto/src/math/ec/multiplier/WTauNafMultiplier.cs b/crypto/src/math/ec/multiplier/WTauNafMultiplier.cs
index 4dce54440..8e50a161d 100644
--- a/crypto/src/math/ec/multiplier/WTauNafMultiplier.cs
+++ b/crypto/src/math/ec/multiplier/WTauNafMultiplier.cs
@@ -24,10 +24,10 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
         */
         protected override ECPoint MultiplyPositive(ECPoint point, BigInteger k)
         {
-            if (!(point is AbstractF2mPoint))
+            AbstractF2mPoint p = point as AbstractF2mPoint;
+            if (p == null)
                 throw new ArgumentException("Only AbstractF2mPoint can be used in WTauNafMultiplier");
 
-            AbstractF2mPoint p = (AbstractF2mPoint)point;
             AbstractF2mCurve curve = (AbstractF2mCurve)p.Curve;
             int m = curve.FieldSize;
             sbyte a = (sbyte)curve.A.ToBigInteger().IntValue;