summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataParser.cs26
-rw-r--r--crypto/src/cms/CMSEnvelopedDataParser.cs22
-rw-r--r--crypto/src/cms/CMSUtils.cs21
3 files changed, 23 insertions, 46 deletions
diff --git a/crypto/src/cms/CMSAuthenticatedDataParser.cs b/crypto/src/cms/CMSAuthenticatedDataParser.cs
index bfd613229..a8f9c480c 100644
--- a/crypto/src/cms/CMSAuthenticatedDataParser.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataParser.cs
@@ -161,17 +161,7 @@ namespace Org.BouncyCastle.Cms
 
 				if (s != null)
 				{
-					Asn1EncodableVector v = new Asn1EncodableVector();
-
-					IAsn1Convertible o;
-					while ((o = s.ReadObject()) != null)
-					{
-						Asn1SequenceParser seq = (Asn1SequenceParser)o;
-
-						v.Add(seq.ToAsn1Object());
-					}
-
-					authAttrs = new Asn1.Cms.AttributeTable(new DerSet(v));
+                    authAttrs = CmsUtilities.ParseAttributeTable(s);
 				}
 			}
 
@@ -193,21 +183,11 @@ namespace Org.BouncyCastle.Cms
 
 				if (s != null)
 				{
-					Asn1EncodableVector v = new Asn1EncodableVector();
-
-					IAsn1Convertible o;
-					while ((o = s.ReadObject()) != null)
-					{
-						Asn1SequenceParser seq = (Asn1SequenceParser)o;
-
-						v.Add(seq.ToAsn1Object());
-					}
-
-					unauthAttrs = new Asn1.Cms.AttributeTable(new DerSet(v));
+					unauthAttrs = CmsUtilities.ParseAttributeTable(s);
 				}
 			}
 
 			return unauthAttrs;
 		}
-	}
+    }
 }
diff --git a/crypto/src/cms/CMSEnvelopedDataParser.cs b/crypto/src/cms/CMSEnvelopedDataParser.cs
index d273ea648..e198ed822 100644
--- a/crypto/src/cms/CMSEnvelopedDataParser.cs
+++ b/crypto/src/cms/CMSEnvelopedDataParser.cs
@@ -106,15 +106,7 @@ namespace Org.BouncyCastle.Cms
 		 * return the ASN.1 encoded encryption algorithm parameters, or null if
 		 * there aren't any.
 		 */
-		public Asn1Object EncryptionAlgParams
-		{
-			get
-			{
-				Asn1Encodable ae = _encAlg.Parameters;
-
-				return ae == null ? null : ae.ToAsn1Object();
-			}
-		}
+		public Asn1Object EncryptionAlgParams => _encAlg.Parameters?.ToAsn1Object();
 
 		/**
 		 * return a store of the intended recipients for this message
@@ -139,17 +131,7 @@ namespace Org.BouncyCastle.Cms
 
 				if (asn1Set != null)
 				{
-					Asn1EncodableVector v = new Asn1EncodableVector();
-					IAsn1Convertible o;
-
-					while ((o = asn1Set.ReadObject()) != null)
-					{
-						Asn1SequenceParser seq = (Asn1SequenceParser)o;
-
-						v.Add(seq.ToAsn1Object());
-					}
-
-					_unprotectedAttributes = new Asn1.Cms.AttributeTable(new DerSet(v));
+                    _unprotectedAttributes = CmsUtilities.ParseAttributeTable(asn1Set);
 				}
 			}
 
diff --git a/crypto/src/cms/CMSUtils.cs b/crypto/src/cms/CMSUtils.cs
index aa25870e6..281e1e73a 100644
--- a/crypto/src/cms/CMSUtils.cs
+++ b/crypto/src/cms/CMSUtils.cs
@@ -12,7 +12,7 @@ using Org.BouncyCastle.X509;
 
 namespace Org.BouncyCastle.Cms
 {
-    internal class CmsUtilities
+	internal static class CmsUtilities
     {
 		// TODO Is there a .NET equivalent to this?
 //		private static readonly Runtime RUNTIME = Runtime.getRuntime();
@@ -161,7 +161,7 @@ namespace Org.BouncyCastle.Cms
 				v.Add(element);
 			}
 
-			return new BerSet(v);
+			return BerSet.FromVector(v);
 		}
 
 		internal static Asn1Set CreateDerSetFromList(IEnumerable<Asn1Encodable> elements)
@@ -173,7 +173,7 @@ namespace Org.BouncyCastle.Cms
 				v.Add(element);
 			}
 
-			return new DerSet(v);
+            return DerSet.FromVector(v);
 		}
 
 		internal static TbsCertificateStructure GetTbsCertificateStructure(X509Certificate cert)
@@ -187,6 +187,21 @@ namespace Org.BouncyCastle.Cms
 			return new IssuerAndSerialNumber(tbsCert.Issuer, tbsCert.SerialNumber.Value);
 		}
 
+        internal static Asn1.Cms.AttributeTable ParseAttributeTable(Asn1SetParser parser)
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector();
+
+            IAsn1Convertible o;
+            while ((o = parser.ReadObject()) != null)
+            {
+                Asn1SequenceParser seq = (Asn1SequenceParser)o;
+
+                v.Add(seq.ToAsn1Object());
+            }
+
+            return new Asn1.Cms.AttributeTable(new DerSet(v));
+        }
+
         internal static void ValidateOtherRevocationInfo(OtherRevocationInfoFormat otherRevocationInfo)
         {
             if (CmsObjectIdentifiers.id_ri_ocsp_response.Equals(otherRevocationInfo.InfoFormat))