using System;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using SdaWSCryptoClient;

namespace MOH_CRA_XCRMS_Service.Common
{
    public static class XmlSigning
    {
        internal static void SignXml(this XmlElement unsignedXml, X509Certificate2 certificate, Guid signObjectUid)
        {
            XmlAttribute idAttribute = unsignedXml.Attributes["Id"];
            if (idAttribute == null)
                idAttribute = unsignedXml.OwnerDocument.CreateAttribute("Id");

            unsignedXml.Attributes.Append(idAttribute).Value = signObjectUid.ToString();

            XmlElement signature = XMLSigner.GenerateXMLSignature(unsignedXml, unsignedXml.Attributes["Id"].Value, certificate);
            //  XmlElement signature = Class1.GenerateXMLSignature(unsignedXml, unsignedXml.Attributes["Id"].Value, certificate);

            unsignedXml.AppendChild(signature);
        }
    }
}