From bf718b4e64a757a8a5442c935cc862b8f231c103 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 28 Jun 2022 00:47:21 +0700 Subject: Generics migration in Bcpg, Bzip2, Cmp --- .../cmp/CertificateConfirmationContentBuilder.cs | 12 +++---- crypto/src/cmp/ProtectedPkiMessageBuilder.cs | 37 +++++++++------------- 2 files changed, 20 insertions(+), 29 deletions(-) (limited to 'crypto/src/cmp') 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 acceptedCerts = new List(); + private readonly IList acceptedReqIds = new List(); 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 generalInfos = new List(); + private List extraCerts = new List(); 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"); -- cgit 1.4.1