Пример #1
0
        protected override int PostSignaturePacked(Packer packer, int messageSize)
        {
            var startPosition = packer.Position - messageSize;

            packer.Position = startPosition;

            packer.AddSignature(_signKey, startPosition, messageSize);

            return(Signature.GetSignatureBytes(Protocol.MessageKeyType));
        }
Пример #2
0
        public static NodeKey Pack(Packer packer, int chainId, uint chainIndex, short keyIndex, PublicChainKeyFlags keyFlags, Key signKey)
        {
            packer.Pack(chainId);
            packer.Pack(chainIndex);
            packer.Pack(keyIndex);
            packer.Pack((long)keyFlags);
            (var hash, var signature) = packer.AddSignature(signKey, 0, packer.Position);

            return(new NodeKey(chainId, chainIndex, keyIndex, keyFlags, signature, hash));
        }
Пример #3
0
        protected override int PostSignaturePacked(Packer packer, int messageSize)
        {
            if (IsCoreNode)
            {
                var startPosition = packer.Position - messageSize;
                packer.Position = startPosition;

                packer.AddSignature(_nodeConfiguration.CoreKey.DecryptedKey, startPosition, messageSize);

                return(Signature.GetSignatureBytes(Protocol.MessageKeyType));
            }

            return(base.PostSignaturePacked(packer, messageSize));
        }
Пример #4
0
        public int Store(Packer packer, ushort version)
        {
            var startPosition = packer.Position;

            var sign = _key != null;

            if (sign)
            {
                packer.Pack(MessageMagicSigned);
            }
            else
            {
                packer.Pack(MessageMagic);
            }

            packer.Pack(version);

            var sizePosition = packer.Position;

            packer.Pack((uint)0); // messageSize dummy
            packer.Pack(MessageType);

            packer.Pack(Pack);

            var messageSize = packer.Position - startPosition;

            if (sign)
            {
                var signatureSize = Signature.GetSignatureBytes(Protocol.MessageKeyType);
                messageSize += signatureSize;
            }

            if (messageSize > MessageMaxSize)
            {
                throw new Exception("Invalid message size");
            }

            Size            = (uint)messageSize;
            packer.Position = sizePosition;
            packer.Pack((uint)messageSize); // update size

            if (sign)
            {
                (SignatureHash, Signature) = packer.AddSignature(_key, startPosition, messageSize);
                messageSize += PostSignaturePacked(packer, messageSize);
            }

            return(messageSize);
        }
Пример #5
0
        protected override void PostPack(Packer packer, int packerStartPosition)
        {
            base.PostPack(packer, packerStartPosition);

            if (Signature == null)
            {
                var dataSize = packer.Position - packerStartPosition;
                (SignatureHash, Signature) = packer.AddSignature(_signKey, packerStartPosition, dataSize);
                UniqueIdentifier           = BitConverter.ToInt64(SignatureHash.RawData.Array, 0);
            }
            else
            {
                packer.Pack(Signature);
            }

            if (HasMetaData)
            {
                MetaData.Pack(packer, _features);
            }
        }