This class refers to one ds:Reference element of the ds:SignedInfo corresponding with one data object qualified by this property. If some but not all the signed data objects share the same commitment, one ObjectReference element must appear for each one of them. However, if all the signed data objects share the same commitment, the AllSignedDataObjects empty element must be present.
示例#1
0
        private bool CheckObjectReference(ObjectReference objectReference)
        {
            bool retVal = false;

            for (int referenceCounter = 0; retVal == false && (referenceCounter < this.SignedInfo.References.Count); referenceCounter++)
            {
                string referenceId = ((Reference)this.SignedInfo.References[referenceCounter]).Id;
                if (("#" + referenceId) == objectReference.ObjectReferenceUri)
                {
                    retVal = true;
                }
            }

            return retVal;
        }
        /// <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;
            ObjectReference newObjectReference;

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

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

            xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeId", xmlNamespaceManager);
            if (xmlNodeList.Count == 0)
            {
                this.commitmentTypeId = null;
                throw new CryptographicException("CommitmentTypeId missing");
            }
            else
            {
                this.commitmentTypeId = new ObjectIdentifier("CommitmentTypeId");
                this.commitmentTypeId.LoadXml((XmlElement)xmlNodeList.Item(0));
            }

            xmlNodeList = xmlElement.SelectNodes("xsd:ObjectReference", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.objectReferenceCollection.Clear();
                this.allSignedDataObjects = false;
                enumerator = xmlNodeList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        iterationXmlElement = enumerator.Current as XmlElement;
                        if (iterationXmlElement != null)
                        {
                            newObjectReference = new ObjectReference();
                            newObjectReference.LoadXml(iterationXmlElement);
                            this.objectReferenceCollection.Add(newObjectReference);
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }

            }
            else
            {
                this.objectReferenceCollection.Clear();
                this.allSignedDataObjects = true;
            }

            xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeQualifiers", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.commitmentTypeQualifiers = new CommitmentTypeQualifiers();
                this.commitmentTypeQualifiers.LoadXml((XmlElement)xmlNodeList.Item(0));
            }
        }
		/// <summary>
		/// Add typed object to the collection
		/// </summary>
		/// <param name="objectToAdd">Typed object to be added to collection</param>
		/// <returns>The object that has been added to collection</returns>
		public ObjectReference Add(ObjectReference objectToAdd)
		{
			base.Add(objectToAdd);

			return objectToAdd;
		}
        /// <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;
            ObjectReference     newObjectReference;

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

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

            xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeId", xmlNamespaceManager);
            if (xmlNodeList.Count == 0)
            {
                this.commitmentTypeId = null;
                throw new CryptographicException("CommitmentTypeId missing");
            }
            else
            {
                this.commitmentTypeId = new ObjectIdentifier("CommitmentTypeId");
                this.commitmentTypeId.LoadXml((XmlElement)xmlNodeList.Item(0));
            }

            xmlNodeList = xmlElement.SelectNodes("xsd:ObjectReference", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.objectReferenceCollection.Clear();
                this.allSignedDataObjects = false;
                enumerator = xmlNodeList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        iterationXmlElement = enumerator.Current as XmlElement;
                        if (iterationXmlElement != null)
                        {
                            newObjectReference = new ObjectReference();
                            newObjectReference.LoadXml(iterationXmlElement);
                            this.objectReferenceCollection.Add(newObjectReference);
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            else
            {
                this.objectReferenceCollection.Clear();
                this.allSignedDataObjects = true;
            }

            xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeQualifiers", xmlNamespaceManager);
            if (xmlNodeList.Count != 0)
            {
                this.commitmentTypeQualifiers = new CommitmentTypeQualifiers();
                this.commitmentTypeQualifiers.LoadXml((XmlElement)xmlNodeList.Item(0));
            }
        }
        /// <summary>
        /// Add typed object to the collection
        /// </summary>
        /// <param name="objectToAdd">Typed object to be added to collection</param>
        /// <returns>The object that has been added to collection</returns>
        public ObjectReference Add(ObjectReference objectToAdd)
        {
            base.Add(objectToAdd);

            return(objectToAdd);
        }