summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2020-12-08 20:46:40 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2020-12-08 20:46:40 +0700
commit0c2afde8c313966d97a9fc64012bd04775ce51d7 (patch)
tree0a11f1a964d14917f8da64ece13f534bbb58175e
parentRefactor result normalization (diff)
downloadBouncyCastle.NET-ed25519-0c2afde8c313966d97a9fc64012bd04775ce51d7.tar.xz
Cleanup
-rw-r--r--crypto/test/src/crypto/test/CSHAKETest.cs4
-rw-r--r--crypto/test/src/crypto/test/NistEccTest.cs16
-rw-r--r--crypto/test/src/pkcs/test/PKCS12StoreTest.cs4
-rw-r--r--crypto/test/src/tsp/test/NewTspTest.cs58
4 files changed, 45 insertions, 37 deletions
diff --git a/crypto/test/src/crypto/test/CSHAKETest.cs b/crypto/test/src/crypto/test/CSHAKETest.cs
index e7c6ce9e0..753663b4b 100644
--- a/crypto/test/src/crypto/test/CSHAKETest.cs
+++ b/crypto/test/src/crypto/test/CSHAKETest.cs
@@ -136,7 +136,7 @@ namespace Org.BouncyCastle.Crypto.Tests
 
             cshake.DoOutput(res, 0, res.Length);
 
-           Assert.IsTrue(!Arrays.AreEqual(Hex.Decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res));
+            Assert.IsTrue(!Arrays.AreEqual(Hex.Decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res));
 
             cshake.DoFinal(res, 0, res.Length);
 
@@ -146,7 +146,7 @@ namespace Org.BouncyCastle.Crypto.Tests
 
             string s = Hex.ToHexString(res);
 
-            Console.WriteLine(s);
+            //Console.WriteLine(s);
 
             Assert.IsTrue(Arrays.AreEqual(Hex.Decode("c1c36925b6409a04f1b504fcbca9d82b4017277cb5ed2b2065fc1d3814d5aaf5"), res));
 
diff --git a/crypto/test/src/crypto/test/NistEccTest.cs b/crypto/test/src/crypto/test/NistEccTest.cs
index 2b0edb63d..a8e4a6cb2 100644
--- a/crypto/test/src/crypto/test/NistEccTest.cs
+++ b/crypto/test/src/crypto/test/NistEccTest.cs
@@ -2,7 +2,9 @@ using System;
 using System.Collections;
 using System.IO;
 using System.Text.RegularExpressions;
+
 using NUnit.Framework;
+
 using Org.BouncyCastle.Asn1.X9;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Math.EC;
@@ -13,7 +15,10 @@ namespace Org.BouncyCastle.Crypto.Tests
     [TestFixture]
     public class NistEccTest : SimpleTest
     {
-        public override string Name { get; } = "NistEcc";
+        public override string Name
+        {
+            get { return "NistEcc"; }
+        }
 
         public override void PerformTest()
         {
@@ -43,24 +48,25 @@ namespace Org.BouncyCastle.Crypto.Tests
                 {
                     Regex capture = new Regex(@"^ ?(\w+):? =? ?(\w+)", RegexOptions.Compiled);
                     Match data = capture.Match(line);
+                    if (!data.Success)
+                        continue;
 
-                    if (!data.Success) continue;
                     string nistKey = data.Groups[1].Value;
                     string nistValue = data.Groups[2].Value;
                     switch (nistKey)
                     {
                         case "Curve":
                             // Change curve name from LNNN to L-NNN ie: P256 to P-256
-                            curve = $"{nistValue.Substring(0, 1)}-{nistValue.Substring(1)}";
+                            curve = nistValue.Insert(1, "-");
                             break;
                         case "k":
                             k = new BigInteger(nistValue, 10);
                             break;
                         case "x":
-                            x = new BigInteger(nistValue, radix: 16);
+                            x = new BigInteger(nistValue, 16);
                             break;
                         case "y":
-                            y = new BigInteger(nistValue, radix: 16);
+                            y = new BigInteger(nistValue, 16);
                             break;
                     }
 
diff --git a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
index 19749278c..3ac28b99f 100644
--- a/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
+++ b/crypto/test/src/pkcs/test/PKCS12StoreTest.cs
@@ -1334,8 +1334,8 @@ namespace Org.BouncyCastle.Pkcs.Tests
 		public void TestFunction()
 		{
 			string resultText = Perform().ToString();
-			Console.Out.WriteLine(resultText);
-			Assert.AreEqual(Name + ": Okay", resultText);
+
+            Assert.AreEqual(Name + ": Okay", resultText);
 		}
 	}
 }
diff --git a/crypto/test/src/tsp/test/NewTspTest.cs b/crypto/test/src/tsp/test/NewTspTest.cs
index 74b3222ce..4c9da7edb 100644
--- a/crypto/test/src/tsp/test/NewTspTest.cs
+++ b/crypto/test/src/tsp/test/NewTspTest.cs
@@ -598,7 +598,7 @@ namespace Org.BouncyCastle.Tsp.Tests
 
 				Assert.Fail("response validation failed on invalid nonce.");
 			}
-			catch (TspValidationException e)
+			catch (TspValidationException)
 			{
 				// ignore
 			}
@@ -611,7 +611,7 @@ namespace Org.BouncyCastle.Tsp.Tests
 
 				Assert.Fail("response validation failed on wrong digest.");
 			}
-			catch (TspValidationException e)
+			catch (TspValidationException)
 			{
 				// ignore
 			}
@@ -624,7 +624,7 @@ namespace Org.BouncyCastle.Tsp.Tests
 
 				Assert.Fail("response validation failed on wrong digest.");
 			}
-			catch (TspValidationException e)
+			catch (TspValidationException)
 			{
 				// ignore
 			}
@@ -670,27 +670,20 @@ namespace Org.BouncyCastle.Tsp.Tests
 			}
 
 
-			EssCertID essCertid = new EssCertID(certHash, issuerSerial);
-			EssCertIDv2 essCertidV2 = new EssCertIDv2(certHash256, issuerSerial);
+			EssCertID essCertID = new EssCertID(certHash, issuerSerial);
+			EssCertIDv2 essCertIDv2 = new EssCertIDv2(certHash256, issuerSerial);
 
-			signerInfoGenBuilder.WithSignedAttributeGenerator(new TestAttrGen()
-			{
-				EssCertID = essCertid,
-				EssCertIDv2 = essCertidV2
-			});
+            signerInfoGenBuilder.WithSignedAttributeGenerator(new TestAttrGen(essCertID, essCertIDv2));
 
 
 			Asn1SignatureFactory sigfact = new Asn1SignatureFactory("SHA1WithRSA", privateKey);
-			SignerInfoGenerator
-				 signerInfoGenerator = signerInfoGenBuilder.Build(sigfact, cert);
+			SignerInfoGenerator signerInfoGenerator = signerInfoGenBuilder.Build(sigfact, cert);
 
-			TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(
-				signerInfoGenerator,
-				Asn1DigestFactory.Get(OiwObjectIdentifiers.IdSha1), new DerObjectIdentifier("1.2"), true);
+            TimeStampTokenGenerator tsTokenGen = new TimeStampTokenGenerator(signerInfoGenerator,
+                Asn1DigestFactory.Get(OiwObjectIdentifiers.IdSha1), new DerObjectIdentifier("1.2"), true);
 
+            tsTokenGen.SetCertificates(certs);
 
-			tsTokenGen.SetCertificates(certs);
-		
 
 			TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
 			TimeStampRequest request = reqGen.Generate(TspAlgorithms.Sha1, new byte[20], BigInteger.ValueOf(100));
@@ -904,28 +897,37 @@ namespace Org.BouncyCastle.Tsp.Tests
 				.Build(sigfact, cert);
 		}
 
-
-
-
-		private class TestAttrGen : CmsAttributeTableGenerator
+        private class TestAttrGen : CmsAttributeTableGenerator
 		{
+            private readonly EssCertID mEssCertID;
+            private readonly EssCertIDv2 mEssCertIDv2;
 
-			public EssCertID EssCertID { get; set; }
+            public TestAttrGen(EssCertID essCertID, EssCertIDv2 essCertIDv2)
+            {
+                this.mEssCertID = essCertID;
+                this.mEssCertIDv2 = essCertIDv2;
+            }
+
+			public EssCertID EssCertID
+            {
+                get { return mEssCertID; }
+            }
 
-			public EssCertIDv2 EssCertIDv2 { get; set; }
+            public EssCertIDv2 EssCertIDv2
+            {
+                get { return mEssCertIDv2; }
+            }
 
-			public Asn1.Cms.AttributeTable GetAttributes(IDictionary parameters)
+            public Asn1.Cms.AttributeTable GetAttributes(IDictionary parameters)
 			{
 				CmsAttributeTableGenerator attrGen = new DefaultSignedAttributeTableGenerator();
 
-				Asn1.Cms.AttributeTable table = attrGen.GetAttributes(parameters);
+                Asn1.Cms.AttributeTable table = attrGen.GetAttributes(parameters);
 				table = table.Add(PkcsObjectIdentifiers.IdAASigningCertificate, new SigningCertificate(EssCertID));
 				table = table.Add(PkcsObjectIdentifiers.IdAASigningCertificateV2, new SigningCertificateV2(new EssCertIDv2[] { EssCertIDv2 }));
 
-				return table;
+                return table;
 			}
 		}
-
 	}
-
 }