public void LoadXml(XmlElement value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } XmlElement keyInfoElement = value; _id = Utils.GetAttribute(keyInfoElement, "Id", SignedXml.XmlDsigNamespaceUrl); if (!Utils.VerifyAttributes(keyInfoElement, "Id")) { throw new CryptographicException(SR.Cryptography_Xml_InvalidElement, "KeyInfo"); } XmlNode child = keyInfoElement.FirstChild; while (child != null) { XmlElement elem = child as XmlElement; if (elem != null) { // Create the right type of KeyInfoClause; we use a combination of the namespace and tag name (local name) string kicString = elem.NamespaceURI + " " + elem.LocalName; // Special-case handling for KeyValue -- we have to go one level deeper if (kicString == "http://www.w3.org/2000/09/xmldsig# KeyValue") { if (!Utils.VerifyAttributes(elem, (string[])null)) { throw new CryptographicException(SR.Cryptography_Xml_InvalidElement, "KeyInfo/KeyValue"); } XmlNodeList nodeList2 = elem.ChildNodes; foreach (XmlNode node2 in nodeList2) { XmlElement elem2 = node2 as XmlElement; if (elem2 != null) { kicString += "/" + elem2.LocalName; break; } } } KeyInfoClause keyInfoClause = CryptoHelpers.CreateFromName <KeyInfoClause>(kicString); // if we don't know what kind of KeyInfoClause we're looking at, use a generic KeyInfoNode: keyInfoClause ??= new KeyInfoNode(); // Ask the create clause to fill itself with the corresponding XML keyInfoClause.LoadXml(elem); // Add it to our list of KeyInfoClauses AddClause(keyInfoClause); } child = child.NextSibling; } }
public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException("value"); } Id = value.Attributes ["Id"] != null?value.GetAttribute("Id") : null; if ((value.LocalName == XmlSignature.ElementNames.KeyInfo) && (value.NamespaceURI == XmlSignature.NamespaceURI)) { foreach (XmlNode n in value.ChildNodes) { if (n.NodeType != XmlNodeType.Element) { continue; } KeyInfoClause kic = null; switch (n.LocalName) { case XmlSignature.ElementNames.KeyValue: XmlNodeList xnl = n.ChildNodes; if (xnl.Count > 0) { // we must now treat the whitespace ! foreach (XmlNode m in xnl) { switch (m.LocalName) { case XmlSignature.ElementNames.DSAKeyValue: kic = (KeyInfoClause) new DSAKeyValue(); break; case XmlSignature.ElementNames.RSAKeyValue: kic = (KeyInfoClause) new RSAKeyValue(); break; } } } break; case XmlSignature.ElementNames.KeyName: kic = (KeyInfoClause) new KeyInfoName(); break; case XmlSignature.ElementNames.RetrievalMethod: kic = (KeyInfoClause) new KeyInfoRetrievalMethod(); break; case XmlSignature.ElementNames.X509Data: kic = (KeyInfoClause) new KeyInfoX509Data(); break; case XmlSignature.ElementNames.RSAKeyValue: kic = (KeyInfoClause) new RSAKeyValue(); break; #if NET_2_0 case XmlSignature.ElementNames.EncryptedKey: kic = (KeyInfoClause) new KeyInfoEncryptedKey(); break; #endif default: kic = (KeyInfoClause) new KeyInfoNode(); break; } if (kic != null) { kic.LoadXml((XmlElement)n); AddClause(kic); } } } // No check is performed on MS.NET... }