2 // KeyInfo.cs - Xml Signature KeyInfo implementation
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 using System.Collections;
13 namespace System.Security.Cryptography.Xml {
15 public class KeyInfo : IEnumerable {
17 private ArrayList Info;
22 Info = new ArrayList ();
26 get { return Info.Count; }
34 public void AddClause (KeyInfoClause clause)
39 public IEnumerator GetEnumerator ()
41 return Info.GetEnumerator ();
44 public IEnumerator GetEnumerator (Type requestedObjectType)
46 // Build a new ArrayList...
47 ArrayList TypeList = new ArrayList ();
48 IEnumerator e = Info.GetEnumerator ();
50 // ...with all object of specified type...
51 if ((e.Current).GetType().Equals (requestedObjectType))
52 TypeList.Add (e.Current);
56 // ...and return its enumerator
57 return TypeList.GetEnumerator ();
60 public XmlElement GetXml ()
62 XmlDocument document = new XmlDocument ();
63 XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyInfo, XmlSignature.NamespaceURI);
64 // we add References afterward so we don't end up with extraneous
65 // xmlns="..." in each reference elements.
66 foreach (KeyInfoClause kic in Info) {
67 XmlNode xn = kic.GetXml ();
68 XmlNode newNode = document.ImportNode (xn, true);
69 xel.AppendChild (newNode);
74 public void LoadXml (XmlElement value)
77 throw new ArgumentNullException ("value");
79 if ((value.LocalName == XmlSignature.ElementNames.KeyInfo) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
80 foreach (XmlNode n in value.ChildNodes) {
81 KeyInfoClause kic = null;
82 if (n is XmlWhitespace)
85 switch (n.LocalName) {
86 case XmlSignature.ElementNames.KeyValue:
87 XmlNodeList xnl = n.ChildNodes;
89 // we must now treat the whitespace !
90 foreach (XmlNode m in xnl) {
91 switch (m.LocalName) {
92 case XmlSignature.ElementNames.DSAKeyValue:
93 kic = (KeyInfoClause) new DSAKeyValue ();
95 case XmlSignature.ElementNames.RSAKeyValue:
96 kic = (KeyInfoClause) new RSAKeyValue ();
102 case XmlSignature.ElementNames.KeyName:
103 kic = (KeyInfoClause) new KeyInfoName ();
105 case XmlSignature.ElementNames.RetrievalMethod:
106 kic = (KeyInfoClause) new KeyInfoRetrievalMethod ();
108 case XmlSignature.ElementNames.X509Data:
109 kic = (KeyInfoClause) new KeyInfoX509Data ();
111 /* case XmlSignature.ElementNames.RSAKeyValue:
112 kic = (KeyInfoClause) new RSAKeyValue ();
115 kic = (KeyInfoClause) new KeyInfoNode ();
120 kic.LoadXml ((XmlElement) n);