mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -10:00
* DataObject.cs: New. Complete implementation. * DSAKeyValue.cs: New. Complete implementation. * KeyInfo.cs: New. Complete implementation. * KeyInfoClause.cs: New. Abstract class (complete). * KeyInfoName.cs: New. Complete implementation. * KeyInfoNode.cs: New. Complete implementation. * KeyInfoRetrievalMethod.cs: New. Complete implementation. * KeyInfoX509Data.cs: New. Complete implementation. * Reference.cs: New. Incomplete implementation. * RSAKeyValue.cs: New. Complete implementation. * Signature.cs: New. Almost complete implementation - returned XML isn't exactly like the MS implementation. * SignedInfo.cs: New. Complete except SignatureLength. * SignedXml.cs: New. Minimal implementation (only enveloped signatures). Still many TODO! * Transform.cs: New. Abstract class (complete). * TransformChain.cs: New. Complete implementation. * XmlDsigBase64Transform.cs: New. Stub + basic logic. * XmlDsigC14NTransform.cs: New. Stub + basic logic. * XmlDsigC14NWithCommentsTransform.cs: New. Stub + basic logic. * XmlDsigEnvelopedSignatureTransform.cs: New. Stub + basic logic. * XmlDsigXPathTransform.cs: New. Stub + basic logic. * XmlDsigXsltTransform.cs: New. Stub + basic logic. svn path=/trunk/mcs/; revision=9124
162 lines
4.0 KiB
C#
162 lines
4.0 KiB
C#
//
|
|
// DataObject.cs - DataObject implementation for XML Signature
|
|
// http://www.w3.org/2000/09/xmldsig#Object
|
|
//
|
|
// Author:
|
|
// Sebastien Pouliot ([email protected])
|
|
//
|
|
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
|
|
//
|
|
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
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 string id;
|
|
private string mimeType;
|
|
private string encoding;
|
|
private string data;
|
|
private XmlDocument doc;
|
|
|
|
static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
|
|
|
|
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);
|
|
}
|
|
|
|
private void Build (string id, string mimeType, string encoding, XmlElement data)
|
|
{
|
|
StringBuilder sb = new StringBuilder ();
|
|
sb.Append ("<Object ");
|
|
if (id != null) {
|
|
this.id = id;
|
|
sb.Append ("Id=\"");
|
|
sb.Append (id);
|
|
sb.Append ("\" ");
|
|
}
|
|
if (mimeType != null) {
|
|
this.mimeType = mimeType;
|
|
sb.Append ("MimeType=\"");
|
|
sb.Append (mimeType);
|
|
sb.Append ("\" ");
|
|
}
|
|
if (encoding != null) {
|
|
this.encoding = encoding;
|
|
sb.Append ("Encoding=\"");
|
|
sb.Append (encoding);
|
|
sb.Append ("\" ");
|
|
}
|
|
sb.Append ("xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />");
|
|
|
|
doc = new XmlDocument ();
|
|
doc.LoadXml (sb.ToString ());
|
|
if (data != null) {
|
|
XmlNodeList xnl = doc.GetElementsByTagName ("Object");
|
|
XmlNode newNode = doc.ImportNode (data, true);
|
|
xnl[0].AppendChild (newNode);
|
|
}
|
|
}
|
|
|
|
// why is data a XmlNodeList instead of a XmlElement ?
|
|
public XmlNodeList Data {
|
|
get {
|
|
XmlNodeList xnl = doc.GetElementsByTagName ("Object");
|
|
return xnl[0].ChildNodes;
|
|
}
|
|
set {
|
|
if (value == null)
|
|
throw new ArgumentNullException ("value");
|
|
|
|
Build (id, mimeType, encoding, null);
|
|
XmlNodeList xnl = doc.GetElementsByTagName ("Object");
|
|
if ((xnl != null) && (xnl.Count > 0)) {
|
|
foreach (XmlNode xn in value) {
|
|
XmlNode newNode = doc.ImportNode (xn, true);
|
|
xnl[0].AppendChild (newNode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// default to null - no encoding
|
|
public string Encoding {
|
|
get { return encoding; }
|
|
set { encoding = value; }
|
|
}
|
|
|
|
// default to null
|
|
public string Id {
|
|
get { return id; }
|
|
set { id = value; }
|
|
}
|
|
|
|
// default to null
|
|
public string MimeType {
|
|
get { return mimeType; }
|
|
set { mimeType = value; }
|
|
}
|
|
|
|
public XmlElement GetXml ()
|
|
{
|
|
if ((doc.DocumentElement.LocalName == "Object") && (doc.DocumentElement.NamespaceURI == "http://www.w3.org/2000/09/xmldsig#")) {
|
|
// recreate all attributes in order
|
|
XmlAttribute xa = null;
|
|
doc.DocumentElement.Attributes.RemoveAll ();
|
|
if (id != null) {
|
|
xa = doc.CreateAttribute ("Id");
|
|
xa.Value = id;
|
|
doc.DocumentElement.Attributes.Append (xa);
|
|
}
|
|
if (mimeType != null) {
|
|
xa = doc.CreateAttribute ("MimeType");
|
|
xa.Value = mimeType;
|
|
doc.DocumentElement.Attributes.Append (xa);
|
|
}
|
|
if (encoding != null) {
|
|
xa = doc.CreateAttribute ("Encoding");
|
|
xa.Value = encoding;
|
|
doc.DocumentElement.Attributes.Append (xa);
|
|
}
|
|
xa = doc.CreateAttribute ("xmlns");
|
|
xa.Value = xmldsig;
|
|
doc.DocumentElement.Attributes.Append (xa);
|
|
}
|
|
return doc.DocumentElement;
|
|
}
|
|
|
|
public void LoadXml (XmlElement value)
|
|
{
|
|
if (value == null)
|
|
throw new ArgumentNullException ("value");
|
|
|
|
if ((value.LocalName == "Object") && (value.NamespaceURI == "http://www.w3.org/2000/09/xmldsig#")) {
|
|
doc.LoadXml (value.OuterXml);
|
|
XmlAttribute xa = value.Attributes ["Id"];
|
|
id = ((xa != null) ? xa.InnerText : null);
|
|
xa = value.Attributes ["MimeType"];
|
|
mimeType = ((xa != null) ? xa.InnerText : null);
|
|
xa = value.Attributes ["Encoding"];
|
|
encoding = ((xa != null) ? xa.InnerText : null);
|
|
}
|
|
else
|
|
doc.LoadXml (value.OuterXml);
|
|
}
|
|
}
|
|
|
|
} |