2006-01-04 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Wed, 4 Jan 2006 18:55:10 +0000 (18:55 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Wed, 4 Jan 2006 18:55:10 +0000 (18:55 -0000)
* X509Extension.cs: Added setter for Critical property (fix #77154).
Fixed asymmetry between encoding and decoding (fix #75781).

svn path=/trunk/mcs/; revision=55062

mcs/class/Mono.Security/Mono.Security.X509/ChangeLog
mcs/class/Mono.Security/Mono.Security.X509/X509Extension.cs

index 6e29fd155d5557bfe4eda7080045bda08ace3939..d557d45dcd5cbd34a2fc68bc545b8e27cee3bab3 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-04  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * X509Extension.cs: Added setter for Critical property (fix #77154).
+       Fixed asymmetry between encoding and decoding (fix #75781).
+
 2005-12-16  Sebastien Pouliot  <sebastien@ximian.com> 
 
        * X509Chain.cs: Fix chain building. Patch from Vincent Cote-Roy.
index e929fe9acc255a150e87cfe543363d186304d350..697a55e79c9af71f7fc233eee94e59b9e778ad96 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -60,31 +60,35 @@ namespace Mono.Security.X509 {
                public X509Extension (ASN1 asn1) 
                {
                        if ((asn1.Tag != 0x30) || (asn1.Count < 2))
-                               throw new ArgumentException ("Invalid X.509 extension");
+                               throw new ArgumentException (Locale.GetText ("Invalid X.509 extension."));
                        if (asn1[0].Tag != 0x06)
-                               throw new ArgumentException ("Invalid X.509 extension");
-                       extnOid = ASN1Convert.ToOid (asn1 [0]);
+                               throw new ArgumentException (Locale.GetText ("Invalid X.509 extension."));
+
+                       extnOid = ASN1Convert.ToOid (asn1[0]);
                        extnCritical = ((asn1[1].Tag == 0x01) && (asn1[1].Value[0] == 0xFF));
                        extnValue = asn1 [asn1.Count - 1]; // last element
                        Decode ();
                }
 
-               public X509Extension (X509Extension extension) : this () 
+               public X509Extension (X509Extension extension)
                {
                        if (extension == null)
                                throw new ArgumentNullException ("extension");
-                       if ((extension.Value.Tag != 0x04) || (extension.Value.Count != 0))
-                               throw new ArgumentException ("Invalid extension");
+                       if ((extension.Value == null) || (extension.Value.Tag != 0x04) || (extension.Value.Count != 1))
+                               throw new ArgumentException (Locale.GetText ("Invalid X.509 extension."));
+
                        extnOid = extension.Oid;
                        extnCritical = extension.Critical;
                        extnValue = extension.Value;
                        Decode ();
                }
 
+               // encode the extension *into* an OCTET STRING
                protected virtual void Decode () 
                {
                }
 
+               // decode the extension from *inside* an OCTET STRING
                protected virtual void Encode ()
                {
                }
@@ -94,10 +98,9 @@ namespace Mono.Security.X509 {
                                ASN1 extension = new ASN1 (0x30);
                                extension.Add (ASN1Convert.FromOid (extnOid));
                                if (extnCritical)
-                                       extension.Add (new ASN1 (0x01, new byte [1] { 0x01 }));
-                               ASN1 os = extension.Add (new ASN1 (0x04));
+                                       extension.Add (new ASN1 (0x01, new byte [1] { 0xFF }));
                                Encode ();
-                               os.Add (extnValue);
+                               extension.Add (extnValue);
                                return extension;
                        }
                }
@@ -108,6 +111,7 @@ namespace Mono.Security.X509 {
 
                public bool Critical {
                        get { return extnCritical; }
+                       set { extnCritical = value; }
                }
 
                // this gets overrided with more meaningful names
@@ -116,7 +120,12 @@ namespace Mono.Security.X509 {
                }
 
                public ASN1 Value {
-                       get { return extnValue; }
+                       get {
+                               if (extnValue == null) {
+                                       Encode ();
+                               }
+                               return extnValue;
+                       }
                }
 
                public override bool Equals (object obj)