summary refs log tree commit diff
path: root/crypto/src/asn1/crmf
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-06-24 20:04:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-06-24 20:04:26 +0700
commit438dc8d53aac9b7483a2014cd4398b8275c496ab (patch)
treed4e53f01313d43c20cf32ae5c930e0d54a364114 /crypto/src/asn1/crmf
parentAdd TODO (diff)
downloadBouncyCastle.NET-ed25519-438dc8d53aac9b7483a2014cd4398b8275c496ab.tar.xz
ASN.1: Use GetTagged with cursor methods
- Add GetTagged method for all CHOICE types
- Make most Asn1Utilities methods public
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/crmf/CertId.cs9
-rw-r--r--crypto/src/asn1/crmf/CertTemplate.cs20
-rw-r--r--crypto/src/asn1/crmf/EncryptedKey.cs9
-rw-r--r--crypto/src/asn1/crmf/OptionalValidity.cs13
-rw-r--r--crypto/src/asn1/crmf/PKIArchiveOptions.cs9
-rw-r--r--crypto/src/asn1/crmf/PKIPublicationInfo.cs9
-rw-r--r--crypto/src/asn1/crmf/PopoPrivKey.cs9
-rw-r--r--crypto/src/asn1/crmf/PopoSigningKey.cs2
-rw-r--r--crypto/src/asn1/crmf/PopoSigningKeyInput.cs9
-rw-r--r--crypto/src/asn1/crmf/ProofOfPossession.cs9
10 files changed, 53 insertions, 45 deletions
diff --git a/crypto/src/asn1/crmf/CertId.cs b/crypto/src/asn1/crmf/CertId.cs
index c9f66b065..a1eabea11 100644
--- a/crypto/src/asn1/crmf/CertId.cs
+++ b/crypto/src/asn1/crmf/CertId.cs
@@ -16,10 +16,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return new CertId(Asn1Sequence.GetInstance(obj));
         }
 
-        public static CertId GetInstance(Asn1TaggedObject obj, bool isExplicit)
-        {
-            return new CertId(Asn1Sequence.GetInstance(obj, isExplicit));
-        }
+        public static CertId GetInstance(Asn1TaggedObject obj, bool isExplicit) =>
+            new CertId(Asn1Sequence.GetInstance(obj, isExplicit));
+
+        public static CertId GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new CertId(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
         private readonly GeneralName m_issuer;
         private readonly DerInteger m_serialNumber;
diff --git a/crypto/src/asn1/crmf/CertTemplate.cs b/crypto/src/asn1/crmf/CertTemplate.cs
index 62227808c..6ae529e9b 100644
--- a/crypto/src/asn1/crmf/CertTemplate.cs
+++ b/crypto/src/asn1/crmf/CertTemplate.cs
@@ -42,16 +42,16 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
             int pos = 0;
 
-            m_version = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, DerInteger.GetInstance);
-            m_serialNumber = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, false, DerInteger.GetInstance);
-            m_signingAlg = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 2, false, AlgorithmIdentifier.GetInstance);
-            m_issuer = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 3, true, X509Name.GetInstance); // CHOICE Name
-            m_validity = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 4, false, OptionalValidity.GetInstance);
-            m_subject = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 5, true, X509Name.GetInstance); // CHOICE Name
-            m_publicKey = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 6, false, SubjectPublicKeyInfo.GetInstance);
-            m_issuerUID = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 7, false, DerBitString.GetInstance);
-            m_subjectUID = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 8, false, DerBitString.GetInstance);
-            m_extensions = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 9, false, X509Extensions.GetInstance);
+            m_version = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, DerInteger.GetTagged);
+            m_serialNumber = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, false, DerInteger.GetTagged);
+            m_signingAlg = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 2, false, AlgorithmIdentifier.GetTagged);
+            m_issuer = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 3, true, X509Name.GetTagged); // CHOICE Name
+            m_validity = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 4, false, OptionalValidity.GetTagged);
+            m_subject = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 5, true, X509Name.GetTagged); // CHOICE Name
+            m_publicKey = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 6, false, SubjectPublicKeyInfo.GetTagged);
+            m_issuerUID = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 7, false, DerBitString.GetTagged);
+            m_subjectUID = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 8, false, DerBitString.GetTagged);
+            m_extensions = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 9, false, X509Extensions.GetTagged);
 
             if (pos != count)
                 throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
diff --git a/crypto/src/asn1/crmf/EncryptedKey.cs b/crypto/src/asn1/crmf/EncryptedKey.cs
index 62c475f5d..6eae55da4 100644
--- a/crypto/src/asn1/crmf/EncryptedKey.cs
+++ b/crypto/src/asn1/crmf/EncryptedKey.cs
@@ -16,10 +16,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return new EncryptedKey(EncryptedValue.GetInstance(obj));
         }
 
-        public static EncryptedKey GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
-        }
+        public static EncryptedKey GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
+
+        public static EncryptedKey GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
 
         private readonly EnvelopedData m_envelopedData;
         private readonly EncryptedValue m_encryptedValue;
diff --git a/crypto/src/asn1/crmf/OptionalValidity.cs b/crypto/src/asn1/crmf/OptionalValidity.cs
index 290d1905e..9abeaca87 100644
--- a/crypto/src/asn1/crmf/OptionalValidity.cs
+++ b/crypto/src/asn1/crmf/OptionalValidity.cs
@@ -16,10 +16,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return new OptionalValidity(Asn1Sequence.GetInstance(obj));
         }
 
-        public static OptionalValidity GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return new OptionalValidity(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
-        }
+        public static OptionalValidity GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new OptionalValidity(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+
+        public static OptionalValidity GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new OptionalValidity(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
         private readonly Time m_notBefore;
         private readonly Time m_notAfter;
@@ -34,8 +35,8 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
             int pos = 0;
 
-            m_notBefore = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, true, Time.GetInstance);
-            m_notAfter = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, true, Time.GetInstance);
+            m_notBefore = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, true, Time.GetTagged);
+            m_notAfter = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, true, Time.GetTagged);
 
             if (pos != count)
                 throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
diff --git a/crypto/src/asn1/crmf/PKIArchiveOptions.cs b/crypto/src/asn1/crmf/PKIArchiveOptions.cs
index a702d6dc2..37e9af83e 100644
--- a/crypto/src/asn1/crmf/PKIArchiveOptions.cs
+++ b/crypto/src/asn1/crmf/PKIArchiveOptions.cs
@@ -26,10 +26,8 @@ namespace Org.BouncyCastle.Asn1.Crmf
             throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj));
         }
 
-        public static PkiArchiveOptions GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
-        }
+        public static PkiArchiveOptions GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
 
         public static PkiArchiveOptions GetOptional(Asn1Encodable element)
         {
@@ -49,6 +47,9 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return null;
         }
 
+        public static PkiArchiveOptions GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
+
         private static Asn1Encodable GetOptionalBaseObject(Asn1TaggedObject taggedObject)
         {
             if (taggedObject.HasContextTag())
diff --git a/crypto/src/asn1/crmf/PKIPublicationInfo.cs b/crypto/src/asn1/crmf/PKIPublicationInfo.cs
index 3c12dffa5..01a258b98 100644
--- a/crypto/src/asn1/crmf/PKIPublicationInfo.cs
+++ b/crypto/src/asn1/crmf/PKIPublicationInfo.cs
@@ -31,10 +31,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return new PkiPublicationInfo(Asn1Sequence.GetInstance(obj));
         }
 
-        public static PkiPublicationInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return new PkiPublicationInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
-        }
+        public static PkiPublicationInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new PkiPublicationInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+
+        public static PkiPublicationInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new PkiPublicationInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
         private readonly DerInteger m_action;
         private readonly Asn1Sequence m_pubInfos;
diff --git a/crypto/src/asn1/crmf/PopoPrivKey.cs b/crypto/src/asn1/crmf/PopoPrivKey.cs
index 91b1ddba4..33ee8744f 100644
--- a/crypto/src/asn1/crmf/PopoPrivKey.cs
+++ b/crypto/src/asn1/crmf/PopoPrivKey.cs
@@ -29,10 +29,8 @@ namespace Org.BouncyCastle.Asn1.Crmf
             throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj));
         }
 
-        public static PopoPrivKey GetInstance(Asn1TaggedObject tagged, bool isExplicit)
-        {
-            return Asn1Utilities.GetInstanceFromChoice(tagged, isExplicit, GetInstance);
-        }
+        public static PopoPrivKey GetInstance(Asn1TaggedObject tagged, bool isExplicit) =>
+            Asn1Utilities.GetInstanceChoice(tagged, isExplicit, GetInstance);
 
         public static PopoPrivKey GetOptional(Asn1Encodable element)
         {
@@ -52,6 +50,9 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return null;
         }
 
+        public static PopoPrivKey GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
+
         private static Asn1Encodable GetOptionalBaseObject(Asn1TaggedObject taggedObject)
         {
             if (taggedObject.HasContextTag())
diff --git a/crypto/src/asn1/crmf/PopoSigningKey.cs b/crypto/src/asn1/crmf/PopoSigningKey.cs
index 00138ddb3..a0b6cad35 100644
--- a/crypto/src/asn1/crmf/PopoSigningKey.cs
+++ b/crypto/src/asn1/crmf/PopoSigningKey.cs
@@ -33,7 +33,7 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
             int pos = 0;
 
-            m_poposkInput = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, PopoSigningKeyInput.GetInstance);
+            m_poposkInput = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, PopoSigningKeyInput.GetTagged);
             m_algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[pos++]);
             m_signature = DerBitString.GetInstance(seq[pos++]);
 
diff --git a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
index c62159051..189cb9681 100644
--- a/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
+++ b/crypto/src/asn1/crmf/PopoSigningKeyInput.cs
@@ -16,10 +16,11 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return new PopoSigningKeyInput(Asn1Sequence.GetInstance(obj));
         }
 
-        public static PopoSigningKeyInput GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return new PopoSigningKeyInput(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
-        }
+        public static PopoSigningKeyInput GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new PopoSigningKeyInput(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+
+        public static PopoSigningKeyInput GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new PopoSigningKeyInput(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
         private readonly GeneralName m_sender;
         private readonly PKMacValue m_publicKeyMac;
diff --git a/crypto/src/asn1/crmf/ProofOfPossession.cs b/crypto/src/asn1/crmf/ProofOfPossession.cs
index d7d9fe7b1..0b0ce1c3a 100644
--- a/crypto/src/asn1/crmf/ProofOfPossession.cs
+++ b/crypto/src/asn1/crmf/ProofOfPossession.cs
@@ -28,10 +28,8 @@ namespace Org.BouncyCastle.Asn1.Crmf
             throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj));
         }
 
-        public static ProofOfPossession GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
-        }
+        public static ProofOfPossession GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
 
         public static ProofOfPossession GetOptional(Asn1Encodable element)
         {
@@ -51,6 +49,9 @@ namespace Org.BouncyCastle.Asn1.Crmf
             return null;
         }
 
+        public static ProofOfPossession GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
+
         private static Asn1Encodable GetOptionalBaseObject(Asn1TaggedObject taggedObject)
         {
             if (taggedObject.HasContextTag())