Ejemplo n.º 1
0
        public void EnhancedBlockStream_Byte()
        {
            var es = new EnhancedBlockStream();

            es.WriteByte(77);
            es.WriteByte(99);

            es.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(77, es.ReadByte());
            Assert.AreEqual(99, es.ReadByte());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the packet into a form suitable for transmission via UDP.
        /// </summary>
        /// <returns>The raw packet byte array.</returns>
        public byte[] ToArray()
        {
            var bs = new EnhancedBlockStream(0, 2048);

            bs.WriteByte((byte)this.Code);
            bs.WriteByte((byte)this.Identifier);
            bs.WriteInt16(0);   // Put a zero in for the length and come back and fill
            // this in after we know what the actual length is.

            bs.WriteBytesNoLen(this.Authenticator);

            for (int i = 0; i < this.Attributes.Count; i++)
            {
                var attr = this.Attributes[i];

                if (attr.Value.Length > RadiusAttribute.MaxValueLen)
                {
                    throw new RadiusException("Attribute value size exceeds 253 bytes.");
                }

                bs.WriteByte((byte)attr.Type);
                bs.WriteByte((byte)(attr.Value.Length + 2));
                bs.WriteBytesNoLen(attr.Value);
            }

            // Go back and write the actual length

            if (bs.Length > short.MaxValue)
            {
                throw new RadiusException("RADIUS packet is too large.");
            }

            bs.Position = 2;
            bs.WriteInt16((int)bs.Length);

            return(bs.ToArray());
        }