2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System / System.Security.Cryptography / Oid.cs
blob98a4435d63ae202aeb475aaf1242a2b63fc3f557
1 //
2 // Oid.cs - System.Security.Cryptography.Oid
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #if NET_2_0 && SECURITY_DEP
32 using System.Security.Cryptography.X509Certificates;
34 namespace System.Security.Cryptography {
36 public sealed class Oid {
38 private string _value;
39 private string _name;
41 // constructors
43 public Oid ()
47 public Oid (string oid)
49 if (oid == null)
50 throw new ArgumentNullException ("oid");
52 _value = oid;
53 _name = GetName (oid);
56 public Oid (string value, string friendlyName)
58 _value = value;
59 _name = friendlyName;
62 public Oid (Oid oid)
64 if (oid == null)
65 throw new ArgumentNullException ("oid");
67 _value = oid.Value;
68 _name = oid.FriendlyName;
71 // properties
73 public string FriendlyName {
74 get { return _name; }
75 set {
76 _name = value;
77 _value = GetValue (_name);
81 public string Value {
82 get { return _value; }
83 set {
84 _value = value;
85 _name = GetName (_value);
89 // internal stuff
91 // Known OID/Names not defined anywhere else (by OID order)
92 internal const string oidRSA = "1.2.840.113549.1.1.1";
93 internal const string nameRSA = "RSA";
94 internal const string oidPkcs7Data = "1.2.840.113549.1.7.1";
95 internal const string namePkcs7Data = "PKCS 7 Data";
96 internal const string oidPkcs9ContentType = "1.2.840.113549.1.9.3";
97 internal const string namePkcs9ContentType = "Content Type";
98 internal const string oidPkcs9MessageDigest = "1.2.840.113549.1.9.4";
99 internal const string namePkcs9MessageDigest = "Message Digest";
100 internal const string oidPkcs9SigningTime = "1.2.840.113549.1.9.5";
101 internal const string namePkcs9SigningTime = "Signing Time";
102 internal const string oidMd5 = "1.2.840.113549.2.5";
103 internal const string nameMd5 = "md5";
104 internal const string oid3Des = "1.2.840.113549.3.7";
105 internal const string name3Des = "3des";
106 internal const string oidSha1 = "1.3.14.3.2.26";
107 internal const string nameSha1 = "sha1";
108 internal const string oidSubjectAltName = "2.5.29.17";
109 internal const string nameSubjectAltName = "Subject Alternative Name";
110 internal const string oidNetscapeCertType = "2.16.840.1.113730.1.1";
111 internal const string nameNetscapeCertType = "Netscape Cert Type";
113 // TODO - find the complete list
114 private string GetName (string oid)
116 switch (oid) {
117 case oidRSA:
118 return nameRSA;
119 case oidPkcs7Data:
120 return namePkcs7Data;
121 case oidPkcs9ContentType:
122 return namePkcs9ContentType;
123 case oidPkcs9MessageDigest:
124 return namePkcs9MessageDigest;
125 case oidPkcs9SigningTime:
126 return namePkcs9SigningTime;
127 case oid3Des:
128 return name3Des;
129 case X509BasicConstraintsExtension.oid:
130 return X509BasicConstraintsExtension.friendlyName;
131 case X509KeyUsageExtension.oid:
132 return X509KeyUsageExtension.friendlyName;
133 case X509EnhancedKeyUsageExtension.oid:
134 return X509EnhancedKeyUsageExtension.friendlyName;
135 case X509SubjectKeyIdentifierExtension.oid:
136 return X509SubjectKeyIdentifierExtension.friendlyName;
137 case oidSubjectAltName:
138 return nameSubjectAltName;
139 case oidNetscapeCertType:
140 return nameNetscapeCertType;
141 case oidMd5:
142 return nameMd5;
143 case oidSha1:
144 return nameSha1;
145 default:
146 return _name;
150 // TODO - find the complete list
151 private string GetValue (string name)
153 switch (name) {
154 case nameRSA:
155 return oidRSA;
156 case namePkcs7Data:
157 return oidPkcs7Data;
158 case namePkcs9ContentType:
159 return oidPkcs9ContentType;
160 case namePkcs9MessageDigest:
161 return oidPkcs9MessageDigest;
162 case namePkcs9SigningTime:
163 return oidPkcs9SigningTime;
164 case name3Des:
165 return oid3Des;
166 case X509BasicConstraintsExtension.friendlyName:
167 return X509BasicConstraintsExtension.oid;
168 case X509KeyUsageExtension.friendlyName:
169 return X509KeyUsageExtension.oid;
170 case X509EnhancedKeyUsageExtension.friendlyName:
171 return X509EnhancedKeyUsageExtension.oid;
172 case X509SubjectKeyIdentifierExtension.friendlyName:
173 return X509SubjectKeyIdentifierExtension.oid;
174 case nameSubjectAltName:
175 return oidSubjectAltName;
176 case nameNetscapeCertType:
177 return oidNetscapeCertType;
178 case nameMd5:
179 return oidMd5;
180 case nameSha1:
181 return oidSha1;
182 default:
183 return _value;
189 #endif