2 // KeyInfo.cs - Xml Signature KeyInfo implementation
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
34 namespace System.Security.Cryptography.Xml {
36 public class KeyInfo : IEnumerable {
38 private ArrayList Info;
43 Info = new ArrayList ();
47 get { return Info.Count; }
55 public void AddClause (KeyInfoClause clause)
60 public IEnumerator GetEnumerator ()
62 return Info.GetEnumerator ();
65 public IEnumerator GetEnumerator (Type requestedObjectType)
67 // Build a new ArrayList...
68 ArrayList TypeList = new ArrayList ();
69 IEnumerator e = Info.GetEnumerator ();
71 // ...with all object of specified type...
72 if ((e.Current).GetType().Equals (requestedObjectType))
73 TypeList.Add (e.Current);
77 // ...and return its enumerator
78 return TypeList.GetEnumerator ();
81 public XmlElement GetXml ()
83 XmlDocument document = new XmlDocument ();
84 XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyInfo, XmlSignature.NamespaceURI);
85 // we add References afterward so we don't end up with extraneous
86 // xmlns="..." in each reference elements.
87 foreach (KeyInfoClause kic in Info) {
88 XmlNode xn = kic.GetXml ();
89 XmlNode newNode = document.ImportNode (xn, true);
90 xel.AppendChild (newNode);
95 public void LoadXml (XmlElement value)
98 throw new ArgumentNullException ("value");
100 Id = value.Attributes ["Id"] != null ? value.GetAttribute ("Id") : null;
102 if ((value.LocalName == XmlSignature.ElementNames.KeyInfo) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
103 foreach (XmlNode n in value.ChildNodes) {
104 if (n.NodeType != XmlNodeType.Element)
107 KeyInfoClause kic = null;
109 switch (n.LocalName) {
110 case XmlSignature.ElementNames.KeyValue:
111 XmlNodeList xnl = n.ChildNodes;
113 // we must now treat the whitespace !
114 foreach (XmlNode m in xnl) {
115 switch (m.LocalName) {
116 case XmlSignature.ElementNames.DSAKeyValue:
117 kic = (KeyInfoClause) new DSAKeyValue ();
119 case XmlSignature.ElementNames.RSAKeyValue:
120 kic = (KeyInfoClause) new RSAKeyValue ();
126 case XmlSignature.ElementNames.KeyName:
127 kic = (KeyInfoClause) new KeyInfoName ();
129 case XmlSignature.ElementNames.RetrievalMethod:
130 kic = (KeyInfoClause) new KeyInfoRetrievalMethod ();
132 case XmlSignature.ElementNames.X509Data:
133 kic = (KeyInfoClause) new KeyInfoX509Data ();
135 case XmlSignature.ElementNames.RSAKeyValue:
136 kic = (KeyInfoClause) new RSAKeyValue ();
138 case XmlSignature.ElementNames.EncryptedKey:
139 kic = (KeyInfoClause) new KeyInfoEncryptedKey ();
142 kic = (KeyInfoClause) new KeyInfoNode ();
147 kic.LoadXml ((XmlElement) n);
152 // No check is performed on MS.NET...