Merge pull request #2698 from esdrubal/iosxmlarray
[mono.git] / mcs / class / System / System.Security.Cryptography.X509Certificates / X509Chain.cs
1 //
2 // System.Security.Cryptography.X509Certificates.X509Chain
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2006 Novell Inc. (http://www.novell.com)
9 // Copyright (C) 2011 Xamarin Inc. (http://www.xamarin.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if SECURITY_DEP
32
33 #if MONO_SECURITY_ALIAS
34 extern alias MonoSecurity;
35 using MX = MonoSecurity::Mono.Security.X509;
36 #else
37 using MX = Mono.Security.X509;
38 #endif
39
40 using System.Collections;
41 using System.Text;
42
43 namespace System.Security.Cryptography.X509Certificates {
44
45         public class X509Chain : IDisposable {
46
47                 X509ChainImpl impl;
48
49                 static X509ChainStatus[] Empty = new X509ChainStatus [0];
50
51                 internal X509ChainImpl Impl {
52                         get {
53                                 X509Helper2.ThrowIfContextInvalid (impl);
54                                 return impl;
55                         }
56                 }
57
58                 internal bool IsValid {
59                         get { return X509Helper2.IsValid (impl); }
60                 }
61
62                 internal void ThrowIfContextInvalid ()
63                 {
64                         X509Helper2.ThrowIfContextInvalid (impl);
65                 }
66
67                 // constructors
68
69                 public X509Chain ()
70                         : this (false)
71                 {
72                 }
73
74                 public X509Chain (bool useMachineContext) 
75                 {
76                         impl = X509Helper2.CreateChainImpl (useMachineContext);
77                 }
78
79                 internal X509Chain (X509ChainImpl impl)
80                 {
81                         X509Helper2.ThrowIfContextInvalid (impl);
82                         this.impl = impl;
83                 }
84
85                 [MonoTODO ("Mono's X509Chain is fully managed. All handles are invalid.")]
86                 public X509Chain (IntPtr chainContext)
87                 {
88                         // CryptoAPI compatibility (unmanaged handle)
89                         throw new NotSupportedException ();
90                 }
91
92                 // properties
93
94                 [MonoTODO ("Mono's X509Chain is fully managed. Always returns IntPtr.Zero.")]
95                 public IntPtr ChainContext {
96                         get {
97                                 if (impl != null && impl.IsValid)
98                                         return impl.Handle;
99                                 return IntPtr.Zero;
100                         }
101                 }
102
103                 public X509ChainElementCollection ChainElements {
104                         get { return Impl.ChainElements; }
105                 }
106
107                 public X509ChainPolicy ChainPolicy {
108                         get { return Impl.ChainPolicy; }
109                         set { Impl.ChainPolicy = value; }
110                 }
111
112                 public X509ChainStatus[] ChainStatus {
113                         get { return Impl.ChainStatus; }
114                 }
115
116                 // methods
117
118                 [MonoTODO ("Not totally RFC3280 compliant, but neither is MS implementation...")]
119                 public bool Build (X509Certificate2 certificate)
120                 {
121                         return Impl.Build (certificate);
122                 }
123
124                 public void Reset () 
125                 {
126                         Impl.Reset ();
127                 }
128
129                 // static methods
130
131                 public static X509Chain Create ()
132                 {
133 #if FULL_AOT_RUNTIME
134                         return new X509Chain ();
135 #else
136                         return (X509Chain) CryptoConfig.CreateFromName ("X509Chain");
137 #endif
138                 }
139
140                 public void Dispose ()
141                 {
142                         Dispose (true);
143                         GC.SuppressFinalize (this);
144                 }
145
146                 protected virtual void Dispose (bool disposing)
147                 {
148                         if (impl != null) {
149                                 impl.Dispose ();
150                                 impl = null;
151                         }
152                 }
153
154                 ~X509Chain ()
155                 {
156                         Dispose (false);
157                 }
158         }
159 }
160 #else
161 namespace System.Security.Cryptography.X509Certificates {
162         public class X509Chain {
163                 public bool Build (X509Certificate2 cert)
164                 {
165                         return false;
166                 }
167         }
168 }
169 #endif
170