2003-11-06 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography / Oid.cs
1 //
2 // Oid.cs - System.Security.Cryptography.Oid
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 #if NET_1_2
11
12 using System;
13
14 namespace System.Security.Cryptography {
15
16         // Note: Match the definition of framework version 1.2.3400.0 on http://longhorn.msdn.microsoft.com
17
18         public sealed class Oid {
19
20                 private string _value;
21                 private string _name;
22
23                 // constructors
24
25                 public Oid () {}
26
27                 public Oid (string oid) 
28                 {
29                         if (oid == null)
30                                 throw new ArgumentNullException ("oid");
31
32                         _value = oid;
33                         _name = GetName (oid);
34                 }
35
36                 public Oid (string value, string friendlyName)
37                 {
38                         _value = value;
39                         _name = friendlyName;
40                 }
41
42                 public Oid (Oid oid) 
43                 {
44 // FIXME: compatibility with fx 1.2.3400.0
45 //                      if (oid == null)
46 //                              throw new ArgumentNullException ("oid");
47
48                         _value = oid.Value;
49                         _name = oid.FriendlyName;
50                 }
51
52                 // properties
53
54                 public string FriendlyName {
55                         get { return _name; }
56                         set { 
57                                 if (value == null)
58                                         throw new ArgumentNullException ("value");
59
60                                 _name = value;
61                                 _value = GetValue (_name);
62                         }
63                 }
64
65                 public string Value { 
66                         get { return _value; }
67                         set { 
68                                 if (value == null)
69                                         throw new ArgumentNullException ("value");
70
71                                 _value = value; 
72                                 _name = GetName (_value);
73                         }
74                 }
75
76                 // private methods
77
78                 // TODO - find the complete list
79                 private string GetName (string value) 
80                 {
81                         switch (value) {
82                                 case "1.2.840.113549.1.1.1":
83                                         return "RSA";
84                                 default:
85                                         return _name;
86                         }
87                 }
88
89                 // TODO - find the complete list
90                 private string GetValue (string name) 
91                 {
92                         switch (name) {
93                                 case "RSA":
94                                         return "1.2.840.113549.1.1.1";
95                                 default:
96                                         return _value;
97                         }
98                 }
99         }
100 }
101
102 #endif