Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / security / system / security / cryptography / x509 / X509ChainElement.cs / 1305376 / X509ChainElement.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// X509ChainElement.cs
//
namespace System.Security.Cryptography.X509Certificates {
using System.Collections;
using System.Runtime.InteropServices;
public class X509ChainElement {
private X509Certificate2 m_certificate;
private X509ChainStatus[] m_chainStatus;
private string m_description;
private X509ChainElement () {}
internal unsafe X509ChainElement (IntPtr pChainElement) {
CAPI.CERT_CHAIN_ELEMENT chainElement = new CAPI.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_ELEMENT)));
uint cbSize = (uint) Marshal.ReadInt32(pChainElement);
if (cbSize > Marshal.SizeOf(chainElement))
cbSize = (uint) Marshal.SizeOf(chainElement);
X509Utils.memcpy(pChainElement, new IntPtr(&chainElement), cbSize);
m_certificate = new X509Certificate2(chainElement.pCertContext);
if (chainElement.pwszExtendedErrorInfo == IntPtr.Zero)
m_description = String.Empty;
else
m_description = Marshal.PtrToStringUni(chainElement.pwszExtendedErrorInfo);
// We give the user a reference to the array since we'll never access it.
if (chainElement.dwErrorStatus == 0)
m_chainStatus = new X509ChainStatus[0]; // empty array
else
m_chainStatus = X509Chain.GetChainStatusInformation(chainElement.dwErrorStatus);
}
public X509Certificate2 Certificate {
get {
return m_certificate;
}
}
public X509ChainStatus[] ChainElementStatus {
get {
return m_chainStatus;
}
}
public string Information {
get {
return m_description;
}
}
}
public sealed class X509ChainElementCollection : ICollection {
private X509ChainElement[] m_elements;
internal X509ChainElementCollection () {
m_elements = new X509ChainElement[0];
}
internal unsafe X509ChainElementCollection (IntPtr pSimpleChain) {
CAPI.CERT_SIMPLE_CHAIN simpleChain = new CAPI.CERT_SIMPLE_CHAIN(Marshal.SizeOf(typeof(CAPI.CERT_SIMPLE_CHAIN)));
uint cbSize = (uint) Marshal.ReadInt32(pSimpleChain);
if (cbSize > Marshal.SizeOf(simpleChain))
cbSize = (uint) Marshal.SizeOf(simpleChain);
X509Utils.memcpy(pSimpleChain, new IntPtr(&simpleChain), cbSize);
m_elements = new X509ChainElement[simpleChain.cElement];
for (int index = 0; index < m_elements.Length; index++) {
m_elements[index] = new X509ChainElement(Marshal.ReadIntPtr(new IntPtr((long) simpleChain.rgpElement + index * Marshal.SizeOf(typeof(IntPtr)))));
}
}
public X509ChainElement this[int index] {
get {
if (index < 0)
throw new InvalidOperationException(SR.GetString(SR.InvalidOperation_EnumNotStarted));
if (index >= m_elements.Length)
throw new ArgumentOutOfRangeException("index", SR.GetString(SR.ArgumentOutOfRange_Index));
return m_elements[index];
}
}
public int Count {
get {
return m_elements.Length;
}
}
public X509ChainElementEnumerator GetEnumerator() {
return new X509ChainElementEnumerator(this);
}
///
IEnumerator IEnumerable.GetEnumerator() {
return new X509ChainElementEnumerator(this);
}
///
void ICollection.CopyTo(Array array, int index) {
if (array == null)
throw new ArgumentNullException("array");
if (array.Rank != 1)
throw new ArgumentException(SR.GetString(SR.Arg_RankMultiDimNotSupported));
if (index < 0 || index >= array.Length)
throw new ArgumentOutOfRangeException("index", SR.GetString(SR.ArgumentOutOfRange_Index));
if (index + this.Count > array.Length)
throw new ArgumentException(SR.GetString(SR.Argument_InvalidOffLen));
for (int i=0; i < this.Count; i++) {
array.SetValue(this[i], index);
index++;
}
}
public void CopyTo(X509ChainElement[] array, int index) {
((ICollection)this).CopyTo(array, index);
}
public bool IsSynchronized {
get {
return false;
}
}
public Object SyncRoot {
get {
return this;
}
}
}
public sealed class X509ChainElementEnumerator : IEnumerator {
private X509ChainElementCollection m_chainElements;
private int m_current;
private X509ChainElementEnumerator () {}
internal X509ChainElementEnumerator (X509ChainElementCollection chainElements) {
m_chainElements = chainElements;
m_current = -1;
}
public X509ChainElement Current {
get {
return (X509ChainElement) m_chainElements[m_current];
}
}
///
Object IEnumerator.Current {
get {
return (Object) m_chainElements[m_current];
}
}
public bool MoveNext() {
if (m_current == ((int) m_chainElements.Count - 1))
return false;
m_current++;
return true;
}
public void Reset() {
m_current = -1;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// X509ChainElement.cs
//
namespace System.Security.Cryptography.X509Certificates {
using System.Collections;
using System.Runtime.InteropServices;
public class X509ChainElement {
private X509Certificate2 m_certificate;
private X509ChainStatus[] m_chainStatus;
private string m_description;
private X509ChainElement () {}
internal unsafe X509ChainElement (IntPtr pChainElement) {
CAPI.CERT_CHAIN_ELEMENT chainElement = new CAPI.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_ELEMENT)));
uint cbSize = (uint) Marshal.ReadInt32(pChainElement);
if (cbSize > Marshal.SizeOf(chainElement))
cbSize = (uint) Marshal.SizeOf(chainElement);
X509Utils.memcpy(pChainElement, new IntPtr(&chainElement), cbSize);
m_certificate = new X509Certificate2(chainElement.pCertContext);
if (chainElement.pwszExtendedErrorInfo == IntPtr.Zero)
m_description = String.Empty;
else
m_description = Marshal.PtrToStringUni(chainElement.pwszExtendedErrorInfo);
// We give the user a reference to the array since we'll never access it.
if (chainElement.dwErrorStatus == 0)
m_chainStatus = new X509ChainStatus[0]; // empty array
else
m_chainStatus = X509Chain.GetChainStatusInformation(chainElement.dwErrorStatus);
}
public X509Certificate2 Certificate {
get {
return m_certificate;
}
}
public X509ChainStatus[] ChainElementStatus {
get {
return m_chainStatus;
}
}
public string Information {
get {
return m_description;
}
}
}
public sealed class X509ChainElementCollection : ICollection {
private X509ChainElement[] m_elements;
internal X509ChainElementCollection () {
m_elements = new X509ChainElement[0];
}
internal unsafe X509ChainElementCollection (IntPtr pSimpleChain) {
CAPI.CERT_SIMPLE_CHAIN simpleChain = new CAPI.CERT_SIMPLE_CHAIN(Marshal.SizeOf(typeof(CAPI.CERT_SIMPLE_CHAIN)));
uint cbSize = (uint) Marshal.ReadInt32(pSimpleChain);
if (cbSize > Marshal.SizeOf(simpleChain))
cbSize = (uint) Marshal.SizeOf(simpleChain);
X509Utils.memcpy(pSimpleChain, new IntPtr(&simpleChain), cbSize);
m_elements = new X509ChainElement[simpleChain.cElement];
for (int index = 0; index < m_elements.Length; index++) {
m_elements[index] = new X509ChainElement(Marshal.ReadIntPtr(new IntPtr((long) simpleChain.rgpElement + index * Marshal.SizeOf(typeof(IntPtr)))));
}
}
public X509ChainElement this[int index] {
get {
if (index < 0)
throw new InvalidOperationException(SR.GetString(SR.InvalidOperation_EnumNotStarted));
if (index >= m_elements.Length)
throw new ArgumentOutOfRangeException("index", SR.GetString(SR.ArgumentOutOfRange_Index));
return m_elements[index];
}
}
public int Count {
get {
return m_elements.Length;
}
}
public X509ChainElementEnumerator GetEnumerator() {
return new X509ChainElementEnumerator(this);
}
///
IEnumerator IEnumerable.GetEnumerator() {
return new X509ChainElementEnumerator(this);
}
///
void ICollection.CopyTo(Array array, int index) {
if (array == null)
throw new ArgumentNullException("array");
if (array.Rank != 1)
throw new ArgumentException(SR.GetString(SR.Arg_RankMultiDimNotSupported));
if (index < 0 || index >= array.Length)
throw new ArgumentOutOfRangeException("index", SR.GetString(SR.ArgumentOutOfRange_Index));
if (index + this.Count > array.Length)
throw new ArgumentException(SR.GetString(SR.Argument_InvalidOffLen));
for (int i=0; i < this.Count; i++) {
array.SetValue(this[i], index);
index++;
}
}
public void CopyTo(X509ChainElement[] array, int index) {
((ICollection)this).CopyTo(array, index);
}
public bool IsSynchronized {
get {
return false;
}
}
public Object SyncRoot {
get {
return this;
}
}
}
public sealed class X509ChainElementEnumerator : IEnumerator {
private X509ChainElementCollection m_chainElements;
private int m_current;
private X509ChainElementEnumerator () {}
internal X509ChainElementEnumerator (X509ChainElementCollection chainElements) {
m_chainElements = chainElements;
m_current = -1;
}
public X509ChainElement Current {
get {
return (X509ChainElement) m_chainElements[m_current];
}
}
///
Object IEnumerator.Current {
get {
return (Object) m_chainElements[m_current];
}
}
public bool MoveNext() {
if (m_current == ((int) m_chainElements.Count - 1))
return false;
m_current++;
return true;
}
public void Reset() {
m_current = -1;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AccessDataSource.cs
- ZoneIdentityPermission.cs
- AffineTransform3D.cs
- QueryCursorEventArgs.cs
- Menu.cs
- ActiveDesignSurfaceEvent.cs
- TransformValueSerializer.cs
- Path.cs
- UserControlAutomationPeer.cs
- CodeNamespaceImport.cs
- SqlClientWrapperSmiStream.cs
- ChannelPoolSettingsElement.cs
- AppSettingsExpressionEditor.cs
- HtmlTitle.cs
- XmlAttributeHolder.cs
- RegionInfo.cs
- EncoderFallback.cs
- OuterGlowBitmapEffect.cs
- Point3DValueSerializer.cs
- XmlSecureResolver.cs
- COM2Enum.cs
- AdPostCacheSubstitution.cs
- ThreadAttributes.cs
- CustomGrammar.cs
- RepeatBehavior.cs
- DescendentsWalkerBase.cs
- OutputCacheProfile.cs
- Parser.cs
- ConnectorEditor.cs
- ToolStripItemDataObject.cs
- VirtualizingPanel.cs
- SspiNegotiationTokenProvider.cs
- HtmlTableRow.cs
- XamlToRtfWriter.cs
- util.cs
- SqlStatistics.cs
- TypeConverterAttribute.cs
- DefaultAssemblyResolver.cs
- InternalPermissions.cs
- CursorConverter.cs
- WizardPanel.cs
- StylusButton.cs
- SectionVisual.cs
- DbConnectionPool.cs
- StringValidator.cs
- FontStyles.cs
- DragDeltaEventArgs.cs
- ErrorFormatter.cs
- Point.cs
- ValidationRuleCollection.cs
- VerticalAlignConverter.cs
- SyntaxCheck.cs
- Calendar.cs
- ServiceThrottle.cs
- BaseDataList.cs
- WebSysDescriptionAttribute.cs
- WebPartCloseVerb.cs
- PasswordRecoveryAutoFormat.cs
- DragCompletedEventArgs.cs
- ToolStripPanelRenderEventArgs.cs
- DataGridViewHitTestInfo.cs
- Thickness.cs
- SimpleRecyclingCache.cs
- Icon.cs
- DesignerActionListCollection.cs
- XmlHierarchicalEnumerable.cs
- PeerCustomResolverSettings.cs
- ControlTemplate.cs
- DragEventArgs.cs
- ElementAtQueryOperator.cs
- OuterGlowBitmapEffect.cs
- FirstMatchCodeGroup.cs
- ToolTipAutomationPeer.cs
- ObjectToIdCache.cs
- Color.cs
- HttpApplicationFactory.cs
- SchemaImporterExtensionElement.cs
- IPipelineRuntime.cs
- MessageBox.cs
- RedistVersionInfo.cs
- ScriptRegistrationManager.cs
- WebPartMinimizeVerb.cs
- XmlDataSourceView.cs
- UIElementCollection.cs
- ManifestSignatureInformation.cs
- RuntimeResourceSet.cs
- PageContent.cs
- BindingMAnagerBase.cs
- StatusBarItem.cs
- QueryCacheEntry.cs
- ResourceCodeDomSerializer.cs
- AVElementHelper.cs
- DataSourceControlBuilder.cs
- FastPropertyAccessor.cs
- XmlElement.cs
- SchemaNamespaceManager.cs
- ObjectQueryExecutionPlan.cs
- HijriCalendar.cs
- UntypedNullExpression.cs
- MetadataArtifactLoaderResource.cs