< Summary

Information
Class: Renci.SshNet.Messages.Connection.ChannelOpenMessage
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Messages\Connection\ChannelOpen\ChannelOpenMessage.cs
Line coverage
100%
Covered lines: 58
Uncovered lines: 0
Coverable lines: 58
Total lines: 154
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_ChannelType()100%1100%
get_LocalChannelNumber()100%1100%
get_InitialWindowSize()100%1100%
get_MaximumPacketSize()100%1100%
get_Info()100%1100%
get_BufferCapacity()100%1100%
.ctor()100%1100%
.ctor(...)100%2100%
LoadData()100%8100%
SaveData()100%1100%
Process(...)100%1100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Messages\Connection\ChannelOpen\ChannelOpenMessage.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace Renci.SshNet.Messages.Connection
 5{
 6    /// <summary>
 7    /// Represents SSH_MSG_CHANNEL_OPEN message.
 8    /// </summary>
 9    [Message("SSH_MSG_CHANNEL_OPEN", MessageNumber)]
 10    public class ChannelOpenMessage : Message
 11    {
 12        internal const byte MessageNumber = 90;
 13
 14        private byte[] _infoBytes;
 15
 16        /// <summary>
 17        /// Gets the type of the channel as ASCII encoded byte array.
 18        /// </summary>
 19        /// <value>
 20        /// The type of the channel.
 21        /// </value>
 582622        public byte[] ChannelType { get; private set; }
 23
 24        /// <summary>
 25        /// Gets or sets the local channel number.
 26        /// </summary>
 27        /// <value>
 28        /// The local channel number.
 29        /// </value>
 439630        public uint LocalChannelNumber { get; protected set; }
 31
 32        /// <summary>
 33        /// Gets the initial size of the window.
 34        /// </summary>
 35        /// <value>
 36        /// The initial size of the window.
 37        /// </value>
 433938        public uint InitialWindowSize { get; private set; }
 39
 40        /// <summary>
 41        /// Gets the maximum size of the packet.
 42        /// </summary>
 43        /// <value>
 44        /// The maximum size of the packet.
 45        /// </value>
 433946        public uint MaximumPacketSize { get; private set; }
 47
 48        /// <summary>
 49        /// Gets channel specific open information.
 50        /// </summary>
 262851        public ChannelOpenInfo Info { get; private set; }
 52
 53        /// <summary>
 54        /// Gets the size of the message in bytes.
 55        /// </summary>
 56        /// <value>
 57        /// The size of the messages in bytes.
 58        /// </value>
 59        protected override int BufferCapacity
 60        {
 61            get
 177962            {
 177963                var capacity = base.BufferCapacity;
 177964                capacity += 4; // ChannelType length
 177965                capacity += ChannelType.Length; // ChannelType
 177966                capacity += 4; // LocalChannelNumber
 177967                capacity += 4; // InitialWindowSize
 177968                capacity += 4; // MaximumPacketSize
 177969                capacity += _infoBytes.Length; // Info
 177970                return capacity;
 177971            }
 72        }
 73
 74        /// <summary>
 75        /// Initializes a new instance of the <see cref="ChannelOpenMessage"/> class.
 76        /// </summary>
 877        public ChannelOpenMessage()
 878        {
 79            // Required for dynamicly loading request type when it comes from the server
 880        }
 81
 82        /// <summary>
 83        /// Initializes a new instance of the <see cref="ChannelOpenMessage"/> class.
 84        /// </summary>
 85        /// <param name="channelNumber">The channel number.</param>
 86        /// <param name="initialWindowSize">Initial size of the window.</param>
 87        /// <param name="maximumPacketSize">Maximum size of the packet.</param>
 88        /// <param name="info">Information specific to the type of the channel to open.</param>
 89        /// <exception cref="ArgumentNullException"><paramref name="info"/> is <see langword="null"/>.</exception>
 219390        public ChannelOpenMessage(uint channelNumber, uint initialWindowSize, uint maximumPacketSize, ChannelOpenInfo in
 219391        {
 219392            if (info == null)
 393            {
 394                throw new ArgumentNullException(nameof(info));
 95            }
 96
 219097            ChannelType = Ascii.GetBytes(info.ChannelType);
 219098            LocalChannelNumber = channelNumber;
 219099            InitialWindowSize = initialWindowSize;
 2190100            MaximumPacketSize = maximumPacketSize;
 2190101            Info = info;
 2190102            _infoBytes = info.GetBytes();
 2190103        }
 104
 105        /// <summary>
 106        /// Called when type specific data need to be loaded.
 107        /// </summary>
 108        protected override void LoadData()
 17109        {
 17110            ChannelType = ReadBinary();
 17111            LocalChannelNumber = ReadUInt32();
 17112            InitialWindowSize = ReadUInt32();
 17113            MaximumPacketSize = ReadUInt32();
 17114            _infoBytes = ReadBytes();
 115
 17116            var channelName = Ascii.GetString(ChannelType, 0, ChannelType.Length);
 117
 17118            switch (channelName)
 119            {
 120                case SessionChannelOpenInfo.Name:
 3121                    Info = new SessionChannelOpenInfo(_infoBytes);
 3122                    break;
 123                case X11ChannelOpenInfo.Name:
 3124                    Info = new X11ChannelOpenInfo(_infoBytes);
 3125                    break;
 126                case DirectTcpipChannelInfo.NAME:
 3127                    Info = new DirectTcpipChannelInfo(_infoBytes);
 3128                    break;
 129                case ForwardedTcpipChannelInfo.NAME:
 5130                    Info = new ForwardedTcpipChannelInfo(_infoBytes);
 5131                    break;
 132                default:
 3133                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Channel type '{0}' is not
 134            }
 14135        }
 136
 137        /// <summary>
 138        /// Called when type specific data need to be saved.
 139        /// </summary>
 140        protected override void SaveData()
 1779141        {
 1779142            WriteBinaryString(ChannelType);
 1779143            Write(LocalChannelNumber);
 1779144            Write(InitialWindowSize);
 1779145            Write(MaximumPacketSize);
 1779146            Write(_infoBytes);
 1779147        }
 148
 149        internal override void Process(Session session)
 2150        {
 2151            session.OnChannelOpenReceived(this);
 2152        }
 153    }
 154}