summary refs log tree commit diff
path: root/crypto/src/asn1/x509/UserNotice.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-21 19:09:31 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-21 19:09:31 +0700
commit79f344b578c17dd919eafbefff8bf76269c8551a (patch)
treef22e217b58bab742f86949e7e43918329e85c0c1 /crypto/src/asn1/x509/UserNotice.cs
parentFix Equals methods (diff)
downloadBouncyCastle.NET-ed25519-79f344b578c17dd919eafbefff8bf76269c8551a.tar.xz
BMA-116
Update some Asn1.X509 classes from Java
Diffstat (limited to 'crypto/src/asn1/x509/UserNotice.cs')
-rw-r--r--crypto/src/asn1/x509/UserNotice.cs102
1 files changed, 60 insertions, 42 deletions
diff --git a/crypto/src/asn1/x509/UserNotice.cs b/crypto/src/asn1/x509/UserNotice.cs
index 2878a180f..5938f7c49 100644
--- a/crypto/src/asn1/x509/UserNotice.cs
+++ b/crypto/src/asn1/x509/UserNotice.cs
@@ -19,10 +19,10 @@ namespace Org.BouncyCastle.Asn1.X509
     public class UserNotice
         : Asn1Encodable
     {
-        internal NoticeReference	noticeRef;
-        internal DisplayText		explicitText;
+        private readonly NoticeReference noticeRef;
+        private readonly DisplayText explicitText;
 
-		/**
+        /**
          * Creates a new <code>UserNotice</code> instance.
          *
          * @param noticeRef a <code>NoticeReference</code> value
@@ -36,7 +36,7 @@ namespace Org.BouncyCastle.Asn1.X509
             this.explicitText = explicitText;
         }
 
-		/**
+        /**
          * Creates a new <code>UserNotice</code> instance.
          *
          * @param noticeRef a <code>NoticeReference</code> value
@@ -45,60 +45,78 @@ namespace Org.BouncyCastle.Asn1.X509
         public UserNotice(
             NoticeReference	noticeRef,
             string			str)
+            : this(noticeRef, new DisplayText(str))
         {
-            this.noticeRef = noticeRef;
-            this.explicitText = new DisplayText(str);
         }
 
-		/**
-		 * Creates a new <code>UserNotice</code> instance.
-		 * <p>Useful from reconstructing a <code>UserNotice</code> instance
-		 * from its encodable/encoded form.
-		 *
-		 * @param as an <code>ASN1Sequence</code> value obtained from either
-		 * calling @{link toASN1Object()} for a <code>UserNotice</code>
-		 * instance or from parsing it from a DER-encoded stream.</p>
-		 */
-		public UserNotice(
-			Asn1Sequence seq)
-		{
-			if (seq.Count == 2)
-			{
-				noticeRef = NoticeReference.GetInstance(seq[0]);
-				explicitText = DisplayText.GetInstance(seq[1]);
-			}
-			else if (seq.Count == 1)
-			{
-				if (seq[0].ToAsn1Object() is Asn1Sequence)
-				{
-					noticeRef = NoticeReference.GetInstance(seq[0]);
-				}
-				else
-				{
-					explicitText = DisplayText.GetInstance(seq[0]);
-				}
-			}
-			else
-			{
-				throw new ArgumentException("Bad sequence size: " + seq.Count);
-			}
+        /**
+         * Creates a new <code>UserNotice</code> instance.
+         * <p>Useful from reconstructing a <code>UserNotice</code> instance
+         * from its encodable/encoded form.
+         *
+         * @param as an <code>ASN1Sequence</code> value obtained from either
+         * calling @{link toASN1Object()} for a <code>UserNotice</code>
+         * instance or from parsing it from a DER-encoded stream.</p>
+         */
+        public UserNotice(
+            Asn1Sequence seq)
+        {
+            if (seq.Count == 2)
+            {
+                noticeRef = NoticeReference.GetInstance(seq[0]);
+                explicitText = DisplayText.GetInstance(seq[1]);
+            }
+            else if (seq.Count == 1)
+            {
+                if (seq[0].ToAsn1Object() is Asn1Sequence)
+                {
+                    noticeRef = NoticeReference.GetInstance(seq[0]);
+                }
+                else
+                {
+                    explicitText = DisplayText.GetInstance(seq[0]);
+                }
+            }
+            else
+            {
+                throw new ArgumentException("Bad sequence size: " + seq.Count);
+            }
+        }
+
+        public static UserNotice GetInstance(object obj)
+        {
+            if (obj is UserNotice)
+                return (UserNotice)obj;
+            if (obj == null)
+                return null;
+            return new UserNotice(Asn1Sequence.GetInstance(obj));
+        }
+
+        public virtual NoticeReference NoticeRef
+        {
+            get { return noticeRef; }
+        }
+
+        public virtual DisplayText ExplicitText
+        {
+            get { return explicitText; }
         }
 
-		public override Asn1Object ToAsn1Object()
+        public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector av = new Asn1EncodableVector();
 
-			if (noticeRef != null)
+            if (noticeRef != null)
             {
                 av.Add(noticeRef);
             }
 
-			if (explicitText != null)
+            if (explicitText != null)
             {
                 av.Add(explicitText);
             }
 
-			return new DerSequence(av);
+            return new DerSequence(av);
         }
     }
 }