Exemplo n.º 1
0
        /// <summary>
        /// Decrypts and deserializes a message from a byte buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="sharedKey">The shared encryption key.</param>
        /// <exception cref="FormatException">Thrown if the buffer does not contain a valid message.</exception>
        public DynDnsMessage(byte[] buffer, SymmetricKey sharedKey)
        {
            try
            {
                using (var ms = new EnhancedMemoryStream(Crypto.Decrypt(buffer, sharedKey)))
                {
                    if (ms.ReadInt32Le() != Magic)
                    {
                        throw new Exception();
                    }

                    this.Version = ms.ReadByte();
                    if (this.Version < FormatVer)
                    {
                        throw new FormatException(string.Format("DynDnsMessage version [{0}] is not supported.", this.Version));
                    }

                    this.TimeStampUtc = new DateTime(ms.ReadInt64Le());
                    this.Flags        = (DynDnsMessageFlag)ms.ReadInt32Le();
                    this.HostEntry    = new DynDnsHostEntry(ms.ReadString16());
                }
            }
            catch (Exception e)
            {
                throw new FormatException("Invalid Dynamic DNS message.", e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decrypts and deserializes a message from a byte buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="sharedKey">The shared encryption key.</param>
        /// <exception cref="FormatException">Thrown if the buffer does not contain a valid message.</exception>
        public UdpBroadcastMessage(byte[] buffer, SymmetricKey sharedKey)
        {
            try
            {
                using (var ms = new EnhancedMemoryStream(Crypto.Decrypt(buffer, sharedKey)))
                {
                    if (ms.ReadInt32Le() != Magic)
                    {
                        throw new Exception();
                    }

                    this.TimeStampUtc   = new DateTime(ms.ReadInt64Le());
                    this.SourceAddress  = new IPAddress(ms.ReadBytes(4));
                    this.MessageType    = (UdpBroadcastMessageType)ms.ReadByte();
                    this.BroadcastGroup = ms.ReadByte();
                    this.Payload        = ms.ReadBytes16();
                }
            }
            catch (Exception e)
            {
                throw new FormatException("Invalid UDP broadcast message.", e);
            }
        }