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.
35 namespace System.Security.Cryptography.Xml {
36 public abstract class EncryptedReference {
49 protected EncryptedReference ()
52 TransformChain = new TransformChain ();
55 protected EncryptedReference (string uri)
58 TransformChain = new TransformChain ();
61 protected EncryptedReference (string uri, TransformChain tc)
68 #endregion // Constructors
73 protected internal bool CacheValid {
74 get { return cacheValid; }
77 protected string ReferenceType {
78 get { return referenceType; }
79 set { referenceType = value; }
82 public TransformChain TransformChain {
92 #endregion // Properties
96 public void AddTransform (Transform transform)
98 TransformChain.Add (transform);
101 public virtual XmlElement GetXml ()
103 return GetXml (new XmlDocument ());
106 internal virtual XmlElement GetXml (XmlDocument document)
108 XmlElement xel = document.CreateElement (ReferenceType, EncryptedXml.XmlEncNamespaceUrl);
110 xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
112 if (TransformChain != null && TransformChain.Count > 0) {
113 XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, EncryptedXml.XmlEncNamespaceUrl);
114 foreach (Transform t in TransformChain)
115 xtr.AppendChild (document.ImportNode (t.GetXml (), true));
116 xel.AppendChild (xtr);
122 [MonoTODO ("Make compliant.")]
123 public virtual void LoadXml (XmlElement value)
126 throw new ArgumentNullException ("value");
129 TransformChain = new TransformChain ();
131 foreach (XmlNode n in value.ChildNodes) {
132 if (n is XmlWhitespace)
135 switch (n.LocalName) {
136 case XmlEncryption.ElementNames.Transforms:
137 foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
139 switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
140 case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
141 t = new XmlDsigBase64Transform ();
143 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
144 t = new XmlDsigC14NTransform ();
146 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
147 t = new XmlDsigC14NWithCommentsTransform ();
149 case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
150 t = new XmlDsigEnvelopedSignatureTransform ();
152 case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
153 t = new XmlDsigXPathTransform ();
155 case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
156 t = new XmlDsigXsltTransform ();
159 case XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform:
160 t = new XmlDecryptionTransform ();
167 t.LoadInnerXml (((XmlElement) xn).ChildNodes);
168 TransformChain.Add (t);
174 if (value.HasAttribute (XmlEncryption.AttributeNames.URI))
175 Uri = value.Attributes [XmlEncryption.AttributeNames.URI].Value;
179 #endregion // Methods