/*
* Mentalis.org Security Library
*
* Copyright © 2002-2005, The KPD-Team
* All rights reserved.
* http://www.mentalis.org/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the KPD-Team, nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Threading;
using Org.Mentalis.Security;
namespace Org.Mentalis.Security.Certificates {
///
/// Represents the status of an asynchronous certificate chain verification operation.
///
internal class CertificateVerificationResult : IAsyncResult {
///
/// Initializes a new CertificateVerificationResult instance.
///
/// The that has to be verified.
/// The server to which the has been issued.
/// One of the values.
/// One of the values.
/// The delegate to call when the verification finishes.
/// User-defined state data.
public CertificateVerificationResult(CertificateChain chain, string server, AuthType type, VerificationFlags flags, AsyncCallback callback, object asyncState) {
m_Chain = chain;
m_Server = server;
m_Type = type;
m_Flags = flags;
m_AsyncState = asyncState;
m_Callback = callback;
m_WaitHandle = null;
m_HasEnded = false;
}
///
/// Gets an indication of whether the asynchronous operation completed synchronously.
///
/// Always false.
public bool CompletedSynchronously {
get {
return false;
}
}
///
/// Gets a boolean value that indicates whether the operation has finished.
///
///
/// true if the verification of the chain has been completed, false otherwise.
///
public bool IsCompleted {
get {
return m_IsCompleted;
}
}
///
/// Gets a that is used to wait for an asynchronous operation to complete.
///
///
/// A WaitHandle that is used to wait for an asynchronous operation to complete.
///
public WaitHandle AsyncWaitHandle {
get {
if (m_WaitHandle == null)
m_WaitHandle = new ManualResetEvent(false);
return m_WaitHandle;
}
}
///
/// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
///
///
/// A user-defined object that qualifies or contains information about an asynchronous operation.
///
public object AsyncState {
get {
return m_AsyncState;
}
}
///
/// Sets the WaitHandle to signalled and calls the appropriate delegate.
///
/// An exception that may have occurred.
/// The status of the certificate chain.
internal void VerificationCompleted(Exception error, CertificateStatus status) {
m_ThrowException = error;
m_Status = status;
m_IsCompleted = true;
if (m_Callback != null)
m_Callback(this);
if (m_WaitHandle != null)
m_WaitHandle.Set();
}
///
/// Gets the associated certificate chain.
///
///
/// A instance.
///
public CertificateChain Chain {
get {
return m_Chain;
}
}
///
/// Gets the associated server name.
///
///
/// A string that holds the server name.
///
public string Server {
get {
return m_Server;
}
}
///
/// Gets the associated authentication type.
///
///
/// One of the values.
///
public AuthType Type {
get {
return m_Type;
}
}
///
/// Gets the associated verification flags.
///
///
/// One of the values.
///
public VerificationFlags Flags {
get {
return m_Flags;
}
}
///
/// Gets or sets a value that indicates whether the user has called EndVerifyChain for this object.
///
///
/// true if the user has called EndVerifyChain, false otherwise.
///
public bool HasEnded {
get {
return m_HasEnded;
}
set {
m_HasEnded = value;
}
}
///
/// Gets an exception that has occurred while verifying the certificate chain or a null reference (Nothing in Visual Basic) if the verification succeeded.
///
///
/// A instance.
///
public Exception ThrowException {
get {
return m_ThrowException;
}
}
///
/// Gets the status of the .
///
///
/// One of the values.
///
public CertificateStatus Status {
get {
return m_Status;
}
}
/// Holds the value of the IsCompleted property.
private bool m_IsCompleted;
/// Holds the value of the AsyncState property.
private object m_AsyncState;
/// Holds the value of the Chain property.
private CertificateChain m_Chain;
/// Holds the value of the Server property.
private string m_Server;
/// Holds the value of the Type property.
private AuthType m_Type;
/// Holds the value of the Flags property.
private VerificationFlags m_Flags;
/// Holds the value of the WaitHandle property.
private ManualResetEvent m_WaitHandle;
/// Holds the value of the Callback property.
private AsyncCallback m_Callback;
/// Holds the value of the HasEnded property.
private bool m_HasEnded;
/// Holds the value of the ThrowException property.
private Exception m_ThrowException;
/// Holds the value of the Status property.
private CertificateStatus m_Status;
}
}