(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / ExtendedKeyUsageExtension.cs
blob10330d0b8debe3b461b54d730d4c04637f193c94
1 //
2 // ExtendedKeyUsageExtension.cs: Handles X.509 ExtendedKeyUsage extensions.
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // (C) 2004 Novell (http://www.novell.com)
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Collections;
34 using System.Text;
36 using Mono.Security;
37 using Mono.Security.X509;
39 namespace Mono.Security.X509.Extensions {
42 * id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 }
44 * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
46 * KeyPurposeId ::= OBJECT IDENTIFIER
49 public class ExtendedKeyUsageExtension : X509Extension {
51 private ArrayList keyPurpose;
53 public ExtendedKeyUsageExtension () : base ()
55 extnOid = "2.5.29.37";
56 keyPurpose = new ArrayList ();
59 public ExtendedKeyUsageExtension (ASN1 asn1) : base (asn1)
63 public ExtendedKeyUsageExtension (X509Extension extension) : base (extension)
67 protected override void Decode ()
69 keyPurpose = new ArrayList ();
70 ASN1 sequence = new ASN1 (extnValue.Value);
71 if (sequence.Tag != 0x30)
72 throw new ArgumentException ("Invalid ExtendedKeyUsage extension");
73 // for every policy OID
74 for (int i=0; i < sequence.Count; i++)
75 keyPurpose.Add (ASN1Convert.ToOid (sequence [i]));
78 protected override void Encode ()
80 if (extnValue == null) {
81 extnValue = new ASN1 (0x30);
82 foreach (string oid in keyPurpose) {
83 extnValue.Add (ASN1Convert.FromOid (oid));
88 public ArrayList KeyPurpose {
89 get { return keyPurpose; }
92 public override string Name {
93 get { return "Extended Key Usage"; }
96 // serverAuth 1.3.6.1.5.5.7.3.1
97 // clientAuth 1.3.6.1.5.5.7.3.2
98 // codeSigning 1.3.6.1.5.5.7.3.3
99 // emailProtection 1.3.6.1.5.5.7.3.4
100 // timeStamping 1.3.6.1.5.5.7.3.8
101 // OCSPSigning 1.3.6.1.5.5.7.3.9
102 public override string ToString ()
104 StringBuilder sb = new StringBuilder ();
105 foreach (string s in keyPurpose) {
106 switch (s) {
107 case "1.3.6.1.5.5.7.3.1":
108 sb.Append ("Server Authentication");
109 break;
110 case "1.3.6.1.5.5.7.3.2":
111 sb.Append ("Client Authentication");
112 break;
113 case "1.3.6.1.5.5.7.3.3":
114 sb.Append ("Code Signing");
115 break;
116 case "1.3.6.1.5.5.7.3.4":
117 sb.Append ("Email Protection");
118 break;
119 case "1.3.6.1.5.5.7.3.8":
120 sb.Append ("Time Stamping");
121 break;
122 case "1.3.6.1.5.5.7.3.9":
123 sb.Append ("OCSP Signing");
124 break;
125 default:
126 sb.Append ("unknown");
127 break;
129 sb.AppendFormat (" ({0}){1}", s, Environment.NewLine);
131 return sb.ToString ();