Example #1
0
        private static void ValidateExtendedSignParams(RawSignedModel model, SignParams @params)
        {
            ValidateSignParams(model, @params.SignerPrivateKey);

            if (@params.Signer == null)
            {
                throw new ArgumentException($"{nameof(@params.Signer)} property is mandatory");
            }
        }
Example #2
0
 private static void ThrowExceptionIfSignatureExists(SignParams @params, IList <RawSignature> signatures)
 {
     if (signatures != null &&
         ((List <RawSignature>)signatures).Exists(
             s => s.Signer == @params.Signer))
     {
         throw new VirgilException("The model already has this signature.");
     }
 }
Example #3
0
        /// <summary>
        /// Adds signature to the specified <see cref="RawSignedModel"/> using specified signer
        /// parameters included private key, signer type and additional raw bytes.
        /// </summary>
        /// <param name="model"> the instance of <see cref="RawSignedModel"/> to be signed.</param>
        /// <param name="@params"> the instance of <see cref="SignParams"/> to sign with.</param>
        /// <param name="signatureSnapshot"> Some additional raw bytes to be signed with model.</param>
        public void Sign(RawSignedModel model, SignParams @params, byte[] signatureSnapshot = null)
        {
            ValidateExtendedSignParams(model, @params);
            ThrowExceptionIfSignatureExists(@params, model.Signatures);

            var extendedSnapshot = signatureSnapshot != null?
                                   Bytes.Combine(model.ContentSnapshot, signatureSnapshot)
                                       : model.ContentSnapshot;

            var signatureBytes = Crypto.GenerateSignature(extendedSnapshot, @params.SignerPrivateKey);

            var signature = new RawSignature
            {
                Signer    = @params.Signer,
                Signature = signatureBytes,
                Snapshot  = signatureSnapshot
            };

            model.Signatures.Add(signature);
        }
Example #4
0
 /// <summary>
 /// Adds signature to the specified <see cref="RawSignedModel"/> using specified signer
 /// parameters included private key, signer type and dictionary with additional data.
 /// </summary>
 /// <param name="model"> the instance of <see cref="RawSignedModel"/> to be signed.</param>
 /// <param name="@params"> the instance of <see cref="SignParams"/> to sign with.</param>
 /// <param name="extraFields"> Dictionary with additional data to be signed with model.</param>
 public void Sign(RawSignedModel model, SignParams @params, Dictionary <string, string> ExtraFields)
 {
     Sign(model, @params,
          (ExtraFields != null) ? SnapshotUtils.TakeSnapshot(ExtraFields) : null
          );
 }