using System;
using System.Web.Http;

namespace PkcsApp.Commands
{
    public class SignController : ApiController
    {


        // GET api/sign
        public string Get()
        {
            return "SignCommand";
        }

        // POST api/values 
        public string Post([FromBody]SignCommand value)
        {
            string signature = null;
            var manager = Pkcs11Manager.getInstance();



            byte[] hash = HelperFunctions.HexStringToByte(value.hash);

            if (value.signatureType == CertificateType.SIG_EP)
            {
                Certificate certEP = manager.getTokenSignCertificate(CertificateType.SIG_EP);
                signature = Convert.ToBase64String(manager.signEP(hash, certEP.ID));
            }
            else
            {

                signature = Convert.ToBase64String(manager.signZEP(hash), Base64FormattingOptions.InsertLineBreaks);
            }

            return signature;
        }

    }
}
