示例#1
0
        public byte[] Encode()
        {
            BinaryProcedures.CreateBinaryWriter(out var ms, out var writer);

            writer.Write((byte)PacketTypes.DmpPing);
            DirectChannelToken32.Encode(writer);
            writer.Write(PingRequestId32);

            byte flags = 0;

            if (PublicEcdheKey != null)
            {
                flags |= Flags_PublicEcdheKeySet;
            }
            writer.Write(flags);

            if (PublicEcdheKey != null)
            {
                PublicEcdheKey.Encode(writer);
            }


            PingPongHMAC.Encode(writer);
            return(ms.ToArray());
        }
示例#2
0
        public byte[] Encode()
        {
            BinaryProcedures.CreateBinaryWriter(out var ms, out var writer);
            writer.Write((byte)PacketTypes.MessagePart);
            writer.Write(MessageId32);
            writer.Write((byte)SenderStatus);
            byte flags = 0;

            writer.Write(flags);

            if (SenderStatus == MessageSessionStatusCode.inProgress)
            {
                BinaryProcedures.EncodeByteArray65536(writer, ContinuedEncryptedData);
            }
            else if (SenderStatus == MessageSessionStatusCode.encryptionDecryptionCompleted)
            {
                SenderSignature.Encode(writer);
            }

            MessageHMAC.Encode(writer);

            var r = ms.ToArray();

            if (r.Length > 500)
            {
                throw new ArgumentException();
            }
            return(r);
        }
示例#3
0
        /// <param name="connectionToNeighborNullable">is not null for packets between registered peers. if set, the procedure sets NeighborToken32 and NeighborHMAC</param>
        public byte[] Encode_OptionallySignNeighborHMAC(ConnectionToNeighbor connectionToNeighborNullable)
        {
            PacketProcedures.CreateBinaryWriter(out var ms, out var writer);

            writer.Write((byte)PacketTypes.RegisterReq);
            byte flags = 0;

            if (connectionToNeighborNullable == null)
            {
                flags |= Flag_AtoEP;
            }
            if (DirectionVectorNullable != null)
            {
                flags |= Flag_DirectionVectorExists;
            }

            writer.Write(flags);
            if (connectionToNeighborNullable != null)
            {
                NeighborToken32 = connectionToNeighborNullable.RemoteNeighborToken32;
                NeighborToken32.Encode(writer);
            }

            GetSharedSignedFields(writer, true);

            if (connectionToNeighborNullable == null)
            {
                if (ProofOfWork2.Length != 64)
                {
                    throw new ArgumentException();
                }
                writer.Write(ProofOfWork2);
            }
            writer.Write(NumberOfHopsRemaining);
            writer.Write(NumberOfRandomHopsRemaining);
            ReqP2pSeq16.Encode(writer);
            if (connectionToNeighborNullable != null)
            {
                NeighborHMAC = connectionToNeighborNullable.GetNeighborHMAC(this.GetSignedFieldsForNeighborHMAC);
                NeighborHMAC.Encode(writer);
            }

            return(ms.ToArray());
        }
示例#4
0
        public byte[] Encode_SetP2pFields(ConnectionToNeighbor transmitToNeighbor)
        {
            PacketProcedures.CreateBinaryWriter(out var ms, out var w);
            w.Write((byte)PacketTypes.InviteReq);
            byte flags = 0;

            w.Write(flags);

            ReqP2pSeq16     = transmitToNeighbor.GetNewRequestP2pSeq16_P2P();
            NeighborToken32 = transmitToNeighbor.RemoteNeighborToken32;
            NeighborToken32.Encode(w);

            GetSignedFieldsForNeighborHMAC(w);

            NeighborHMAC = transmitToNeighbor.GetNeighborHMAC(GetSignedFieldsForNeighborHMAC);
            NeighborHMAC.Encode(w);

            return(ms.ToArray());
        }
示例#5
0
        public byte[] Encode()
        {
            BinaryProcedures.CreateBinaryWriter(out var ms, out var writer);
            GetHeaderFields(writer, DirectChannelToken32, PingRequestId32);
            byte flags = 0;

            if (PublicEcdheKey != null)
            {
                flags |= Flags_PublicEcdheKeySet;
            }
            writer.Write(flags);

            if (PublicEcdheKey != null)
            {
                PublicEcdheKey.Encode(writer);
            }

            PingPongHMAC.Encode(writer);
            return(ms.ToArray());
        }
示例#6
0
        public byte[] Encode()
        {
            BinaryProcedures.CreateBinaryWriter(out var ms, out var writer);
            writer.Write((byte)PacketTypes.MessageStart);
            DirectChannelToken32.Encode(writer);
            writer.Write(MessageId32);
            byte flags = 0;

            writer.Write(flags);
            writer.Write(MessageTimestamp64);
            BinaryProcedures.EncodeByteArray65536(writer, EncryptedMessageData);
            MessageHMAC.Encode(writer);

            var r = ms.ToArray();

            if (r.Length > 500)
            {
                throw new ArgumentException();
            }
            return(r);
        }
示例#7
0
        public byte[] Encode(bool epToA)
        {
            PacketProcedures.CreateBinaryWriter(out var ms, out var writer);
            EncodeHeader(writer, ReqP2pSeq16);
            byte flags = 0;

            if (epToA)
            {
                flags |= Flag_EPtoA;
            }
            writer.Write(flags);
            if (epToA == false)
            {
                NeighborToken32.Encode(writer);
            }
            writer.Write((byte)ResponseCode);
            if (epToA == false)
            {
                NeighborHMAC.Encode(writer);
            }
            return(ms.ToArray());
        }
示例#8
0
        public byte[] Encode()
        {
            BinaryProcedures.CreateBinaryWriter(out var ms, out var writer);
            writer.Write((byte)PacketTypes.MessageAck);
            writer.Write(MessageId32);
            writer.Write((byte)ReceiverStatus);
            byte flags = 0;

            writer.Write(flags);
            if (ReceiverStatus == MessageSessionStatusCode.encryptionDecryptionCompleted)
            {
                writer.Write(ReceiverFinalNonce);
            }

            MessageHMAC.Encode(writer);

            var r = ms.ToArray();

            if (r.Length > 500)
            {
                throw new ArgumentException();
            }
            return(r);
        }