summary refs log tree commit diff
path: root/crypto/src/cmp
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-06-28 00:47:21 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-28 00:47:21 +0700
commitbf718b4e64a757a8a5442c935cc862b8f231c103 (patch)
tree7302f2840266b6b38855c7d38b83e473d359de51 /crypto/src/cmp
parentFix NPE (diff)
downloadBouncyCastle.NET-ed25519-bf718b4e64a757a8a5442c935cc862b8f231c103.tar.xz
Generics migration in Bcpg, Bzip2, Cmp
Diffstat (limited to 'crypto/src/cmp')
-rw-r--r--crypto/src/cmp/CertificateConfirmationContentBuilder.cs12
-rw-r--r--crypto/src/cmp/ProtectedPkiMessageBuilder.cs37
2 files changed, 20 insertions, 29 deletions
diff --git a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
index 611fa4449..94f5eda8b 100644
--- a/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
+++ b/crypto/src/cmp/CertificateConfirmationContentBuilder.cs
@@ -1,14 +1,12 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Cms;
-using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.X509;
 
 namespace Org.BouncyCastle.Cmp
@@ -18,8 +16,8 @@ namespace Org.BouncyCastle.Cmp
         private static readonly DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
 
         private readonly DefaultDigestAlgorithmIdentifierFinder digestAlgFinder;
-        private readonly IList acceptedCerts = Platform.CreateArrayList();
-        private readonly IList acceptedReqIds = Platform.CreateArrayList();
+        private readonly IList<X509Certificate> acceptedCerts = new List<X509Certificate>();
+        private readonly IList<BigInteger> acceptedReqIds = new List<BigInteger>();
 
         public CertificateConfirmationContentBuilder()
             : this(new DefaultDigestAlgorithmIdentifierFinder())
@@ -44,8 +42,8 @@ namespace Org.BouncyCastle.Cmp
             Asn1EncodableVector v = new Asn1EncodableVector();
             for (int i = 0; i != acceptedCerts.Count; i++)
             {
-                X509Certificate cert = (X509Certificate)acceptedCerts[i];
-                BigInteger reqId = (BigInteger)acceptedReqIds[i];
+                X509Certificate cert = acceptedCerts[i];
+                BigInteger reqId = acceptedReqIds[i];
 
 
                 AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName);
diff --git a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
index 5939e92df..269910cc6 100644
--- a/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
+++ b/crypto/src/cmp/ProtectedPkiMessageBuilder.cs
@@ -1,12 +1,11 @@
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
-using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.X509;
 
 namespace Org.BouncyCastle.Cmp
@@ -15,8 +14,8 @@ namespace Org.BouncyCastle.Cmp
     {
         private PkiHeaderBuilder hdrBuilBuilder;
         private PkiBody body;
-        private IList generalInfos = Platform.CreateArrayList();
-        private IList extraCerts = Platform.CreateArrayList();
+        private List<InfoTypeAndValue> generalInfos = new List<InfoTypeAndValue>();
+        private List<X509Certificate> extraCerts = new List<X509Certificate>();
 
         public ProtectedPkiMessageBuilder(GeneralName sender, GeneralName recipient)
             : this(PkiHeader.CMP_2000, sender, recipient)
@@ -123,13 +122,7 @@ namespace Org.BouncyCastle.Cmp
             hdrBuilBuilder.SetProtectionAlg(algorithmIdentifier);
             if (generalInfos.Count > 0)
             {
-                InfoTypeAndValue[] genInfos = new InfoTypeAndValue[generalInfos.Count];
-                for (int t = 0; t < genInfos.Length; t++)
-                {
-                    genInfos[t] = (InfoTypeAndValue)generalInfos[t];
-                }
-
-                hdrBuilBuilder.SetGeneralInfo(genInfos);
+                hdrBuilBuilder.SetGeneralInfo(generalInfos.ToArray());
             }
         }
 
@@ -140,8 +133,8 @@ namespace Org.BouncyCastle.Cmp
                 CmpCertificate[] cmpCertificates = new CmpCertificate[extraCerts.Count];
                 for (int i = 0; i < cmpCertificates.Length; i++)
                 {
-                    byte[] cert = ((X509Certificate)extraCerts[i]).GetEncoded();
-                    cmpCertificates[i] = CmpCertificate.GetInstance((Asn1Sequence.FromByteArray(cert)));
+                    byte[] cert = extraCerts[i].GetEncoded();
+                    cmpCertificates[i] = CmpCertificate.GetInstance(Asn1Object.FromByteArray(cert));
                 }
 
                 return new ProtectedPkiMessage(new PkiMessage(header, body, protection, cmpCertificates));
@@ -152,24 +145,24 @@ namespace Org.BouncyCastle.Cmp
 
         private byte[] CalculateSignature(IStreamCalculator signer, PkiHeader header, PkiBody body)
         {
-            Asn1EncodableVector avec = new Asn1EncodableVector();
+            Asn1EncodableVector avec = new Asn1EncodableVector(2);
             avec.Add(header);
             avec.Add(body);
-            byte[] encoded = new DerSequence(avec).GetEncoded();
-            signer.Stream.Write(encoded, 0, encoded.Length);
+
+            new DerSequence(avec).EncodeTo(signer.Stream);
             object result = signer.GetResult();
 
-            if (result is DefaultSignatureResult)
+            if (result is DefaultSignatureResult sigResult)
             {
-                return ((DefaultSignatureResult)result).Collect();
+                return sigResult.Collect();
             }
-            else if (result is IBlockResult)
+            else if (result is IBlockResult blockResult)
             {
-                return ((IBlockResult)result).Collect();
+                return blockResult.Collect();
             }
-            else if (result is byte[])
+            else if (result is byte[] bytesResult)
             {
-                return (byte[])result;
+                return bytesResult;
             }
 
             throw new InvalidOperationException("result is not byte[] or DefaultSignatureResult");