2 // EncryptedReference.cs - EncryptedReference implementation for XML Encryption
3 // http://www.w3.org/2001/04/xmlenc#sec-EncryptedReference
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Tim Coleman, 2004
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.
34 namespace System.Security.Cryptography.Xml {
35 public abstract class EncryptedReference {
47 protected EncryptedReference ()
49 TransformChain = new TransformChain ();
52 protected EncryptedReference (string uri)
55 TransformChain = new TransformChain ();
58 protected EncryptedReference (string uri, TransformChain transformChain)
62 TransformChain = transformChain;
65 #endregion // Constructors
69 [MonoTODO("Always returns false")]
70 protected internal bool CacheValid {
74 protected string ReferenceType {
75 get { return referenceType; }
76 set { referenceType = value; }
79 public TransformChain TransformChain {
89 #endregion // Properties
93 public void AddTransform (Transform transform)
95 TransformChain.Add (transform);
98 public virtual XmlElement GetXml ()
100 return GetXml (new XmlDocument ());
103 internal virtual XmlElement GetXml (XmlDocument document)
105 XmlElement xel = document.CreateElement (ReferenceType, EncryptedXml.XmlEncNamespaceUrl);
107 xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
109 if (TransformChain != null && TransformChain.Count > 0) {
110 XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, EncryptedXml.XmlEncNamespaceUrl);
111 foreach (Transform t in TransformChain)
112 xtr.AppendChild (document.ImportNode (t.GetXml (), true));
113 xel.AppendChild (xtr);
119 [MonoTODO ("Make compliant.")]
120 public virtual void LoadXml (XmlElement value)
123 throw new ArgumentNullException ("value");
126 TransformChain = new TransformChain ();
128 foreach (XmlNode n in value.ChildNodes) {
129 if (n is XmlWhitespace)
132 switch (n.LocalName) {
133 case XmlEncryption.ElementNames.Transforms:
134 foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
136 switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
137 case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
138 t = new XmlDsigBase64Transform ();
140 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
141 t = new XmlDsigC14NTransform ();
143 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
144 t = new XmlDsigC14NWithCommentsTransform ();
146 case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
147 t = new XmlDsigEnvelopedSignatureTransform ();
149 case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
150 t = new XmlDsigXPathTransform ();
152 case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
153 t = new XmlDsigXsltTransform ();
155 case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform:
156 t = new XmlDsigExcC14NTransform ();
158 case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NWithCommentsTransform:
159 t = new XmlDsigExcC14NWithCommentsTransform ();
161 case XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform:
162 t = new XmlDecryptionTransform ();
168 t.LoadInnerXml (((XmlElement) xn).ChildNodes);
169 TransformChain.Add (t);
175 if (value.HasAttribute (XmlEncryption.AttributeNames.URI))
176 Uri = value.Attributes [XmlEncryption.AttributeNames.URI].Value;
180 #endregion // Methods