// RevocationValues.cs // // XAdES Starter Kit for Microsoft .NET 3.5 (and above) // 2010 Microsoft France // Published under the CECILL-B Free Software license agreement. // (http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt) // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. // THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE OF THIS CODE // AND INFORMATION REMAINS WITH THE USER. using System; using System.Xml; namespace Microsoft.Xades { /// /// The RevocationValues element is used to hold the values of the /// revocation information which are to be shipped with the XML signature /// in case of an XML Advanced Electronic Signature with Extended /// Validation Data (XAdES-X-Long). This is a unsigned property that /// qualifies the signature. An XML electronic signature aligned with the /// present document MAY contain at most one RevocationValues element. /// public class RevocationValues { #region Private variables private string id; private CRLValues crlValues; private OCSPValues ocspValues; private OtherValues otherValues; #endregion #region Public properties /// /// Optional Id for the XML element /// public string Id { get { return this.id; } set { this.id = value; } } /// /// Certificate Revocation Lists /// public CRLValues CRLValues { get { return this.crlValues; } set { this.crlValues = value; } } /// /// Responses from an online certificate status server /// public OCSPValues OCSPValues { get { return this.ocspValues; } set { this.ocspValues = value; } } /// /// Placeholder for other revocation information is provided for future /// use /// public OtherValues OtherValues { get { return this.otherValues; } set { this.otherValues = value; } } #endregion #region Constructors /// /// Default constructor /// public RevocationValues() { this.crlValues = new CRLValues(); this.ocspValues = new OCSPValues(); this.otherValues = new OtherValues(); } #endregion #region Public methods /// /// Check to see if something has changed in this instance and needs to be serialized /// /// Flag indicating if a member needs serialization public bool HasChanged() { bool retVal = false; if (!String.IsNullOrEmpty(this.id)) { retVal = true; } if (this.crlValues != null && this.crlValues.HasChanged()) { retVal = true; } if (this.ocspValues != null && this.ocspValues.HasChanged()) { retVal = true; } if (this.otherValues != null && this.otherValues.HasChanged()) { retVal = true; } return retVal; } /// /// Load state from an XML element /// /// XML element containing new state public void LoadXml(System.Xml.XmlElement xmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } if (xmlElement.HasAttribute("Id")) { this.id = xmlElement.GetAttribute("Id"); } else { this.id = ""; } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri); xmlNodeList = xmlElement.SelectNodes("xsd:CRLValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.crlValues = new CRLValues(); this.crlValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } xmlNodeList = xmlElement.SelectNodes("xsd:OCSPValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.ocspValues = new OCSPValues(); this.ocspValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } xmlNodeList = xmlElement.SelectNodes("xsd:OtherValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.otherValues = new OtherValues(); this.otherValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } } /// /// Returns the XML representation of the this object /// /// XML element containing the state of this object public XmlElement GetXml() { XmlDocument creationXmlDocument; XmlElement retVal; creationXmlDocument = new XmlDocument(); retVal = creationXmlDocument.CreateElement("xades", "RevocationValues", XadesSignedXml.XadesNamespaceUri); if (this.id != null && this.id != "") { retVal.SetAttribute("Id", this.id); } if (this.crlValues != null && this.crlValues.HasChanged()) { retVal.AppendChild(creationXmlDocument.ImportNode(this.crlValues.GetXml(), true)); } if (this.ocspValues != null && this.ocspValues.HasChanged()) { retVal.AppendChild(creationXmlDocument.ImportNode(this.ocspValues.GetXml(), true)); } if (this.otherValues != null && this.otherValues.HasChanged()) { retVal.AppendChild(creationXmlDocument.ImportNode(this.otherValues.GetXml(), true)); } return retVal; } #endregion } }