Represents an attribute of RadiusPacket.
Inheritance: ISupportBinaryImage
Example #1
0
        /// <summary>
        /// Parses <see cref="RadiusPacket"/> object by parsing the specified <paramref name="buffer"/> containing a binary image.
        /// </summary>
        /// <param name="buffer">Buffer containing binary image to parse.</param>
        /// <param name="startIndex">0-based starting index in the <paramref name="buffer"/> to start parsing.</param>
        /// <param name="length">Valid number of bytes within <paramref name="buffer"/> from <paramref name="startIndex"/>.</param>
        /// <returns>The number of bytes used for initialization in the <paramref name="buffer"/> (i.e., the number of bytes parsed), or 0 if not enough data.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
        public int ParseBinaryImage(byte[] buffer, int startIndex, int length)
        {
            if ((object)buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            int imageLength = BinaryLength;

            if (length >= imageLength)
            {
                // Binary image has sufficient data.
                UInt16 size;
                m_type       = (PacketType)(buffer[startIndex]);
                m_identifier = buffer[startIndex + 1];
                size         = EndianOrder.ToUInt16(buffer, startIndex + 2);
                Buffer.BlockCopy(buffer, startIndex + 4, m_authenticator, 0, m_authenticator.Length);

                // Parse all attributes in the packet.
                int cursor = 20;

                while (cursor < size)
                {
                    RadiusPacketAttribute attribute = new RadiusPacketAttribute(buffer, startIndex + cursor, length);
                    m_attributes.Add(attribute);
                    cursor += attribute.BinaryLength;
                }

                return(imageLength);
            }

            // Binary image does not have sufficient data.
            return(0);
        }
Example #2
0
        /// <summary>
        /// Gets the value of the specified <paramref name="attributeType"/> if it is present in the <see cref="RadiusPacket"/>.
        /// </summary>
        /// <param name="attributeType"><see cref="RadiusPacketAttribute.Type"/> of the <see cref="RadiusPacketAttribute"/> whose value is to be retrieved.</param>
        /// <returns><see cref="RadiusPacketAttribute"/>.<see cref="RadiusPacketAttribute.Value"/> if <see cref="RadiusPacketAttribute"/> is present; otherwise null.</returns>
        public byte[] GetAttributeValue(AttributeType attributeType)
        {
            RadiusPacketAttribute match = m_attributes.Find(attribute => attribute.Type == attributeType);

            if (match == null)
            {
                return(null);
            }

            return(match.Value);
        }
        /// <summary>
        /// Parses <see cref="RadiusPacket"/> object by parsing the specified <paramref name="buffer"/> containing a binary image.
        /// </summary>
        /// <param name="buffer">Buffer containing binary image to parse.</param>
        /// <param name="startIndex">0-based starting index in the <paramref name="buffer"/> to start parsing.</param>
        /// <param name="length">Valid number of bytes within <paramref name="buffer"/> from <paramref name="startIndex"/>.</param>
        /// <returns>The number of bytes used for initialization in the <paramref name="buffer"/> (i.e., the number of bytes parsed), or 0 if not enough data.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
        public int ParseBinaryImage(byte[] buffer, int startIndex, int length)
        {
            if ((object)buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            int imageLength = BinaryLength;

            if (length >= imageLength)
            {
                // Binary image has sufficient data.
                UInt16 size;
                m_type = (PacketType)(buffer[startIndex]);
                m_identifier = buffer[startIndex + 1];
                size = EndianOrder.ToUInt16(buffer, startIndex + 2);
                Buffer.BlockCopy(buffer, startIndex + 4, m_authenticator, 0, m_authenticator.Length);

                // Parse all attributes in the packet.
                int cursor = 20;

                while (cursor < size)
                {
                    RadiusPacketAttribute attribute = new RadiusPacketAttribute(buffer, startIndex + cursor, length);
                    m_attributes.Add(attribute);
                    cursor += attribute.BinaryLength;
                }

                return imageLength;
            }

            // Binary image does not have sufficient data.
            return 0;
        }