2 // Oid.cs - System.Security.Cryptography.Oid
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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
;
47 public Oid (string oid
)
50 throw new ArgumentNullException ("oid");
53 _name
= GetName (oid
);
56 public Oid (string value, string friendlyName
)
65 throw new ArgumentNullException ("oid");
68 _name
= oid
.FriendlyName
;
73 public string FriendlyName
{
77 _value
= GetValue (_name
);
82 get { return _value; }
85 _name
= GetName (_value
);
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
)
120 return namePkcs7Data
;
121 case oidPkcs9ContentType
:
122 return namePkcs9ContentType
;
123 case oidPkcs9MessageDigest
:
124 return namePkcs9MessageDigest
;
125 case oidPkcs9SigningTime
:
126 return namePkcs9SigningTime
;
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
;
150 // TODO - find the complete list
151 private string GetValue (string name
)
158 case namePkcs9ContentType
:
159 return oidPkcs9ContentType
;
160 case namePkcs9MessageDigest
:
161 return oidPkcs9MessageDigest
;
162 case namePkcs9SigningTime
:
163 return oidPkcs9SigningTime
;
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
;