Ejemplo n.º 1
0
 public void EncodeDone(AlternativeCompositeByteBuf buffer, ISignatureFactory signatureFactory, IPrivateKey messagePrivateKey)
 {
     if (IsSigned)
     {
         if (Signature == null && PrivateKey != null)
         {
             Signature = signatureFactory.Sign(PrivateKey, _buffer.ToByteBuf());
         }
         else if (Signature == null && messagePrivateKey != null)
         {
             Signature = signatureFactory.Sign(messagePrivateKey, _buffer.ToByteBuf());
         }
         else if (Signature == null)
         {
             throw new ArgumentException("A private key is required to sign.");
         }
         Signature.Write(buffer);
     }
 }
Ejemplo n.º 2
0
 private Data SignNow(IPrivateKey privateKey, ISignatureFactory signatureFactory, bool isProtectedEntry)
 {
     if (Signature == null)
     {
         Signature        = signatureFactory.Sign(privateKey, _buffer.ToByteBuf());
         IsSigned         = true;
         HasPublicKey     = true;
         IsProtectedEntry = isProtectedEntry;
     }
     return(this);
 }
Ejemplo n.º 3
0
        public bool Write(AlternativeCompositeByteBuf buffer, Message message, ISignatureCodec signatureCodec)
        {
            Message = message;
            Logger.Debug("Message for outbound {0}.", message);

            if (!_header)
            {
                MessageHeaderCodec.EncodeHeader(buffer, message);
                _header = true;
            }
            else
            {
                Logger.Debug("Send a follow-up message {0}.", message);
                _resume = true;
            }

            bool done = Loop(buffer);

            Logger.Debug("Message encoded {0}.", message);

            // write out what we have
            if (buffer.IsReadable && done)
            {
                // check if message needs to be signed
                if (message.IsSign)
                {
                    // we sign if we did not provide a signature already
                    if (signatureCodec == null)
                    {
                        signatureCodec = _signatureFactory.Sign(message.PrivateKey, buffer);
                    }
                    // in case of relay, we have a signature, so we need to resuse this
                    signatureCodec.Write(buffer);
                }
            }

            return(done);
        }