You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.47
Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
parent
88ff76fe28
commit
e46a49ecf1
@@ -28,6 +28,10 @@ EXTRA_DISTFILES = \
|
||||
|
||||
RESX_RESOURCE_STRING = ../../../external/corefx/src/System.Security.Cryptography.Xml/src/Resources/Strings.resx
|
||||
|
||||
ifdef MOBILE_PROFILE
|
||||
NO_TEST = yes
|
||||
endif
|
||||
|
||||
include ../../build/library.make
|
||||
|
||||
$(build_lib): $(secxml_libdir)/System.dll $(MONO_SECURITY_DLL)
|
||||
|
@@ -1,146 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
if (CipherReference != null)
|
||||
xel.AppendChild (document.ImportNode (cipherReference.GetXml (), true));
|
||||
|
||||
if (CipherValue != null) {
|
||||
XmlElement xcv = document.CreateElement (XmlEncryption.ElementNames.CipherValue, EncryptedXml.XmlEncNamespaceUrl);
|
||||
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 != EncryptedXml.XmlEncNamespaceUrl))
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
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 transformChain)
|
||||
: base (uri, transformChain)
|
||||
{
|
||||
}
|
||||
|
||||
#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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
|
||||
|
||||
if (TransformChain != null && TransformChain.Count > 0) {
|
||||
XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, EncryptedXml.XmlEncNamespaceUrl);
|
||||
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 != EncryptedXml.XmlEncNamespaceUrl))
|
||||
throw new CryptographicException ("Malformed CipherReference element.");
|
||||
base.LoadXml (value);
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
|
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// DSAKeyValue.cs - DSA KeyValue implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class DSAKeyValue : KeyInfoClause {
|
||||
|
||||
private DSA dsa;
|
||||
|
||||
public DSAKeyValue ()
|
||||
{
|
||||
dsa = (DSA)DSA.Create ();
|
||||
}
|
||||
|
||||
public DSAKeyValue (DSA key)
|
||||
{
|
||||
dsa = key;
|
||||
}
|
||||
|
||||
public DSA Key
|
||||
{
|
||||
get { return dsa; }
|
||||
set { dsa = value; }
|
||||
}
|
||||
|
||||
public override XmlElement GetXml ()
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
|
||||
xel.SetAttribute ("xmlns", XmlSignature.NamespaceURI);
|
||||
xel.InnerXml = dsa.ToXmlString (false);
|
||||
return xel;
|
||||
}
|
||||
|
||||
public override void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || (value.NamespaceURI != XmlSignature.NamespaceURI))
|
||||
throw new CryptographicException ("value");
|
||||
|
||||
dsa.FromXmlString (value.InnerXml);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,168 +0,0 @@
|
||||
//
|
||||
// DataObject.cs - DataObject implementation for XML Signature
|
||||
// http://www.w3.org/2000/09/xmldsig#Object
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Atsushi Enomoto (atsushi@ximian.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
// XmlElement part of the signature
|
||||
// Note: Looks like KeyInfoNode (but the later is XmlElement inside KeyInfo)
|
||||
// required for "enveloping signatures"
|
||||
public class DataObject {
|
||||
|
||||
private XmlElement element;
|
||||
private bool propertyModified;
|
||||
|
||||
public DataObject ()
|
||||
{
|
||||
Build (null, null, null, null);
|
||||
}
|
||||
|
||||
public DataObject (string id, string mimeType, string encoding, XmlElement data)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException ("data");
|
||||
|
||||
Build (id, mimeType, encoding, data);
|
||||
}
|
||||
|
||||
// this one accept a null "data" parameter
|
||||
private void Build (string id, string mimeType, string encoding, XmlElement data)
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Object, XmlSignature.NamespaceURI);
|
||||
if (id != null) {
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
|
||||
}
|
||||
if (mimeType != null) {
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.MimeType, mimeType);
|
||||
}
|
||||
if (encoding != null) {
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.Encoding, encoding);
|
||||
}
|
||||
if (data != null) {
|
||||
XmlNode newNode = document.ImportNode (data, true);
|
||||
xel.AppendChild (newNode);
|
||||
}
|
||||
element = xel;
|
||||
}
|
||||
|
||||
// why is data a XmlNodeList instead of a XmlElement ?
|
||||
public XmlNodeList Data {
|
||||
get {
|
||||
return element.ChildNodes;
|
||||
}
|
||||
set {
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
XmlElement el = (XmlElement) doc.ImportNode (element, true);
|
||||
while (el.LastChild != null)
|
||||
el.RemoveChild (el.LastChild);
|
||||
foreach (XmlNode n in value)
|
||||
el.AppendChild (doc.ImportNode (n, true));
|
||||
element = el;
|
||||
propertyModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// default to null - no encoding
|
||||
public string Encoding {
|
||||
get { return GetField (XmlSignature.AttributeNames.Encoding); }
|
||||
set { SetField (XmlSignature.AttributeNames.Encoding, value); }
|
||||
}
|
||||
|
||||
// default to null
|
||||
public string Id {
|
||||
get { return GetField (XmlSignature.AttributeNames.Id); }
|
||||
set { SetField (XmlSignature.AttributeNames.Id, value); }
|
||||
}
|
||||
|
||||
// default to null
|
||||
public string MimeType {
|
||||
get { return GetField (XmlSignature.AttributeNames.MimeType); }
|
||||
set { SetField (XmlSignature.AttributeNames.MimeType, value); }
|
||||
}
|
||||
|
||||
private string GetField (string attribute)
|
||||
{
|
||||
XmlNode attr = element.Attributes [attribute];
|
||||
return attr != null ? attr.Value : null;
|
||||
}
|
||||
|
||||
private void SetField (string attribute, string value)
|
||||
{
|
||||
// MS-BUGS: it never cleans attribute value up.
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
if (propertyModified)
|
||||
element.SetAttribute (attribute, value);
|
||||
else {
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement el = document.ImportNode (element, true) as XmlElement;
|
||||
el.SetAttribute (attribute, value);
|
||||
element = el;
|
||||
propertyModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
if (propertyModified) {
|
||||
// It looks MS.NET returns element which comes from new XmlDocument every time
|
||||
XmlElement oldElement = element;
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
element = doc.CreateElement (XmlSignature.ElementNames.Object, XmlSignature.NamespaceURI);
|
||||
foreach (XmlAttribute attribute in oldElement.Attributes) {
|
||||
switch (attribute.Name) {
|
||||
case XmlSignature.AttributeNames.Id:
|
||||
case XmlSignature.AttributeNames.Encoding:
|
||||
case XmlSignature.AttributeNames.MimeType:
|
||||
element.SetAttribute (attribute.Name, attribute.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (XmlNode n in oldElement.ChildNodes)
|
||||
element.AppendChild (doc.ImportNode (n, true));
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
element = value;
|
||||
propertyModified = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
//
|
||||
// DataReference.cs - DataReference implementation for XML Encryption
|
||||
// http://www.w3.org/2001/04/xmlenc#sec-ReferenceList
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public sealed class DataReference : EncryptedReference {
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DataReference ()
|
||||
: base ()
|
||||
{
|
||||
ReferenceType = XmlEncryption.ElementNames.DataReference;
|
||||
}
|
||||
|
||||
public DataReference (string uri)
|
||||
: base (uri)
|
||||
{
|
||||
ReferenceType = XmlEncryption.ElementNames.DataReference;
|
||||
}
|
||||
|
||||
public DataReference (string uri, TransformChain transformChain)
|
||||
: base (uri, transformChain)
|
||||
{
|
||||
ReferenceType = XmlEncryption.ElementNames.DataReference;
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
}
|
||||
}
|
||||
|
@@ -1,140 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public sealed class EncryptedData : EncryptedType {
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EncryptedData ()
|
||||
{
|
||||
}
|
||||
|
||||
#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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
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 != EncryptedXml.XmlEncNamespaceUrl))
|
||||
throw new CryptographicException ("Malformed EncryptedData element.");
|
||||
else {
|
||||
EncryptionMethod = null;
|
||||
EncryptionMethod = null;
|
||||
EncryptionProperties.Clear ();
|
||||
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, EncryptedXml.XmlEncNamespaceUrl))
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,217 +0,0 @@
|
||||
//
|
||||
// EncryptedKey.cs - EncryptedKey implementation for XML Encryption
|
||||
// http://www.w3.org/2001/04/xmlenc#sec-EncryptedKey
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public sealed class EncryptedKey : EncryptedType {
|
||||
|
||||
#region Fields
|
||||
|
||||
string carriedKeyName;
|
||||
string recipient;
|
||||
ReferenceList referenceList;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EncryptedKey ()
|
||||
{
|
||||
referenceList = new ReferenceList ();
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
public string CarriedKeyName {
|
||||
get { return carriedKeyName; }
|
||||
set { carriedKeyName = value; }
|
||||
}
|
||||
|
||||
public string Recipient {
|
||||
get { return recipient; }
|
||||
set { recipient = value; }
|
||||
}
|
||||
|
||||
public ReferenceList ReferenceList {
|
||||
get { return referenceList; }
|
||||
}
|
||||
|
||||
#endregion // Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
public void AddReference (DataReference dataReference)
|
||||
{
|
||||
ReferenceList.Add (dataReference);
|
||||
}
|
||||
|
||||
public void AddReference (KeyReference keyReference)
|
||||
{
|
||||
ReferenceList.Add (keyReference);
|
||||
}
|
||||
|
||||
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.EncryptedKey, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
foreach (EncryptionProperty p in EncryptionProperties)
|
||||
xep.AppendChild (p.GetXml (document));
|
||||
xel.AppendChild (xep);
|
||||
}
|
||||
|
||||
if (ReferenceList.Count > 0) {
|
||||
XmlElement xrl = document.CreateElement (XmlEncryption.ElementNames.ReferenceList, EncryptedXml.XmlEncNamespaceUrl);
|
||||
foreach (EncryptedReference er in ReferenceList)
|
||||
xrl.AppendChild (er.GetXml (document));
|
||||
xel.AppendChild (xrl);
|
||||
}
|
||||
|
||||
if (CarriedKeyName != null) {
|
||||
XmlElement xck = document.CreateElement (XmlEncryption.ElementNames.CarriedKeyName, EncryptedXml.XmlEncNamespaceUrl);
|
||||
xck.InnerText = CarriedKeyName;
|
||||
xel.AppendChild (xck);
|
||||
}
|
||||
|
||||
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);
|
||||
if (Recipient != null)
|
||||
xel.SetAttribute (XmlEncryption.AttributeNames.Recipient, Recipient);
|
||||
return xel;
|
||||
}
|
||||
|
||||
public override void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
|
||||
if ((value.LocalName != XmlEncryption.ElementNames.EncryptedKey) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
|
||||
throw new CryptographicException ("Malformed EncryptedKey element.");
|
||||
else {
|
||||
EncryptionMethod = null;
|
||||
EncryptionMethod = null;
|
||||
EncryptionProperties.Clear ();
|
||||
ReferenceList.Clear ();
|
||||
CarriedKeyName = null;
|
||||
Id = null;
|
||||
Type = null;
|
||||
MimeType = null;
|
||||
Encoding = null;
|
||||
Recipient = 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, EncryptedXml.XmlEncNamespaceUrl))
|
||||
EncryptionProperties.Add (new EncryptionProperty (element));
|
||||
break;
|
||||
case XmlEncryption.ElementNames.ReferenceList:
|
||||
foreach (XmlNode r in ((XmlElement) n).ChildNodes) {
|
||||
if (r is XmlWhitespace)
|
||||
continue;
|
||||
|
||||
switch (r.LocalName) {
|
||||
case XmlEncryption.ElementNames.DataReference:
|
||||
DataReference dr = new DataReference ();
|
||||
dr.LoadXml ((XmlElement) r);
|
||||
AddReference (dr);
|
||||
break;
|
||||
case XmlEncryption.ElementNames.KeyReference:
|
||||
KeyReference kr = new KeyReference ();
|
||||
kr.LoadXml ((XmlElement) r);
|
||||
AddReference (kr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XmlEncryption.ElementNames.CarriedKeyName:
|
||||
CarriedKeyName = ((XmlElement) n).InnerText;
|
||||
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;
|
||||
if (value.HasAttribute (XmlEncryption.AttributeNames.Recipient))
|
||||
Encoding = value.Attributes [XmlEncryption.AttributeNames.Recipient].Value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
|
@@ -1,183 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public abstract class EncryptedReference {
|
||||
|
||||
#region Fields
|
||||
|
||||
string referenceType;
|
||||
string uri;
|
||||
TransformChain tc;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected EncryptedReference ()
|
||||
{
|
||||
TransformChain = new TransformChain ();
|
||||
}
|
||||
|
||||
protected EncryptedReference (string uri)
|
||||
{
|
||||
Uri = uri;
|
||||
TransformChain = new TransformChain ();
|
||||
}
|
||||
|
||||
protected EncryptedReference (string uri, TransformChain transformChain)
|
||||
: this ()
|
||||
{
|
||||
Uri = uri;
|
||||
TransformChain = transformChain;
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
[MonoTODO("Always returns false")]
|
||||
protected internal bool CacheValid {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
protected string ReferenceType {
|
||||
get { return referenceType; }
|
||||
set { referenceType = value; }
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
XmlElement xel = document.CreateElement (ReferenceType, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
|
||||
|
||||
if (TransformChain != null && TransformChain.Count > 0) {
|
||||
XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, EncryptedXml.XmlEncNamespaceUrl);
|
||||
foreach (Transform t in TransformChain)
|
||||
xtr.AppendChild (document.ImportNode (t.GetXml (), true));
|
||||
xel.AppendChild (xtr);
|
||||
}
|
||||
|
||||
return xel;
|
||||
}
|
||||
|
||||
[MonoTODO ("Make compliant.")]
|
||||
public virtual void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
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 SignedXml.XmlDsigBase64TransformUrl:
|
||||
t = new XmlDsigBase64Transform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigC14NTransformUrl:
|
||||
t = new XmlDsigC14NTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigC14NWithCommentsTransformUrl:
|
||||
t = new XmlDsigC14NWithCommentsTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigEnvelopedSignatureTransformUrl:
|
||||
t = new XmlDsigEnvelopedSignatureTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigXPathTransformUrl:
|
||||
t = new XmlDsigXPathTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigXsltTransformUrl:
|
||||
t = new XmlDsigXsltTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigExcC14NTransformUrl:
|
||||
t = new XmlDsigExcC14NTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDsigExcC14NWithCommentsTransformUrl:
|
||||
t = new XmlDsigExcC14NWithCommentsTransform ();
|
||||
break;
|
||||
case SignedXml.XmlDecryptionTransformUrl:
|
||||
t = new XmlDecryptionTransform ();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,117 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public abstract class EncryptedType {
|
||||
|
||||
#region Fields
|
||||
|
||||
CipherData cipherData;
|
||||
string encoding;
|
||||
EncryptionMethod encryptionMethod;
|
||||
EncryptionPropertyCollection encryptionProperties;
|
||||
string id;
|
||||
KeyInfo keyInfo;
|
||||
string mimeType;
|
||||
string type;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected EncryptedType ()
|
||||
{
|
||||
cipherData = new CipherData ();
|
||||
encryptionProperties = new EncryptionPropertyCollection ();
|
||||
keyInfo = new KeyInfo ();
|
||||
}
|
||||
|
||||
#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 EncryptionPropertyCollection EncryptionProperties {
|
||||
get { return encryptionProperties; }
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
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 algorithm)
|
||||
{
|
||||
KeyAlgorithm = algorithm;
|
||||
}
|
||||
|
||||
#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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
if (KeySize != 0) {
|
||||
XmlElement xks = document.CreateElement (XmlEncryption.ElementNames.KeySize, EncryptedXml.XmlEncNamespaceUrl);
|
||||
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 != EncryptedXml.XmlEncNamespaceUrl))
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,175 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public sealed class EncryptionPropertyCollection : IList, ICollection, IEnumerable {
|
||||
|
||||
#region Fields
|
||||
|
||||
ArrayList list;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EncryptionPropertyCollection ()
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
[IndexerName ("ItemOf")]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,112 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public sealed class EncryptionProperty {
|
||||
|
||||
#region Fields
|
||||
|
||||
string id;
|
||||
string target;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public EncryptionProperty ()
|
||||
{
|
||||
}
|
||||
|
||||
public EncryptionProperty (XmlElement elementProperty)
|
||||
{
|
||||
LoadXml (elementProperty);
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
}
|
||||
|
||||
[MonoTODO ("Always returns null")]
|
||||
public XmlElement PropertyElement {
|
||||
get { return null; }
|
||||
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, EncryptedXml.XmlEncNamespaceUrl);
|
||||
|
||||
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 != EncryptedXml.XmlEncNamespaceUrl))
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Xml.IRelDecryptor interface
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public interface IRelDecryptor {
|
||||
|
||||
Stream Decrypt (EncryptionMethod encryptionMethod, KeyInfo keyInfo, Stream toDecrypt);
|
||||
}
|
||||
}
|
||||
|
@@ -1,155 +0,0 @@
|
||||
//
|
||||
// KeyInfo.cs - Xml Signature KeyInfo implementation
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class KeyInfo : IEnumerable {
|
||||
|
||||
private ArrayList Info;
|
||||
private string id;
|
||||
|
||||
public KeyInfo()
|
||||
{
|
||||
Info = new ArrayList ();
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get { return Info.Count; }
|
||||
}
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
set { id = value; }
|
||||
}
|
||||
|
||||
public void AddClause (KeyInfoClause clause)
|
||||
{
|
||||
Info.Add (clause);
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator ()
|
||||
{
|
||||
return Info.GetEnumerator ();
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator (Type requestedObjectType)
|
||||
{
|
||||
// Build a new ArrayList...
|
||||
ArrayList TypeList = new ArrayList ();
|
||||
IEnumerator e = Info.GetEnumerator ();
|
||||
while (true) {
|
||||
// ...with all object of specified type...
|
||||
if ((e.Current).GetType().Equals (requestedObjectType))
|
||||
TypeList.Add (e.Current);
|
||||
if (!e.MoveNext ())
|
||||
break;
|
||||
}
|
||||
// ...and return its enumerator
|
||||
return TypeList.GetEnumerator ();
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyInfo, XmlSignature.NamespaceURI);
|
||||
// we add References afterward so we don't end up with extraneous
|
||||
// xmlns="..." in each reference elements.
|
||||
foreach (KeyInfoClause kic in Info) {
|
||||
XmlNode xn = kic.GetXml ();
|
||||
XmlNode newNode = document.ImportNode (xn, true);
|
||||
xel.AppendChild (newNode);
|
||||
}
|
||||
return xel;
|
||||
}
|
||||
|
||||
public void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
|
||||
Id = value.Attributes ["Id"] != null ? value.GetAttribute ("Id") : null;
|
||||
|
||||
if ((value.LocalName == XmlSignature.ElementNames.KeyInfo) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
|
||||
foreach (XmlNode n in value.ChildNodes) {
|
||||
if (n.NodeType != XmlNodeType.Element)
|
||||
continue;
|
||||
|
||||
KeyInfoClause kic = null;
|
||||
|
||||
switch (n.LocalName) {
|
||||
case XmlSignature.ElementNames.KeyValue:
|
||||
XmlNodeList xnl = n.ChildNodes;
|
||||
if (xnl.Count > 0) {
|
||||
// we must now treat the whitespace !
|
||||
foreach (XmlNode m in xnl) {
|
||||
switch (m.LocalName) {
|
||||
case XmlSignature.ElementNames.DSAKeyValue:
|
||||
kic = (KeyInfoClause) new DSAKeyValue ();
|
||||
break;
|
||||
case XmlSignature.ElementNames.RSAKeyValue:
|
||||
kic = (KeyInfoClause) new RSAKeyValue ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XmlSignature.ElementNames.KeyName:
|
||||
kic = (KeyInfoClause) new KeyInfoName ();
|
||||
break;
|
||||
case XmlSignature.ElementNames.RetrievalMethod:
|
||||
kic = (KeyInfoClause) new KeyInfoRetrievalMethod ();
|
||||
break;
|
||||
case XmlSignature.ElementNames.X509Data:
|
||||
kic = (KeyInfoClause) new KeyInfoX509Data ();
|
||||
break;
|
||||
case XmlSignature.ElementNames.RSAKeyValue:
|
||||
kic = (KeyInfoClause) new RSAKeyValue ();
|
||||
break;
|
||||
case XmlSignature.ElementNames.EncryptedKey:
|
||||
kic = (KeyInfoClause) new KeyInfoEncryptedKey ();
|
||||
break;
|
||||
default:
|
||||
kic = (KeyInfoClause) new KeyInfoNode ();
|
||||
break;
|
||||
}
|
||||
|
||||
if (kic != null) {
|
||||
kic.LoadXml ((XmlElement) n);
|
||||
AddClause (kic);
|
||||
}
|
||||
}
|
||||
}
|
||||
// No check is performed on MS.NET...
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// KeyInfoClause.cs - Abstract KeyInfoClause implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) 2006 Novell Inc. (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public abstract class KeyInfoClause {
|
||||
|
||||
protected KeyInfoClause ()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract XmlElement GetXml ();
|
||||
|
||||
public abstract void LoadXml (XmlElement element);
|
||||
}
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
//
|
||||
// KeyInfoEncryptedKey.cs - KeyInfoEncryptedKey implementation for XML Encryption
|
||||
// http://www.w3.org/2001/04/xmlenc#sec-EncryptedKey
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class KeyInfoEncryptedKey : KeyInfoClause {
|
||||
|
||||
#region Fields
|
||||
|
||||
EncryptedKey encryptedKey;
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public KeyInfoEncryptedKey ()
|
||||
{
|
||||
}
|
||||
|
||||
public KeyInfoEncryptedKey (EncryptedKey encryptedKey)
|
||||
{
|
||||
EncryptedKey = encryptedKey;
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
public EncryptedKey EncryptedKey {
|
||||
get { return encryptedKey; }
|
||||
set { encryptedKey = value; }
|
||||
}
|
||||
|
||||
#endregion // Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
public override XmlElement GetXml ()
|
||||
{
|
||||
return GetXml (new XmlDocument ());
|
||||
}
|
||||
|
||||
internal XmlElement GetXml (XmlDocument document)
|
||||
{
|
||||
if (encryptedKey != null)
|
||||
return encryptedKey.GetXml (document);
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void LoadXml (XmlElement value)
|
||||
{
|
||||
EncryptedKey = new EncryptedKey ();
|
||||
EncryptedKey.LoadXml (value);
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
|
@@ -1,73 +0,0 @@
|
||||
//
|
||||
// KeyInfoName.cs - KeyInfoName implementation for XML Signature
|
||||
//
|
||||
// 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
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class KeyInfoName : KeyInfoClause {
|
||||
|
||||
private string name;
|
||||
|
||||
public KeyInfoName ()
|
||||
{
|
||||
}
|
||||
|
||||
public KeyInfoName (string keyName)
|
||||
{
|
||||
name = keyName;
|
||||
}
|
||||
|
||||
public string Value {
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
|
||||
public override XmlElement GetXml ()
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyName, XmlSignature.NamespaceURI);
|
||||
xel.InnerText = name;
|
||||
return xel;
|
||||
}
|
||||
|
||||
public override void LoadXml (XmlElement value)
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ();
|
||||
if ((value.LocalName != XmlSignature.ElementNames.KeyName) || (value.NamespaceURI != XmlSignature.NamespaceURI))
|
||||
name = "";
|
||||
else
|
||||
name = value.InnerText;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// KeyInfoNode.cs - KeyInfoNode implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class KeyInfoNode : KeyInfoClause {
|
||||
|
||||
private XmlElement Node;
|
||||
|
||||
public KeyInfoNode () {}
|
||||
|
||||
public KeyInfoNode (XmlElement node)
|
||||
{
|
||||
LoadXml (node);
|
||||
}
|
||||
|
||||
public XmlElement Value {
|
||||
get { return Node; }
|
||||
set { Node = value; }
|
||||
}
|
||||
|
||||
public override XmlElement GetXml ()
|
||||
{
|
||||
return Node;
|
||||
}
|
||||
|
||||
// LAMESPEC: No ArgumentNullException is thrown if value == null
|
||||
public override void LoadXml (XmlElement value)
|
||||
{
|
||||
Node = value;
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user