2 // X509ChainElement.cs - System.Security.Cryptography.X509Certificates.X509ChainElement
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005-2006 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.
32 namespace System.Security.Cryptography.X509Certificates {
34 public class X509ChainElement {
36 private X509Certificate2 certificate;
37 private X509ChainStatus[] status;
39 private X509ChainStatusFlags compressed_status_flags;
43 // only accessible from X509Chain.ChainElements
44 internal X509ChainElement (X509Certificate2 certificate)
46 this.certificate = certificate;
47 // so far String.Empty is the only thing I've seen.
48 // The interesting stuff is inside X509ChainStatus.Information
54 public X509Certificate2 Certificate {
55 get { return certificate; }
58 public X509ChainStatus[] ChainElementStatus {
59 get { return status; }
62 public string Information {
68 internal X509ChainStatusFlags StatusFlags {
69 get { return compressed_status_flags; }
70 set { compressed_status_flags = value; }
73 private int Count (X509ChainStatusFlags flags)
87 private void Set (X509ChainStatus[] status, ref int position, X509ChainStatusFlags flags, X509ChainStatusFlags mask)
89 if ((flags & mask) != 0) {
90 status [position].Status = mask;
91 status [position].StatusInformation = X509ChainStatus.GetInformation (mask);
96 internal void UncompressFlags ()
98 if (compressed_status_flags == X509ChainStatusFlags.NoError) {
99 status = new X509ChainStatus [0];
101 int size = Count (compressed_status_flags);
102 status = new X509ChainStatus [size];
105 // process every possible error
106 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.UntrustedRoot);
107 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotTimeValid);
108 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotTimeNested);
109 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.Revoked);
110 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotSignatureValid);
111 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotValidForUsage);
112 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.RevocationStatusUnknown);
113 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.Cyclic);
114 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidExtension);
115 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidPolicyConstraints);
116 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidBasicConstraints);
117 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidNameConstraints);
118 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotSupportedNameConstraint);
119 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotDefinedNameConstraint);
120 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotPermittedNameConstraint);
121 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasExcludedNameConstraint);
122 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.PartialChain);
123 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotTimeValid);
124 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotSignatureValid);
125 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotValidForUsage);
126 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.OfflineRevocation);
127 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NoIssuanceChainPolicy);