# < Summary

Information

Class: | Renci.SshNet.Common.Pack
Assembly: | Renci.SshNet
File(s): | \home\appveyor\projects\ssh-net\src\Renci.SshNet\Common\Pack.cs

Line coverage
90%

Covered lines: | 126
Uncovered lines: | 13
Coverable lines: | 139
Total lines: | 271
Line coverage: | 90.6%

Branch coverage
N/A

Covered branches: | 0
Total branches: | 0
Branch coverage: | N/A

Method coverage

Feature is only available for sponsors

Upgrade to PRO version

# Metrics

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
LittleEndianToUInt16(...) | 100% | 1 | 100%
LittleEndianToUInt32(...) | 100% | 1 | 0%
LittleEndianToUInt32(...) | 100% | 1 | 100%
LittleEndianToUInt64(...) | 100% | 1 | 100%
UInt16ToLittleEndian(...) | 100% | 1 | 100%
UInt16ToLittleEndian(...) | 100% | 1 | 100%
UInt32ToLittleEndian(...) | 100% | 1 | 100%
UInt32ToLittleEndian(...) | 100% | 1 | 100%
UInt32ToLittleEndian(...) | 100% | 1 | 0%
UInt64ToLittleEndian(...) | 100% | 1 | 100%
UInt64ToLittleEndian(...) | 100% | 1 | 100%
UInt16ToBigEndian(...) | 100% | 1 | 100%
UInt16ToBigEndian(...) | 100% | 1 | 100%
UInt16ToBigEndian(...) | 100% | 1 | 100%
UInt32ToBigEndian(...) | 100% | 1 | 100%
UInt32ToBigEndian(...) | 100% | 1 | 100%
UInt32ToBigEndian(...) | 100% | 1 | 100%
UInt64ToBigEndian(...) | 100% | 1 | 100%
BigEndianToUInt16(...) | 100% | 1 | 100%
BigEndianToUInt32(...) | 100% | 1 | 100%
BigEndianToUInt32(...) | 100% | 1 | 100%
BigEndianToUInt64(...) | 100% | 1 | 100%

# File(s)

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Common\Pack.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `namespace Renci.SshNet.Common`
|  | `2` |  | `{`
|  | `3` |  | `/// <summary>`
|  | `4` |  | `/// Provides convenience methods for conversion to and from both Big Endian and Little Endian.`
|  | `5` |  | `/// </summary>`
|  | `6` |  | `internal static class Pack`
|  | `7` |  | `{`
|  | `8` |  | `/// <summary>`
|  | `9` |  | `/// Converts little endian bytes into number.`
|  | `10` |  | `/// </summary>`
|  | `11` |  | `/// <param name="buffer">The buffer.</param>`
|  | `12` |  | `/// <returns>Converted <see cref="ushort" />.</returns>`
|  | `13` |  | `internal static ushort LittleEndianToUInt16(byte[] buffer)`
| 18 | `14` |  | `{`
| 18 | `15` |  | `ushort n = buffer[0];`
| 18 | `16` |  | `n |= (ushort) (buffer[1] << 8);`
| 18 | `17` |  | `return n;`
| 18 | `18` |  | `}`
|  | `19` |  | ``
|  | `20` |  | `/// <summary>`
|  | `21` |  | `/// Converts little endian bytes into number.`
|  | `22` |  | `/// </summary>`
|  | `23` |  | `/// <param name="buffer">The buffer.</param>`
|  | `24` |  | `/// <param name="offset">The buffer offset.</param>`
|  | `25` |  | `/// <returns>Converted <see cref="uint" />.</returns>`
|  | `26` |  | `internal static uint LittleEndianToUInt32(byte[] buffer, int offset)`
| 0 | `27` |  | `{`
| 0 | `28` |  | `uint n = buffer[offset];`
| 0 | `29` |  | `n |= (uint) buffer[offset + 1] << 8;`
| 0 | `30` |  | `n |= (uint) buffer[offset + 2] << 16;`
| 0 | `31` |  | `n |= (uint) buffer[offset + 3] << 24;`
| 0 | `32` |  | `return n;`
| 0 | `33` |  | `}`
|  | `34` |  | ``
|  | `35` |  | `/// <summary>`
|  | `36` |  | `/// Converts little endian bytes into number.`
|  | `37` |  | `/// </summary>`
|  | `38` |  | `/// <param name="buffer">The buffer.</param>`
|  | `39` |  | `/// <returns>Converted <see cref="uint" />.</returns>`
|  | `40` |  | `internal static uint LittleEndianToUInt32(byte[] buffer)`
| 27 | `41` |  | `{`
| 27 | `42` |  | `uint n = buffer[0];`
| 27 | `43` |  | `n |= (uint) buffer[1] << 8;`
| 27 | `44` |  | `n |= (uint) buffer[2] << 16;`
| 27 | `45` |  | `n |= (uint) buffer[3] << 24;`
| 27 | `46` |  | `return n;`
| 27 | `47` |  | `}`
|  | `48` |  | ``
|  | `49` |  | `/// <summary>`
|  | `50` |  | `/// Converts little endian bytes into number.`
|  | `51` |  | `/// </summary>`
|  | `52` |  | `/// <param name="buffer">The buffer.</param>`
|  | `53` |  | `/// <returns>Converted <see cref="ulong" />.</returns>`
|  | `54` |  | `internal static ulong LittleEndianToUInt64(byte[] buffer)`
| 39 | `55` |  | `{`
| 39 | `56` |  | `ulong n = buffer[0];`
| 39 | `57` |  | `n |= (ulong) buffer[1] << 8;`
| 39 | `58` |  | `n |= (ulong) buffer[2] << 16;`
| 39 | `59` |  | `n |= (ulong) buffer[3] << 24;`
| 39 | `60` |  | `n |= (ulong) buffer[4] << 32;`
| 39 | `61` |  | `n |= (ulong) buffer[5] << 40;`
| 39 | `62` |  | `n |= (ulong) buffer[6] << 48;`
| 39 | `63` |  | `n |= (ulong) buffer[7] << 56;`
| 39 | `64` |  | `return n;`
| 39 | `65` |  | `}`
|  | `66` |  | ``
|  | `67` |  | `/// <summary>`
|  | `68` |  | `/// Populates buffer with little endian number representation.`
|  | `69` |  | `/// </summary>`
|  | `70` |  | `/// <param name="value">The number to convert.</param>`
|  | `71` |  | `internal static byte[] UInt16ToLittleEndian(ushort value)`
| 18 | `72` |  | `{`
| 18 | `73` |  | `var buffer = new byte[2];`
| 18 | `74` |  | `UInt16ToLittleEndian(value, buffer);`
| 18 | `75` |  | `return buffer;`
| 18 | `76` |  | `}`
|  | `77` |  | ``
|  | `78` |  | `/// <summary>`
|  | `79` |  | `/// Populates buffer with little endian number representation.`
|  | `80` |  | `/// </summary>`
|  | `81` |  | `/// <param name="value">The number to convert.</param>`
|  | `82` |  | `/// <param name="buffer">The buffer.</param>`
|  | `83` |  | `internal static void UInt16ToLittleEndian(ushort value, byte[] buffer)`
| 18 | `84` |  | `{`
| 18 | `85` |  | `buffer[0] = (byte) (value & 0x00FF);`
| 18 | `86` |  | `buffer[1] = (byte) ((value & 0xFF00) >> 8);`
| 18 | `87` |  | `}`
|  | `88` |  | ``
|  | `89` |  | `/// <summary>`
|  | `90` |  | `/// Populates buffer with little endian number representation.`
|  | `91` |  | `/// </summary>`
|  | `92` |  | `/// <param name="value">The number to convert.</param>`
|  | `93` |  | `internal static byte[] UInt32ToLittleEndian(uint value)`
| 27 | `94` |  | `{`
| 27 | `95` |  | `var buffer = new byte[4];`
| 27 | `96` |  | `UInt32ToLittleEndian(value, buffer);`
| 27 | `97` |  | `return buffer;`
| 27 | `98` |  | `}`
|  | `99` |  | ``
|  | `100` |  | `/// <summary>`
|  | `101` |  | `/// Populates buffer with little endian number representation.`
|  | `102` |  | `/// </summary>`
|  | `103` |  | `/// <param name="value">The number to convert.</param>`
|  | `104` |  | `/// <param name="buffer">The buffer.</param>`
|  | `105` |  | `internal static void UInt32ToLittleEndian(uint value, byte[] buffer)`
| 27 | `106` |  | `{`
| 27 | `107` |  | `buffer[0] = (byte) (value & 0x000000FF);`
| 27 | `108` |  | `buffer[1] = (byte) ((value & 0x0000FF00) >> 8);`
| 27 | `109` |  | `buffer[2] = (byte) ((value & 0x00FF0000) >> 16);`
| 27 | `110` |  | `buffer[3] = (byte) ((value & 0xFF000000) >> 24);`
| 27 | `111` |  | `}`
|  | `112` |  | ``
|  | `113` |  | `/// <summary>`
|  | `114` |  | `/// Populates buffer with little endian number representation.`
|  | `115` |  | `/// </summary>`
|  | `116` |  | `/// <param name="value">The number to convert.</param>`
|  | `117` |  | `/// <param name="buffer">The buffer.</param>`
|  | `118` |  | `/// <param name="offset">The buffer offset.</param>`
|  | `119` |  | `internal static void UInt32ToLittleEndian(uint value, byte[] buffer, int offset)`
| 0 | `120` |  | `{`
| 0 | `121` |  | `buffer[offset] = (byte) (value & 0x000000FF);`
| 0 | `122` |  | `buffer[offset + 1] = (byte) ((value & 0x0000FF00) >> 8);`
| 0 | `123` |  | `buffer[offset + 2] = (byte) ((value & 0x00FF0000) >> 16);`
| 0 | `124` |  | `buffer[offset + 3] = (byte) ((value & 0xFF000000) >> 24);`
| 0 | `125` |  | `}`
|  | `126` |  | ``
|  | `127` |  | `/// <summary>`
|  | `128` |  | `/// Populates buffer with little endian number representation.`
|  | `129` |  | `/// </summary>`
|  | `130` |  | `/// <param name="value">The number to convert.</param>`
|  | `131` |  | `internal static byte[] UInt64ToLittleEndian(ulong value)`
| 39 | `132` |  | `{`
| 39 | `133` |  | `var buffer = new byte[8];`
| 39 | `134` |  | `UInt64ToLittleEndian(value, buffer);`
| 39 | `135` |  | `return buffer;`
| 39 | `136` |  | `}`
|  | `137` |  | ``
|  | `138` |  | `/// <summary>`
|  | `139` |  | `/// Populates buffer with little endian number representation.`
|  | `140` |  | `/// </summary>`
|  | `141` |  | `/// <param name="value">The number to convert.</param>`
|  | `142` |  | `/// <param name="buffer">The buffer.</param>`
|  | `143` |  | `internal static void UInt64ToLittleEndian(ulong value, byte[] buffer)`
| 39 | `144` |  | `{`
| 39 | `145` |  | `buffer[0] = (byte) (value & 0x00000000000000FF);`
| 39 | `146` |  | `buffer[1] = (byte) ((value & 0x000000000000FF00) >> 8);`
| 39 | `147` |  | `buffer[2] = (byte) ((value & 0x0000000000FF0000) >> 16);`
| 39 | `148` |  | `buffer[3] = (byte) ((value & 0x00000000FF000000) >> 24);`
| 39 | `149` |  | `buffer[4] = (byte) ((value & 0x000000FF00000000) >> 32);`
| 39 | `150` |  | `buffer[5] = (byte) ((value & 0x0000FF0000000000) >> 40);`
| 39 | `151` |  | `buffer[6] = (byte) ((value & 0x00FF000000000000) >> 48);`
| 39 | `152` |  | `buffer[7] = (byte) ((value & 0xFF00000000000000) >> 56);`
| 39 | `153` |  | `}`
|  | `154` |  | ``
|  | `155` |  | `internal static byte[] UInt16ToBigEndian(ushort value)`
| 18 | `156` |  | `{`
| 18 | `157` |  | `var buffer = new byte[2];`
| 18 | `158` |  | `UInt16ToBigEndian(value, buffer);`
| 18 | `159` |  | `return buffer;`
| 18 | `160` |  | `}`
|  | `161` |  | ``
|  | `162` |  | `internal static void UInt16ToBigEndian(ushort value, byte[] buffer)`
| 18 | `163` |  | `{`
| 18 | `164` |  | `buffer[0] = (byte) (value >> 8);`
| 18 | `165` |  | `buffer[1] = (byte) (value & 0x00FF);`
| 18 | `166` |  | `}`
|  | `167` |  | ``
|  | `168` |  | `internal static void UInt16ToBigEndian(ushort value, byte[] buffer, int offset)`
| 102 | `169` |  | `{`
| 102 | `170` |  | `buffer[offset] = (byte) (value >> 8);`
| 102 | `171` |  | `buffer[offset + 1] = (byte) (value & 0x00FF);`
| 102 | `172` |  | `}`
|  | `173` |  | ``
|  | `174` |  | `internal static void UInt32ToBigEndian(uint value, byte[] buffer)`
| 475589 | `175` |  | `{`
| 475589 | `176` |  | `buffer[0] = (byte) ((value & 0xFF000000) >> 24);`
| 475589 | `177` |  | `buffer[1] = (byte) ((value & 0x00FF0000) >> 16);`
| 475589 | `178` |  | `buffer[2] = (byte) ((value & 0x0000FF00) >> 8);`
| 475589 | `179` |  | `buffer[3] = (byte) (value & 0x000000FF);`
| 475589 | `180` |  | `}`
|  | `181` |  | ``
|  | `182` |  | `internal static void UInt32ToBigEndian(uint value, byte[] buffer, int offset)`
| 13980 | `183` |  | `{`
| 13980 | `184` |  | `buffer[offset++] = (byte) ((value & 0xFF000000) >> 24);`
| 13980 | `185` |  | `buffer[offset++] = (byte) ((value & 0x00FF0000) >> 16);`
| 13980 | `186` |  | `buffer[offset++] = (byte) ((value & 0x0000FF00) >> 8);`
| 13980 | `187` |  | `buffer[offset] = (byte) (value & 0x000000FF);`
| 13980 | `188` |  | `}`
|  | `189` |  | ``
|  | `190` |  | `internal static byte[] UInt32ToBigEndian(uint value)`
| 368731 | `191` |  | `{`
| 368731 | `192` |  | `var buffer = new byte[4];`
| 368731 | `193` |  | `UInt32ToBigEndian(value, buffer);`
| 368731 | `194` |  | `return buffer;`
| 368731 | `195` |  | `}`
|  | `196` |  | ``
|  | `197` |  | `/// <summary>`
|  | `198` |  | `/// Returns the specified 64-bit unsigned integer value as an array of bytes.`
|  | `199` |  | `/// </summary>`
|  | `200` |  | `/// <param name="value">The number to convert.</param>`
|  | `201` |  | `/// <returns>An array of bytes with length 8.</returns>`
|  | `202` |  | `internal static byte[] UInt64ToBigEndian(ulong value)`
| 8221 | `203` |  | `{`
| 8221 | `204` |  | `return new[]`
| 8221 | `205` |  | `{`
| 8221 | `206` |  | `(byte) ((value & 0xFF00000000000000) >> 56),`
| 8221 | `207` |  | `(byte) ((value & 0x00FF000000000000) >> 48),`
| 8221 | `208` |  | `(byte) ((value & 0x0000FF0000000000) >> 40),`
| 8221 | `209` |  | `(byte) ((value & 0x000000FF00000000) >> 32),`
| 8221 | `210` |  | `(byte) ((value & 0x00000000FF000000) >> 24),`
| 8221 | `211` |  | `(byte) ((value & 0x0000000000FF0000) >> 16),`
| 8221 | `212` |  | `(byte) ((value & 0x000000000000FF00) >> 8),`
| 8221 | `213` |  | `(byte) (value & 0x00000000000000FF)`
| 8221 | `214` |  | `};`
| 8221 | `215` |  | `}`
|  | `216` |  | ``
|  | `217` |  | `/// <summary>`
|  | `218` |  | `/// Converts big endian bytes into number.`
|  | `219` |  | `/// </summary>`
|  | `220` |  | `/// <param name="buffer">The buffer.</param>`
|  | `221` |  | `/// <returns>Converted <see cref="ushort" />.</returns>`
|  | `222` |  | `internal static ushort BigEndianToUInt16(byte[] buffer)`
| 97 | `223` |  | `{`
| 97 | `224` |  | `return (ushort) (buffer[0] << 8 | buffer[1]);`
| 97 | `225` |  | `}`
|  | `226` |  | ``
|  | `227` |  | `/// <summary>`
|  | `228` |  | `/// Converts big endian bytes into number.`
|  | `229` |  | `/// </summary>`
|  | `230` |  | `/// <param name="buffer">The buffer.</param>`
|  | `231` |  | `/// <param name="offset">The buffer offset.</param>`
|  | `232` |  | `/// <returns>Converted <see cref="uint" />.</returns>`
|  | `233` |  | `internal static uint BigEndianToUInt32(byte[] buffer, int offset)`
| 13980 | `234` |  | `{`
| 13980 | `235` |  | `return (uint) buffer[offset + 0] << 24 |`
| 13980 | `236` |  | `(uint) buffer[offset + 1] << 16 |`
| 13980 | `237` |  | `(uint) buffer[offset + 2] << 8 |`
| 13980 | `238` |  | `buffer[offset + 3];`
| 13980 | `239` |  | `}`
|  | `240` |  | ``
|  | `241` |  | `/// <summary>`
|  | `242` |  | `/// Converts big endian bytes into number.`
|  | `243` |  | `/// </summary>`
|  | `244` |  | `/// <param name="buffer">The buffer.</param>`
|  | `245` |  | `/// <returns>Converted <see cref="uint" />.</returns>`
|  | `246` |  | `internal static uint BigEndianToUInt32(byte[] buffer)`
| 416495 | `247` |  | `{`
| 416495 | `248` |  | `return (uint) buffer[0] << 24 |`
| 416495 | `249` |  | `(uint) buffer[1] << 16 |`
| 416495 | `250` |  | `(uint) buffer[2] << 8 |`
| 416495 | `251` |  | `buffer[3];`
| 416495 | `252` |  | `}`
|  | `253` |  | ``
|  | `254` |  | `/// <summary>`
|  | `255` |  | `/// Converts big endian bytes into number.`
|  | `256` |  | `/// </summary>`
|  | `257` |  | `/// <param name="buffer">The buffer.</param>`
|  | `258` |  | `/// <returns>Converted <see cref="ulong" />.</returns>`
|  | `259` |  | `internal static ulong BigEndianToUInt64(byte[] buffer)`
| 10817 | `260` |  | `{`
| 10817 | `261` |  | `return (ulong) buffer[0] << 56 |`
| 10817 | `262` |  | `(ulong) buffer[1] << 48 |`
| 10817 | `263` |  | `(ulong) buffer[2] << 40 |`
| 10817 | `264` |  | `(ulong) buffer[3] << 32 |`
| 10817 | `265` |  | `(ulong) buffer[4] << 24 |`
| 10817 | `266` |  | `(ulong) buffer[5] << 16 |`
| 10817 | `267` |  | `(ulong) buffer[6] << 8 |`
| 10817 | `268` |  | `buffer[7];`
| 10817 | `269` |  | `}`
|  | `270` |  | `}`
|  | `271` |  | `}`

# Methods/Properties

LittleEndianToUInt16(System.Byte[])
LittleEndianToUInt32(System.Byte[],System.Int32)
LittleEndianToUInt32(System.Byte[])
LittleEndianToUInt64(System.Byte[])
UInt16ToLittleEndian(System.UInt16)
UInt16ToLittleEndian(System.UInt16,System.Byte[])
UInt32ToLittleEndian(System.UInt32)
UInt32ToLittleEndian(System.UInt32,System.Byte[])
UInt32ToLittleEndian(System.UInt32,System.Byte[],System.Int32)
UInt64ToLittleEndian(System.UInt64)
UInt64ToLittleEndian(System.UInt64,System.Byte[])
UInt16ToBigEndian(System.UInt16)
UInt16ToBigEndian(System.UInt16,System.Byte[])
UInt16ToBigEndian(System.UInt16,System.Byte[],System.Int32)
UInt32ToBigEndian(System.UInt32,System.Byte[])
UInt32ToBigEndian(System.UInt32,System.Byte[],System.Int32)
UInt32ToBigEndian(System.UInt32)
UInt64ToBigEndian(System.UInt64)
BigEndianToUInt16(System.Byte[])
BigEndianToUInt32(System.Byte[],System.Int32)
BigEndianToUInt32(System.Byte[])
BigEndianToUInt64(System.Byte[])