예제 #1
0
        public SecondIssuanceMessageInfo SecondMessage(SecondIssuanceMessageSpec spec)
        {
            if (spec.IssuerParameter == null)
            {
                ApiArgumentFault fault = new ApiArgumentFault();
                fault.Details       = "Issuer with unique ID was found";
                fault.Argument      = "IssuerSetupParametersSpec.ID";
                fault.ArgumentValue = spec.IssuerParameter.Serialize();
                throw new FaultException <ApiArgumentFault>(fault);
            }
            ProverProtocolParameters pProtoParam = new ProverProtocolParameters(spec.IssuerParameter);

            pProtoParam.NumberOfTokens = spec.NumberOfTokens;
            if (!String.IsNullOrWhiteSpace(spec.TokenInfomation))
            {
                pProtoParam.TokenInformation = ExtensionMethods.ToByteArray(spec.TokenInfomation);
            }

            if (!String.IsNullOrWhiteSpace(spec.Gamma))
            {
                pProtoParam.Gamma = ExtensionMethods.ToGroupElement(spec.Gamma, spec.IssuerParameter);
            }

            if (!String.IsNullOrWhiteSpace(spec.DevicePublicKey))
            {
                pProtoParam.DevicePublicKey = ExtensionMethods.ToGroupElement(spec.DevicePublicKey, spec.IssuerParameter);
            }

            if (!String.IsNullOrWhiteSpace(spec.ProverInfomation))
            {
                pProtoParam.ProverInformation = ExtensionMethods.ToByteArray(spec.ProverInfomation);
            }

            if (spec.RandomData != null)
            {
                pProtoParam.ProverRandomData = spec.RandomData;
            }
            if (spec.BatchSecurityLevel > 0)
            {
                pProtoParam.BatchValidationSecurityLevel = spec.BatchSecurityLevel;
            }
            pProtoParam.Validate();
            Prover prover = pProtoParam.CreateProver();

            SecondIssuanceMessage  secondMessage          = prover.GenerateSecondMessage(spec.FirstMessage);
            PostSecondMessageState postSecondMessageState = prover.ExportPostSecondMessageState();

            SecondIssuanceMessageInfo simInfo = new SecondIssuanceMessageInfo();

            simInfo.PostSecondMessageState = postSecondMessageState;
            simInfo.SecondMessage          = secondMessage;

            Guid issuerInstance = Guid.NewGuid();

            simInfo.ProverInstanceID = issuerInstance;
            proverInstanceDB.TryAdd(issuerInstance, new ProverInstanceData(prover));

            return(simInfo);
        }
    public SecondIssuanceMessageInfo SecondMessage(SecondIssuanceMessageSpec spec)
    {
      if (spec.IssuerParameter == null)
      {
        ApiArgumentFault fault = new ApiArgumentFault();
        fault.Details = "Issuer with unique ID was found";
        fault.Argument = "IssuerSetupParametersSpec.ID";
        fault.ArgumentValue = spec.IssuerParameter.Serialize();
        throw new FaultException<ApiArgumentFault>(fault);
      }
      ProverProtocolParameters pProtoParam = new ProverProtocolParameters(spec.IssuerParameter);
      pProtoParam.NumberOfTokens = spec.NumberOfTokens;
      if (!String.IsNullOrWhiteSpace(spec.TokenInfomation))
      {
        pProtoParam.TokenInformation = ExtensionMethods.ToByteArray(spec.TokenInfomation);
      }

      if (!String.IsNullOrWhiteSpace(spec.Gamma))
      {

        pProtoParam.Gamma = ExtensionMethods.ToGroupElement(spec.Gamma, spec.IssuerParameter);
      }

      if (!String.IsNullOrWhiteSpace(spec.DevicePublicKey))
      {
        pProtoParam.DevicePublicKey = ExtensionMethods.ToGroupElement(spec.DevicePublicKey, spec.IssuerParameter);
      }

      if (!String.IsNullOrWhiteSpace(spec.ProverInfomation))
      {
        pProtoParam.ProverInformation = ExtensionMethods.ToByteArray(spec.ProverInfomation);
      }

      if (spec.RandomData != null)
      {
        pProtoParam.ProverRandomData = spec.RandomData;
      }
      if (spec.BatchSecurityLevel > 0)
      {
        pProtoParam.BatchValidationSecurityLevel = spec.BatchSecurityLevel;
      }
      pProtoParam.Validate();
      Prover prover = pProtoParam.CreateProver();

      SecondIssuanceMessage secondMessage = prover.GenerateSecondMessage(spec.FirstMessage);
      PostSecondMessageState postSecondMessageState = prover.ExportPostSecondMessageState();

      SecondIssuanceMessageInfo simInfo = new SecondIssuanceMessageInfo();
      simInfo.PostSecondMessageState = postSecondMessageState;
      simInfo.SecondMessage = secondMessage;

      Guid issuerInstance = Guid.NewGuid();
      simInfo.ProverInstanceID = issuerInstance;
      proverInstanceDB.TryAdd(issuerInstance, new ProverInstanceData(prover));

      return simInfo;
    }