GetPacketLength() public static method

Reads a packet header from an array and extracts the packet's length.
/// Thrown if is . /// /// Thrown if has less than 4 elements. ///
public static GetPacketLength ( byte header ) : int
header byte The array to read from.
return int
Ejemplo n.º 1
0
        public void GetPacketHeader_Throws_For_Null_Segment()
        {
            Action getPacketLength = () => RollingIv.GetPacketLength(null);

            getPacketLength
            .ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 2
0
        public void GetPacketHeader_Throws_When_Segment_Shorter_Than_4_Bytes()
        {
            Action getPacketLength = () => RollingIv.GetPacketLength(new byte[] { 0x01, 0x02, 0x03 });

            getPacketLength
            .ShouldThrow <ArgumentException>()
            .WithMessagePrefix(SegmentMustBeLongerThan4());
        }
Ejemplo n.º 3
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);
     }
 }