Merge pull request #2387 from BrzVlad/feature-concurrent-scanfunc
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509 / X520Attributes.cs
index b8feb6a2db60685db93e4e8c48dab4c205b1bdd3..b8506aab791a2a9c52935c15bddb2fa3545bcd64 100644 (file)
@@ -5,9 +5,7 @@
 //     Sebastien Pouliot <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (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
@@ -30,6 +28,7 @@
 //
 
 using System;
+using System.Globalization;
 using System.Text;
 
 using Mono.Security;
@@ -41,6 +40,10 @@ namespace Mono.Security.X509 {
        //      http://www.itu.int/rec/recommendation.asp?type=folders&lang=e&parent=T-REC-X.520 
        // 2.   Internet X.509 Public Key Infrastructure Certificate and CRL Profile
        //      http://www.ietf.org/rfc/rfc3280.txt
+       // 3.   A Summary of the X.500(96) User Schema for use with LDAPv3
+       //      http://www.faqs.org/rfcs/rfc2256.html
+       // 4.   RFC 2247 - Using Domains in LDAP/X.500 Distinguished Names
+       //      http://www.faqs.org/rfcs/rfc2247.html
 
        /* 
         * AttributeTypeAndValue ::= SEQUENCE {
@@ -81,7 +84,13 @@ namespace Mono.Security.X509 {
 
                        public string Value {
                                get { return attrValue; }
-                               set { attrValue = value; }
+                               set { 
+                                       if ((attrValue != null) && (attrValue.Length > upperBound)) {
+                                               string msg = Locale.GetText ("Value length bigger than upperbound ({0}).");
+                                               throw new FormatException (String.Format (msg, upperBound));
+                                       }
+                                       attrValue = value; 
+                               }
                        }
 
                        public ASN1 ASN1 {
@@ -130,11 +139,18 @@ namespace Mono.Security.X509 {
 
                        private byte SelectBestEncoding ()
                        {
-                               char[] notPrintableString = { '@', '_' };
-                               if (attrValue.IndexOfAny (notPrintableString) != -1)
-                                       return 0x1E; // BMPSTRING
-                               else
-                                       return 0x13; // PRINTABLESTRING
+                               foreach (char c in attrValue) {
+                                       switch (c) {
+                                       case '@':
+                                       case '_':
+                                               return 0x1E; // BMPSTRING
+                                       default:
+                                               if (c > 127)
+                                                       return 0x1E; // BMPSTRING
+                                               break;
+                                       }
+                               }
+                               return 0x13; // PRINTABLESTRING
                        }
                }
 
@@ -152,6 +168,16 @@ namespace Mono.Security.X509 {
                        }
                }
 
+               // RFC2256, Section 5.6
+               public class SerialNumber : AttributeTypeAndValue {
+
+                       // max length 64 bytes, Printable String only
+                       public SerialNumber ()
+                               : base ("2.5.4.5", 64, 0x13)
+                       {
+                       }
+               }
+
                public class LocalityName : AttributeTypeAndValue {
 
                        public LocalityName () : base ("2.5.4.7", 128)
@@ -181,13 +207,40 @@ namespace Mono.Security.X509 {
                }
 
                // NOTE: Not part of RFC2253
-               public class EmailAddress : AttributeTypeAndValue 
-               {
+               public class EmailAddress : AttributeTypeAndValue {
+
                        public EmailAddress () : base ("1.2.840.113549.1.9.1", 128, 0x16)
                        {
                        }
                }
 
+               // RFC2247, Section 4
+               public class DomainComponent : AttributeTypeAndValue {
+
+                       // no maximum length defined
+                       public DomainComponent ()
+                               : base ("0.9.2342.19200300.100.1.25", Int32.MaxValue, 0x16)
+                       {
+                       }
+               }
+
+               // RFC1274, Section 9.3.1
+               public class UserId : AttributeTypeAndValue {
+
+                       public UserId ()
+                               : base ("0.9.2342.19200300.100.1.1", 256)
+                       {
+                       }
+               }
+
+               public class Oid : AttributeTypeAndValue {
+
+                       public Oid (string oid)
+                               : base (oid, Int32.MaxValue)
+                       {
+                       }
+               }
+
                /* -- Naming attributes of type X520Title
                 * id-at-title             AttributeType ::= { id-at 12 }
                 * 
@@ -201,7 +254,9 @@ namespace Mono.Security.X509 {
                 */
                public class Title : AttributeTypeAndValue {
 
-                       public Title () : base ("2.5.4.12", 64) {}
+                       public Title () : base ("2.5.4.12", 64)
+                       {
+                       }
                }
 
                public class CountryName : AttributeTypeAndValue {
@@ -211,6 +266,36 @@ namespace Mono.Security.X509 {
                        {
                        }
                }
+
+               public class DnQualifier : AttributeTypeAndValue {
+
+                       // (0x13) PRINTABLESTRING
+                       public DnQualifier () : base ("2.5.4.46", 2, 0x13) 
+                       {
+                       }
+               }
+
+               public class Surname : AttributeTypeAndValue {
+
+                       public Surname () : base ("2.5.4.4", 32768) 
+                       {
+                       }
+               }
+
+               public class GivenName : AttributeTypeAndValue {
+
+                       public GivenName () : base ("2.5.4.42", 16) 
+                       {
+                       }
+               }
+
+               public class Initial : AttributeTypeAndValue {
+
+                       public Initial () : base ("2.5.4.43", 5) 
+                       {
+                       }
+               }
+
        }
         
        /* From RFC3280