2004-02-07 Tim Coleman <tim@timcoleman.com>
authorTim Coleman <tim@mono-cvs.ximian.com>
Sat, 7 Feb 2004 05:02:23 +0000 (05:02 -0000)
committerTim Coleman <tim@mono-cvs.ximian.com>
Sat, 7 Feb 2004 05:02:23 +0000 (05:02 -0000)
        * CipherData.cs CipherReference.cs EncryptedData.cs
        * EncryptedReference.cs EncryptedType.cs EncryptionMethod.cs
        * EncryptionProperties.cs EncryptionProperty.cs XmlEncryption.cs:
                New classes added for Xml Encryption in 1.2
        * KeyInfoRetrievalMethod.cs:
                Added Type attribute for 1.2
        * XmlSignature.cs:
                Added string constants for algorithm namespaces

svn path=/trunk/mcs/; revision=22849

12 files changed:
mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
mcs/class/System.Security/System.Security.Cryptography.Xml/CipherData.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/CipherReference.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedData.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedType.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionMethod.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperties.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperty.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfoRetrievalMethod.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlEncryption.cs [new file with mode: 0644]
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs

index 63f91adbdd2891cfc55bf74bec150c6fa5923feb..fb4c04d0c6005c59cb07a3cb399bc1c16e1cc635 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-07  Tim Coleman <tim@timcoleman.com>
+       * CipherData.cs CipherReference.cs EncryptedData.cs
+       * EncryptedReference.cs EncryptedType.cs EncryptionMethod.cs
+       * EncryptionProperties.cs EncryptionProperty.cs XmlEncryption.cs:
+               New classes added for Xml Encryption in 1.2
+       * KeyInfoRetrievalMethod.cs:
+               Added Type attribute for 1.2
+       * XmlSignature.cs:
+               Added string constants for algorithm namespaces
+
 2004-01-11  Sebastien Pouliot  <spouliot@videotron.ca>
 
        * SignedXml.cs: Fixed class signature (for 1.1+) by adding public to 
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/CipherData.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/CipherData.cs
new file mode 100644 (file)
index 0000000..de46102
--- /dev/null
@@ -0,0 +1,127 @@
+//
+// CipherData.cs - CipherData implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-CipherData
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Security.Cryptography;
+using System.IO;
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public sealed class CipherData {
+
+               #region Fields
+
+               byte[] cipherValue;
+               CipherReference cipherReference;
+       
+               #endregion // Fields
+       
+               #region Constructors
+       
+               public CipherData ()
+               {
+               }
+       
+               public CipherData (byte[] cipherValue)
+               {
+                       CipherValue = cipherValue;
+               }
+       
+               public CipherData (CipherReference cipherReference)
+               {
+                       CipherReference = cipherReference;
+               }
+       
+               #endregion // Constructors
+       
+               #region Properties
+       
+               public CipherReference CipherReference {
+                       get { return cipherReference; }
+                       set { 
+                               if (CipherValue != null)
+                                       throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+                               cipherReference = value;
+                       }
+               }
+       
+               public byte[] CipherValue {
+                       get { return cipherValue; }
+                       set {
+                               if (CipherReference != null)
+                                       throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+                               cipherValue = value;
+                       }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal XmlElement GetXml (XmlDocument document)
+               {
+                       if (CipherReference == null && CipherValue == null)
+                               throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+
+                       XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.CipherData, XmlEncryption.NamespaceURI);
+                       if (CipherReference != null) 
+                               xel.AppendChild (document.ImportNode (cipherReference.GetXml (), true));
+
+                       if (CipherValue != null) {
+                               XmlElement xcv = document.CreateElement (XmlEncryption.ElementNames.CipherValue, XmlEncryption.NamespaceURI);
+                               StreamReader reader = new StreamReader (new CryptoStream (new MemoryStream (cipherValue), new ToBase64Transform (), CryptoStreamMode.Read));
+                               xcv.InnerText = reader.ReadToEnd ();
+                               reader.Close ();
+                               xel.AppendChild (xcv);
+                       }
+                       return xel;
+               }
+
+               public void LoadXml (XmlElement value)
+               {
+                       CipherReference = null;
+                       CipherValue = null;
+
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+
+                       if ((value.LocalName != XmlEncryption.ElementNames.CipherData) || (value.NamespaceURI != XmlEncryption.NamespaceURI)) 
+                               throw new CryptographicException ("Malformed Cipher Data element.");
+                       else {
+                               foreach (XmlNode n in value.ChildNodes) {
+                                       if (n is XmlWhitespace)
+                                               continue;
+
+                                       switch (n.LocalName) {
+                                       case XmlEncryption.ElementNames.CipherReference:
+                                               cipherReference = new CipherReference ();
+                                               cipherReference.LoadXml ((XmlElement) n);
+                                               break;
+                                       case XmlEncryption.ElementNames.CipherValue:
+                                               CipherValue = Convert.FromBase64String (n.InnerText);
+                                               break;
+                                       }
+                               }
+
+                               if (CipherReference == null && CipherValue == null)
+                                       throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+                       }
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/CipherReference.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/CipherReference.cs
new file mode 100644 (file)
index 0000000..2d65594
--- /dev/null
@@ -0,0 +1,116 @@
+//
+// CipherReference.cs - CipherReference implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-CipherReference
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public sealed class CipherReference : EncryptedReference {
+
+               #region Constructors
+       
+               public CipherReference ()
+                       : base ()
+               {
+               }
+       
+               public CipherReference (string uri)
+                       : base (uri)
+               {
+               }
+       
+               public CipherReference (string uri, TransformChain tc)
+                       : base (uri, tc)
+               {
+               }
+       
+               #endregion // Constructors
+       
+               #region Methods
+
+               public override XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal override XmlElement GetXml (XmlDocument document)
+               {
+                       XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.CipherReference, XmlEncryption.NamespaceURI);
+
+                       xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
+
+                       if (TransformChain != null && TransformChain.Count > 0) {
+                               XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, XmlEncryption.NamespaceURI);
+                               foreach (Transform t in TransformChain) 
+                                       xtr.AppendChild (document.ImportNode (t.GetXml (), true));
+                               xel.AppendChild (xtr);
+                       }
+
+                       return xel;
+               }
+
+               public override void LoadXml (XmlElement value)
+               {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+                       if ((value.LocalName != XmlEncryption.ElementNames.CipherReference) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+                               throw new CryptographicException ("Malformed CipherReference element.");
+                       else {
+                               Uri = null;
+                               TransformChain = new TransformChain ();
+
+                               foreach (XmlNode n in value.ChildNodes) {
+                                       if (n is XmlWhitespace)
+                                               continue;
+
+                                       switch (n.LocalName) {
+                                       case XmlEncryption.ElementNames.Transforms:
+                                               foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
+                                                       Transform t = null;
+                                                       switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
+                                                               t = new XmlDsigBase64Transform ();
+                                                               break;
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
+                                                               t = new XmlDsigC14NTransform ();
+                                                               break;
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
+                                                               t = new XmlDsigC14NWithCommentsTransform ();
+                                                               break;
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
+                                                               t = new XmlDsigEnvelopedSignatureTransform ();
+                                                               break;
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
+                                                               t = new XmlDsigXPathTransform ();
+                                                               break;
+                                                       case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
+                                                               t = new XmlDsigXsltTransform ();
+                                                               break;
+                                                       default:
+                                                               continue;
+                                                       }
+
+                                                       t.LoadInnerXml (((XmlElement) xn).ChildNodes);
+                                                       TransformChain.Add (t);
+                                               }
+                                               break;
+                                       }
+                               }
+                                               
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.URI))
+                                       Uri = value.Attributes [XmlEncryption.AttributeNames.URI].Value;
+                       }
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedData.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedData.cs
new file mode 100644 (file)
index 0000000..40d1bf1
--- /dev/null
@@ -0,0 +1,122 @@
+//
+// EncryptedData.cs - EncryptedData implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedData
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public sealed class EncryptedData : EncryptedType {
+
+               #region Constructors
+
+               public EncryptedData ()
+                       : base ()
+               {
+               }
+
+               #endregion // Constructors
+
+               #region Methods
+
+               public override XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal XmlElement GetXml (XmlDocument document)
+               {
+                       if (CipherData == null)
+                               throw new CryptographicException ("Cipher data is not specified.");
+
+                       XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptedData, XmlEncryption.NamespaceURI);
+
+                       if (EncryptionMethod != null)
+                               xel.AppendChild (EncryptionMethod.GetXml (document));
+                       if (KeyInfo != null) 
+                               xel.AppendChild (document.ImportNode (KeyInfo.GetXml (), true));
+                       if (CipherData != null)
+                               xel.AppendChild (CipherData.GetXml (document));
+
+                       if (EncryptionProperties.Count > 0) {
+                               XmlElement xep = document.CreateElement (XmlEncryption.ElementNames.EncryptionProperties, XmlEncryption.NamespaceURI);
+                               foreach (EncryptionProperty p in EncryptionProperties)
+                                       xep.AppendChild (p.GetXml (document));
+                               xel.AppendChild (xep);
+                       }
+
+                       if (Id != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Id, Id);
+                       if (Type != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Type, Type);
+                       if (MimeType != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.MimeType, MimeType);
+                       if (Encoding != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Encoding, Encoding);
+                       return xel;
+               }
+
+               public override void LoadXml (XmlElement value)
+               {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+
+                       if ((value.LocalName != XmlEncryption.ElementNames.EncryptedData) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+                               throw new CryptographicException ("Malformed EncryptedData element.");
+                       else {
+                               EncryptionMethod = null;
+                               KeyInfo keyInfo = null;
+                               CipherData cipherData = null;
+                               EncryptionMethod = null;
+                               EncryptionProperties = new EncryptionProperties ();
+                               Id = null;
+                               Type = null;
+                               MimeType = null;
+                               Encoding = null;
+
+                               foreach (XmlNode n in value.ChildNodes) {
+                                       if (n is XmlWhitespace)
+                                               continue;
+
+                                       switch (n.LocalName) {
+                                       case XmlEncryption.ElementNames.EncryptionMethod:
+                                               EncryptionMethod = new EncryptionMethod ();
+                                               EncryptionMethod.LoadXml ((XmlElement) n);
+                                               break;
+                                       case XmlSignature.ElementNames.KeyInfo:
+                                               KeyInfo = new KeyInfo ();
+                                               KeyInfo.LoadXml ((XmlElement) n);
+                                               break;
+                                       case XmlEncryption.ElementNames.CipherData:
+                                               CipherData = new CipherData ();
+                                               CipherData.LoadXml ((XmlElement) n);
+                                               break;
+                                       case XmlEncryption.ElementNames.EncryptionProperties:
+                                               foreach (XmlElement element in ((XmlElement) n).GetElementsByTagName (XmlEncryption.ElementNames.EncryptionProperty, XmlEncryption.NamespaceURI))
+                                                       EncryptionProperties.Add (new EncryptionProperty (element));
+                                               break;
+                                       }
+                               }
+
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Id))
+                                       Id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Type))
+                                       Type = value.Attributes [XmlEncryption.AttributeNames.Type].Value;
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.MimeType))
+                                       MimeType = value.Attributes [XmlEncryption.AttributeNames.MimeType].Value;
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Encoding))
+                                       Encoding = value.Attributes [XmlEncryption.AttributeNames.Encoding].Value;
+                       }
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs
new file mode 100644 (file)
index 0000000..b248fe0
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// EncryptedReference.cs - EncryptedReference implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedReference
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public abstract class EncryptedReference {
+
+               #region Fields
+
+               bool cacheValid;
+               string referenceType;
+               string uri;
+               TransformChain tc;
+
+               #endregion // Fields
+
+               #region Constructors
+
+               protected EncryptedReference ()
+               {
+                       uri = null;
+                       TransformChain = new TransformChain ();
+               }
+       
+               protected EncryptedReference (string uri)
+               {
+                       Uri = uri;
+                       TransformChain = new TransformChain ();
+               }
+       
+               protected EncryptedReference (string uri, TransformChain tc)
+                       : this ()
+               {
+                       Uri = uri;
+                       TransformChain = tc;
+               }
+       
+               #endregion // Constructors
+
+               #region Properties
+
+               [MonoTODO()]
+               protected internal bool CacheValid {
+                       get { return cacheValid; }
+               }
+
+               [MonoTODO]
+               protected string ReferenceType {
+                       get { return referenceType; }
+               }
+
+               public TransformChain TransformChain {
+                       get { return tc; }
+                       set { tc = value; }
+               }
+
+               public string Uri {
+                       get { return uri; }
+                       set { uri = value; }
+               }
+
+               #endregion // Properties
+       
+               #region Methods
+
+               public void AddTransform (Transform transform)
+               {
+                       TransformChain.Add (transform);
+               }
+
+               public virtual XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal virtual XmlElement GetXml (XmlDocument document)
+               {
+                       return document.CreateElement ("", "");
+               }
+
+               public virtual void LoadXml (XmlElement value)
+               {
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedType.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedType.cs
new file mode 100644 (file)
index 0000000..1f5085d
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// EncryptedType.cs - EncryptedType implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedType
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public abstract class EncryptedType {
+
+               #region Fields
+
+               CipherData cipherData;
+               string encoding;
+               EncryptionMethod encryptionMethod;
+               EncryptionProperties encryptionProperties;
+               string id;
+               KeyInfo keyInfo;
+               string mimeType;
+               string type;
+       
+               #endregion // Fields
+       
+               #region Constructors
+
+               protected EncryptedType ()
+               {
+                       cipherData = null;
+                       encoding = null;
+                       encryptionMethod = null;
+                       encryptionProperties = new EncryptionProperties ();
+                       id = null;
+                       keyInfo = null;
+                       mimeType = null;
+                       type = null;
+               }
+       
+               #endregion // Constructors
+       
+               #region Properties
+
+               public virtual CipherData CipherData {
+                       get { return cipherData; }
+                       set { cipherData = value; }
+               }
+
+               public virtual string Encoding {
+                       get { return encoding; }
+                       set { encoding = value; }
+               }
+
+               public virtual EncryptionMethod EncryptionMethod {
+                       get { return encryptionMethod; }
+                       set { encryptionMethod = value; }
+               }
+
+               public virtual EncryptionProperties EncryptionProperties {
+                       get { return encryptionProperties; }
+                       set { encryptionProperties = value; }
+               }
+
+               public virtual string Id {
+                       get { return id; }
+                       set { id = value; }
+               }
+
+               public KeyInfo KeyInfo {
+                       get { return keyInfo; }
+                       set { keyInfo = value; }
+               }
+
+               public virtual string MimeType {
+                       get { return mimeType; }
+                       set { mimeType = value; }
+               }
+
+               public virtual string Type {
+                       get { return type; }
+                       set { type = value; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public void AddProperty (EncryptionProperty ep)
+               {
+                       EncryptionProperties.Add (ep);
+               }
+
+               public abstract XmlElement GetXml ();
+               public abstract void LoadXml (XmlElement value);
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionMethod.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionMethod.cs
new file mode 100644 (file)
index 0000000..8831792
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// EncryptionMethod.cs - EncryptionMethod implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionMethod
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public class EncryptionMethod {
+
+               #region Fields
+
+               string algorithm;
+               int keySize;
+
+               #endregion // Fields
+       
+               #region Constructors
+
+               public EncryptionMethod ()
+               {
+                       KeyAlgorithm = null;
+               }
+
+               public EncryptionMethod (string strAlgorithm)
+               {
+                       KeyAlgorithm = strAlgorithm;
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public string KeyAlgorithm {
+                       get { return algorithm; }
+                       set { algorithm = value; }
+               }
+
+               public int KeySize {
+                       get { return keySize; }
+                       set {
+                               if (value <= 0)
+                                       throw new ArgumentOutOfRangeException ("The key size should be a non negative integer.");
+                               keySize = value; 
+                       }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal XmlElement GetXml (XmlDocument document)
+               {
+                       XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionMethod, XmlEncryption.NamespaceURI);
+
+                       if (KeySize != 0) {
+                               XmlElement xks = document.CreateElement (XmlEncryption.ElementNames.KeySize, XmlEncryption.NamespaceURI);
+                               xks.InnerText = String.Format ("{0}", keySize);
+                               xel.AppendChild (xks);
+                       }
+
+                       if (KeyAlgorithm != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Algorithm, KeyAlgorithm);
+                       return xel;
+               }
+
+               public void LoadXml (XmlElement value)
+               {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+                       if ((value.LocalName != XmlEncryption.ElementNames.EncryptionMethod) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+                               throw new CryptographicException ("Malformed EncryptionMethod element.");
+                       else {
+                               KeyAlgorithm = null;
+                               foreach (XmlNode n in value.ChildNodes) {
+                                       if (n is XmlWhitespace)
+                                               continue;
+                                       switch (n.LocalName) {
+                                       case XmlEncryption.ElementNames.KeySize:
+                                               KeySize = Int32.Parse (n.InnerText);
+                                               break;
+                                       }
+                               }
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Algorithm))
+                                       KeyAlgorithm = value.Attributes [XmlEncryption.AttributeNames.Algorithm].Value;
+                       }
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperties.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperties.cs
new file mode 100644 (file)
index 0000000..6ab37b2
--- /dev/null
@@ -0,0 +1,153 @@
+//
+// EncryptionProperties.cs - EncryptionProperties implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionProperties
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Collections;
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public sealed class EncryptionProperties : IList, ICollection, IEnumerable {
+
+               #region Fields
+               
+               ArrayList list;
+
+               #endregion // Fields
+       
+               #region Constructors
+
+               public EncryptionProperties ()
+               {
+                       list = new ArrayList ();
+               }
+       
+               #endregion // Constructors
+       
+               #region Properties
+
+               public int Count {
+                       get { return list.Count; }
+               }
+
+               public bool IsFixedSize {
+                       get { return list.IsFixedSize; }
+               }
+
+               public bool IsReadOnly {
+                       get { return list.IsReadOnly; }
+               }
+
+               public bool IsSynchronized {
+                       get { return list.IsSynchronized; }
+               }
+
+               object IList.this [int index] {
+                       get { return this [index]; }
+                       set { this [index] = (EncryptionProperty) value; }
+               }
+
+               public EncryptionProperty this [int index] {
+                       get { return (EncryptionProperty) list [index]; }
+                       set { list [index] = value; }
+               }
+
+               public object SyncRoot {
+                       get { return list.SyncRoot; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public int Add (EncryptionProperty value)
+               {
+                       return list.Add (value);
+               }
+
+               public void Clear ()
+               {
+                       list.Clear ();
+               }
+
+               public bool Contains (EncryptionProperty value)
+               {
+                       return list.Contains (value);
+               }
+
+               public void CopyTo (Array array, int index)
+               {
+                       list.CopyTo (array, index);
+               }
+
+               public void CopyTo (EncryptionProperty[] array, int index)
+               {
+                       list.CopyTo (array, index);
+               }
+
+               public IEnumerator GetEnumerator ()
+               {
+                       return list.GetEnumerator ();
+               }
+
+               bool IList.Contains (object value)
+               {
+                       return Contains ((EncryptionProperty) value);
+               }
+
+               int IList.Add (object value)
+               {
+                       return Add ((EncryptionProperty) value);
+               }
+
+               int IList.IndexOf (object value)
+               {
+                       return IndexOf ((EncryptionProperty) value);
+               }
+
+               void IList.Insert (int index, object value)
+               {
+                       Insert (index, (EncryptionProperty) value);
+               }
+
+               void IList.Remove (object value)
+               {
+                       Remove ((EncryptionProperty) value);
+               }
+
+               public int IndexOf (EncryptionProperty value)
+               {
+                       return list.IndexOf (value);
+               }
+
+               public void Insert (int index, EncryptionProperty value)
+               {
+                       list.Insert (index, value);
+               }
+
+               public EncryptionProperty Item (int index)
+               {
+                       return (EncryptionProperty) list [index];
+               }
+
+               public void Remove (EncryptionProperty value)
+               {
+                       list.Remove (value);
+               }
+
+               public void RemoveAt (int index)
+               {
+                       list.RemoveAt (index);
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperty.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptionProperty.cs
new file mode 100644 (file)
index 0000000..863e776
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// EncryptionProperty.cs - EncryptionProperty implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionProperty
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+       public sealed class EncryptionProperty {
+
+               #region Fields
+
+               XmlElement elemProp;
+               string id;
+               string target;
+
+               #endregion // Fields
+       
+               #region Constructors
+
+               public EncryptionProperty ()
+               {
+               }
+
+               public EncryptionProperty (XmlElement elemProp)
+               {
+                       LoadXml (elemProp);
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public string Id {
+                       get { return id; }
+               }
+
+               public XmlElement PropertyElement {
+                       get { return elemProp; }
+                       set { LoadXml (value); }
+               }
+
+               public string Target {
+                       get { return target; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public XmlElement GetXml ()
+               {
+                       return GetXml (new XmlDocument ());
+               }
+
+               internal XmlElement GetXml (XmlDocument document)
+               {
+                       XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionProperty, XmlEncryption.NamespaceURI);
+
+                       if (Id != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Id, Id);
+                       if (Target != null)
+                               xel.SetAttribute (XmlEncryption.AttributeNames.Target, Target);
+
+                       return xel;
+               }
+
+               public void LoadXml (XmlElement value)
+               {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+
+                       if ((value.LocalName != XmlEncryption.ElementNames.EncryptionProperty) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+                               throw new CryptographicException ("Malformed EncryptionProperty element.");
+                       else {  
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Id))
+                                       this.id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
+                               if (value.HasAttribute (XmlEncryption.AttributeNames.Target))
+                                       this.target = value.Attributes [XmlEncryption.AttributeNames.Target].Value;
+                       }
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif
index 2a891e143c047119e43652a7e6f2d0bf5a902e4e..e7712edd738e73006f56ce75d2c16e7981d422b9 100644 (file)
@@ -3,8 +3,10 @@
 //
 // Author:
 //     Sebastien Pouliot (spouliot@motus.com)
+//      Tim Coleman (tim@timcoleman.com)
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) Tim Coleman, 2004
 //
 
 using System.Xml;
@@ -15,6 +17,10 @@ namespace System.Security.Cryptography.Xml {
 
                private string URI;
 
+#if NET_1_2
+               string type;
+#endif
+
                public KeyInfoRetrievalMethod () {}
 
                public KeyInfoRetrievalMethod (string strUri) 
@@ -22,17 +28,35 @@ namespace System.Security.Cryptography.Xml {
                        URI = strUri;
                }
 
+#if NET_1_2
+               public KeyInfoRetrievalMethod (string strUri, string strType)
+                       : this (strUri)
+               {
+                       Type = strType;
+               }
+
+               public string Type {
+                       get { return type; }
+                       set { type = value; }
+               }
+#endif
+
                public string Uri {
                        get { return URI; }
                        set { URI = value; }
                }
 
+
                public override XmlElement GetXml () 
                {
                        XmlDocument document = new XmlDocument ();
                        XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
                        if (URI != null)
                                xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
+#if NET_1_2
+                       if (Type != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.Type, Type);
+#endif
                        return xel;
                }
 
@@ -41,10 +65,15 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ();
 
-                       if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI))
+                       if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
                                URI = ""; // not null - so we return URI="" as attribute !!!
-                       else
+                       } else {
                                URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
+#if NET_1_2
+                               if (value.HasAttribute (XmlSignature.AttributeNames.Type))
+                                       Type = value.Attributes [XmlSignature.AttributeNames.Type].Value;
+#endif
+                       }
                }
        }
-}
\ No newline at end of file
+}
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlEncryption.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlEncryption.cs
new file mode 100644 (file)
index 0000000..2dfa249
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// XmlEncryption.cs: Handles Xml Encryption
+//
+// Author:
+//      Tim Coleman (tim@timcoleman.com)
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) Tim Coleman, 2004
+//
+
+#if NET_1_2
+
+using System;
+
+namespace System.Security.Cryptography.Xml {
+
+       // following the design of WSE
+       internal class XmlEncryption {
+
+               public class ElementNames {
+
+                       public const string CipherData = "CipherData";
+                       public const string CipherReference = "CipherReference";
+                       public const string CipherValue = "CipherValue";
+                       public const string EncryptedData = "EncryptedData";
+                       public const string EncryptionMethod = "EncryptionMethod";
+                       public const string EncryptionProperties = "EncryptionProperties";
+                       public const string EncryptionProperty = "EncryptionProperty";
+                       public const string KeySize = "KeySize";
+                       public const string Transforms = "Transforms";
+
+                       public ElementNames () {}
+               }
+
+               public class AttributeNames {
+
+                       public const string Algorithm = "Algorithm";
+                       public const string Encoding = "Encoding";
+                       public const string Id = "Id";
+                       public const string MimeType = "MimeType";
+                       public const string Target = "Target";
+                       public const string Type = "Type";
+                       public const string URI = "URI";
+
+                       public AttributeNames () {}
+               }
+
+               public const string NamespaceURI = "http://www.w3.org/2001/04/xmlenc#";
+               public const string Prefix = "xenc";
+
+               public XmlEncryption () {}
+       }
+}
+
+#endif
index 199b7813bf7a11e850a0856fbd8e413a4bc99a11..208766bb01c3ce553c8ac43268233753a00dea19 100644 (file)
@@ -63,6 +63,15 @@ namespace System.Security.Cryptography.Xml {
                        public AttributeNames () {}
                }
 
+               public class AlgorithmNamespaces {
+                       public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64";
+                       public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
+                       public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
+                       public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
+                       public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+                       public const string XmlDsigXsltTransform =  "http://www.w3.org/TR/1999/REC-xslt-19991116";
+               }
+
                public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
                public const string Prefix = "ds";