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 ()
51 TransformChain
= new TransformChain ();
54 protected EncryptedReference (string uri
)
57 TransformChain
= new TransformChain ();
60 protected EncryptedReference (string uri
, TransformChain tc
)
67 #endregion // Constructors
72 protected internal bool CacheValid
{
73 get { return cacheValid; }
76 protected string ReferenceType
{
77 get { return referenceType; }
78 set { referenceType = value; }
81 public TransformChain TransformChain
{
91 #endregion // Properties
95 public void AddTransform (Transform transform
)
97 TransformChain
.Add (transform
);
100 public virtual XmlElement
GetXml ()
102 return GetXml (new XmlDocument ());
105 internal virtual XmlElement
GetXml (XmlDocument document
)
107 XmlElement xel
= document
.CreateElement (ReferenceType
, EncryptedXml
.XmlEncNamespaceUrl
);
109 xel
.SetAttribute (XmlEncryption
.AttributeNames
.URI
, Uri
);
111 if (TransformChain
!= null && TransformChain
.Count
> 0) {
112 XmlElement xtr
= document
.CreateElement (XmlEncryption
.ElementNames
.Transforms
, EncryptedXml
.XmlEncNamespaceUrl
);
113 foreach (Transform t
in TransformChain
)
114 xtr
.AppendChild (document
.ImportNode (t
.GetXml (), true));
115 xel
.AppendChild (xtr
);
121 [MonoTODO ("Make compliant.")]
122 public virtual void LoadXml (XmlElement
value)
125 throw new ArgumentNullException ("value");
128 TransformChain
= new TransformChain ();
130 foreach (XmlNode n
in value.ChildNodes
) {
131 if (n
is XmlWhitespace
)
134 switch (n
.LocalName
) {
135 case XmlEncryption
.ElementNames
.Transforms
:
136 foreach (XmlNode xn
in ((XmlElement
) n
).GetElementsByTagName (XmlSignature
.ElementNames
.Transform
, XmlSignature
.NamespaceURI
)) {
138 switch (((XmlElement
) xn
).Attributes
[XmlSignature
.AttributeNames
.Algorithm
].Value
) {
139 case XmlSignature
.AlgorithmNamespaces
.XmlDsigBase64Transform
:
140 t
= new XmlDsigBase64Transform ();
142 case XmlSignature
.AlgorithmNamespaces
.XmlDsigC14NTransform
:
143 t
= new XmlDsigC14NTransform ();
145 case XmlSignature
.AlgorithmNamespaces
.XmlDsigC14NWithCommentsTransform
:
146 t
= new XmlDsigC14NWithCommentsTransform ();
148 case XmlSignature
.AlgorithmNamespaces
.XmlDsigEnvelopedSignatureTransform
:
149 t
= new XmlDsigEnvelopedSignatureTransform ();
151 case XmlSignature
.AlgorithmNamespaces
.XmlDsigXPathTransform
:
152 t
= new XmlDsigXPathTransform ();
154 case XmlSignature
.AlgorithmNamespaces
.XmlDsigXsltTransform
:
155 t
= new XmlDsigXsltTransform ();
158 case XmlSignature
.AlgorithmNamespaces
.XmlDsigExcC14NTransform
:
159 t
= new XmlDsigExcC14NTransform ();
161 case XmlSignature
.AlgorithmNamespaces
.XmlDsigExcC14NWithCommentsTransform
:
162 t
= new XmlDsigExcC14NWithCommentsTransform ();
164 case XmlSignature
.AlgorithmNamespaces
.XmlDecryptionTransform
:
165 t
= new XmlDecryptionTransform ();
172 t
.LoadInnerXml (((XmlElement
) xn
).ChildNodes
);
173 TransformChain
.Add (t
);
179 if (value.HasAttribute (XmlEncryption
.AttributeNames
.URI
))
180 Uri
= value.Attributes
[XmlEncryption
.AttributeNames
.URI
].Value
;
184 #endregion // Methods