summary refs log tree commit diff
path: root/crypto/src/asn1/icao/LDSVersionInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/icao/LDSVersionInfo.cs')
-rw-r--r--crypto/src/asn1/icao/LDSVersionInfo.cs76
1 files changed, 43 insertions, 33 deletions
diff --git a/crypto/src/asn1/icao/LDSVersionInfo.cs b/crypto/src/asn1/icao/LDSVersionInfo.cs
index 2cdcad2db..e0a1af5c3 100644
--- a/crypto/src/asn1/icao/LDSVersionInfo.cs
+++ b/crypto/src/asn1/icao/LDSVersionInfo.cs
@@ -2,48 +2,61 @@ using System;
 
 namespace Org.BouncyCastle.Asn1.Icao
 {
-	public class LdsVersionInfo
+    public class LdsVersionInfo
 		: Asn1Encodable
 	{
-		private DerPrintableString ldsVersion;
-		private DerPrintableString unicodeVersion;
+        public static LdsVersionInfo GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is LdsVersionInfo ldsVersionInfo)
+                return ldsVersionInfo;
+            return new LdsVersionInfo(Asn1Sequence.GetInstance(obj));
+        }
 
-		public LdsVersionInfo(string ldsVersion, string unicodeVersion)
-		{
-			this.ldsVersion = new DerPrintableString(ldsVersion);
-			this.unicodeVersion = new DerPrintableString(unicodeVersion);
-		}
+        public static LdsVersionInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return new LdsVersionInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
 
-		private LdsVersionInfo(Asn1Sequence seq)
-		{
-			if (seq.Count != 2)
-				throw new ArgumentException("sequence wrong size for LDSVersionInfo", "seq");
+        public static LdsVersionInfo GetOptional(Asn1Encodable element)
+        {
+            if (element == null)
+                throw new ArgumentNullException(nameof(element));
 
-			this.ldsVersion = DerPrintableString.GetInstance(seq[0]);
-			this.unicodeVersion = DerPrintableString.GetInstance(seq[1]);
-		}
+            if (element is LdsVersionInfo ldsVersionInfo)
+                return ldsVersionInfo;
 
-		public static LdsVersionInfo GetInstance(object obj)
-		{
-			if (obj is LdsVersionInfo)
-				return (LdsVersionInfo)obj;
+            Asn1Sequence asn1Sequence = Asn1Sequence.GetOptional(element);
+            if (asn1Sequence != null)
+                return new LdsVersionInfo(asn1Sequence);
 
-			if (obj != null)
-				return new LdsVersionInfo(Asn1Sequence.GetInstance(obj));
+            return null;
+        }
 
-			return null;
-		}
+        private DerPrintableString m_ldsVersion;
+        private DerPrintableString m_unicodeVersion;
 
-		public virtual string GetLdsVersion()
+        private LdsVersionInfo(Asn1Sequence seq)
 		{
-			return ldsVersion.GetString();
-		}
+            int count = seq.Count;
+            if (count != 2)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
 
-		public virtual string GetUnicodeVersion()
-		{
-			return unicodeVersion.GetString();
+			m_ldsVersion = DerPrintableString.GetInstance(seq[0]);
+			m_unicodeVersion = DerPrintableString.GetInstance(seq[1]);
 		}
 
+        public LdsVersionInfo(string ldsVersion, string unicodeVersion)
+        {
+            m_ldsVersion = new DerPrintableString(ldsVersion);
+            m_unicodeVersion = new DerPrintableString(unicodeVersion);
+        }
+
+		public virtual string GetLdsVersion() => m_ldsVersion.GetString();
+
+		public virtual string GetUnicodeVersion() => m_unicodeVersion.GetString();
+
 		/**
 		 * <pre>
 		 * LDSVersionInfo ::= SEQUENCE {
@@ -53,9 +66,6 @@ namespace Org.BouncyCastle.Asn1.Icao
 		 * </pre>
 		 * @return
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return new DerSequence(ldsVersion, unicodeVersion);
-		}
+		public override Asn1Object ToAsn1Object() => new DerSequence(m_ldsVersion, m_unicodeVersion);
 	}
 }