This class contains a timestamp encoded as XML
Example #1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public TimeStamp()
 {
     this.canonicalizationMethod = new CanonicalizationMethod();
     this.hashDataInfoCollection = new HashDataInfoCollection();
     this.encapsulatedTimeStamp  = new EncapsulatedPKIData("EncapsulatedTimeStamp");
     this.xmlTimeStamp           = null;
 }
Example #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public TimeStamp(string prefix, string namespaceUri)
        {
            this.hashDataInfoCollection = new HashDataInfoCollection();
            this.encapsulatedTimeStamp  = new EncapsulatedPKIData("EncapsulatedTimeStamp");
            this.xmlTimeStamp           = null;

            this.prefix       = prefix;
            this.namespaceUri = namespaceUri;
        }
        /// <summary>
        /// Load state from an XML element
        /// </summary>
        /// <param name="xmlElement">XML element containing new state</param>
        public void LoadXml(System.Xml.XmlElement xmlElement)
        {
            XmlNamespaceManager xmlNamespaceManager;
            XmlNodeList         xmlNodeList;
            IEnumerator         enumerator;
            XmlElement          iterationXmlElement;
            HashDataInfo        newHashDataInfo;

            if (xmlElement == null)
            {
                throw new ArgumentNullException("xmlElement");
            }

            xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
            xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri);

            this.hashDataInfoCollection.Clear();
            xmlNodeList = xmlElement.SelectNodes("xsd:HashDataInfo", xmlNamespaceManager);
            enumerator  = xmlNodeList.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    iterationXmlElement = enumerator.Current as XmlElement;
                    if (iterationXmlElement != null)
                    {
                        newHashDataInfo = new HashDataInfo();
                        newHashDataInfo.LoadXml(iterationXmlElement);
                        this.hashDataInfoCollection.Add(newHashDataInfo);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }

            xmlNodeList = xmlElement.SelectNodes("xsd:EncapsulatedTimeStamp", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
                this.encapsulatedTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
                this.xmlTimeStamp = null;
            }
            else
            {
                xmlNodeList = xmlElement.SelectNodes("xsd:XMLTimeStamp", xmlNamespaceManager);
                if (xmlNodeList.Count != 0)
                {
                    this.xmlTimeStamp = new XMLTimeStamp();
                    this.xmlTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
                    this.encapsulatedTimeStamp = null;
                }
                else
                {
                    throw new CryptographicException("EncapsulatedTimeStamp or XMLTimeStamp missing");
                }
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 public TimeStamp()
 {
     this.hashDataInfoCollection = new HashDataInfoCollection();
     this.encapsulatedTimeStamp  = new EncapsulatedPKIData("EncapsulatedTimeStamp");
     this.xmlTimeStamp           = null;
 }
Example #5
0
        /// <summary>
        /// Load state from an XML element
        /// </summary>
        /// <param name="xmlElement">XML element containing new state</param>
        public void LoadXml(System.Xml.XmlElement xmlElement)
        {
            XmlNamespaceManager xmlNamespaceManager;
            XmlNodeList         xmlNodeList;
            IEnumerator         enumerator;
            XmlElement          iterationXmlElement;
            HashDataInfo        newHashDataInfo;

            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.HasAttribute("Id"))
            {
                this.id = xmlElement.GetAttribute("Id");
            }
            else
            {
                this.id = "";
            }

            xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
            xmlNamespaceManager.AddNamespace("xades", XadesSignedXml.XadesNamespaceUri);

            this.hashDataInfoCollection.Clear();
            xmlNodeList = xmlElement.SelectNodes("xades:HashDataInfo", xmlNamespaceManager);
            enumerator  = xmlNodeList.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    iterationXmlElement = enumerator.Current as XmlElement;
                    if (iterationXmlElement != null)
                    {
                        newHashDataInfo = new HashDataInfo();
                        newHashDataInfo.LoadXml(iterationXmlElement);
                        this.hashDataInfoCollection.Add(newHashDataInfo);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }

            xmlNodeList = xmlElement.SelectNodes("xades:EncapsulatedTimeStamp", xmlNamespaceManager);

            if (xmlNodeList.Count != 0)
            {
                this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
                this.encapsulatedTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
                this.xmlTimeStamp = null;
            }
            else
            {
                XmlNode nodeEncapsulatedTimeStamp = null;

                foreach (XmlNode node in xmlElement.ChildNodes)
                {
                    if (node.Name == "EncapsulatedTimeStamp")
                    {
                        nodeEncapsulatedTimeStamp = node;
                        break;
                    }
                }

                if (nodeEncapsulatedTimeStamp != null)
                {
                    this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
                    this.encapsulatedTimeStamp.LoadXml((XmlElement)nodeEncapsulatedTimeStamp);
                    this.xmlTimeStamp = null;
                }
                else
                {
                    xmlNodeList = xmlElement.SelectNodes("xades:XMLTimeStamp", xmlNamespaceManager);
                    if (xmlNodeList.Count != 0)
                    {
                        this.xmlTimeStamp = new XMLTimeStamp();
                        this.xmlTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
                        this.encapsulatedTimeStamp = null;
                    }
                    else
                    {
                        throw new CryptographicException("EncapsulatedTimeStamp or XMLTimeStamp element is missing");
                    }
                }
            }
        }
Example #6
0
		/// <summary>
		/// Load state from an XML element
		/// </summary>
		/// <param name="xmlElement">XML element containing new state</param>
		public void LoadXml(System.Xml.XmlElement xmlElement)
		{
			XmlNamespaceManager xmlNamespaceManager;
			XmlNodeList xmlNodeList;
			IEnumerator enumerator;
			XmlElement iterationXmlElement;
			HashDataInfo newHashDataInfo;
			
			if (xmlElement == null)
			{
				throw new ArgumentNullException("xmlElement");
			}

			xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
			xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri);

			this.hashDataInfoCollection.Clear();
			xmlNodeList = xmlElement.SelectNodes("xsd:HashDataInfo", xmlNamespaceManager);
			enumerator = xmlNodeList.GetEnumerator();
			try 
			{
				while (enumerator.MoveNext()) 
				{
					iterationXmlElement = enumerator.Current as XmlElement;
					if (iterationXmlElement != null)
					{
						newHashDataInfo = new HashDataInfo();
						newHashDataInfo.LoadXml(iterationXmlElement);
						this.hashDataInfoCollection.Add(newHashDataInfo);
					}
				}
			}
			finally 
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}

			xmlNodeList = xmlElement.SelectNodes("xsd:EncapsulatedTimeStamp", xmlNamespaceManager);
			if (xmlNodeList.Count != 0)
			{
				this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
				this.encapsulatedTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
				this.xmlTimeStamp = null;
			}
			else
			{
				xmlNodeList = xmlElement.SelectNodes("xsd:XMLTimeStamp", xmlNamespaceManager);
				if (xmlNodeList.Count != 0)
				{
					this.xmlTimeStamp = new XMLTimeStamp();
					this.xmlTimeStamp.LoadXml((XmlElement)xmlNodeList.Item(0));
					this.encapsulatedTimeStamp = null;

				}
				else
				{
					throw new CryptographicException("EncapsulatedTimeStamp or XMLTimeStamp missing");
				}
			}
		}
Example #7
0
		/// <summary>
		/// Default constructor
		/// </summary>
		public TimeStamp()
		{
			this.hashDataInfoCollection = new HashDataInfoCollection();
			this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
			this.xmlTimeStamp = null;
		}
Example #8
0
		/// <summary>
		/// Default constructor
		/// </summary>
		public TimeStamp()
		{
            this.canonicalizationMethod = new CanonicalizationMethod();
			this.hashDataInfoCollection = new HashDataInfoCollection();
			this.encapsulatedTimeStamp = new EncapsulatedPKIData("EncapsulatedTimeStamp");
			this.xmlTimeStamp = null;
		}