OpenStory.Cryptography.RollingIv.ValidateHeader C# (CSharp) Method

ValidateHeader() public method

Determines whether the start of an array is a valid packet header.
public ValidateHeader ( byte header ) : bool
header byte The raw packet data to validate.
return bool
        public bool ValidateHeader(byte[] header)
        {
            Guard.NotNull(() => header, header);

            if (header.Length < 4)
            {
                var message = string.Format(CommonStrings.SegmentTooShort, 4);
                throw new ArgumentException(message, "header");
            }

            return ValidateHeaderInternal(header, this.iv, this.versionMask);
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Attempts to extract the length of a packet from its header.
 /// </summary>
 /// <remarks>
 /// When overriding this method in a derived class,
 /// do not call the base implementation.
 /// </remarks>
 /// <param name="header">The header byte array to process.</param>
 /// <param name="length">A variable to hold the result.</param>
 /// <returns><see langword="true"/> if the extraction was successful; otherwise, <see langword="false"/>.</returns>
 public bool TryGetLength(byte[] header, out int length)
 {
     if (_decryptor.ValidateHeader(header))
     {
         length = RollingIv.GetPacketLength(header);
         return(true);
     }
     else
     {
         length = default(int);
         return(false);
     }
 }