Exemplo n.º 1
0
        /// <summary>
        /// Converts a ASN.1 Encoded Variable to a System String
        /// </summary>
        /// <returns></returns>
        public override String ToString()
        {
            List <byte> raw      = ToBytes();
            int         position = 0;

            return(BasicEncodingRules.DecodeOctetString(BasicEncodingRules.DecodeOctetString(ref raw, ref position)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a Managed Protocol Data Unit from a List of Byte
        /// </summary>
        /// <param name="Pdu">The List of Byte to Construct a Protocol Data Unit from</param>
        public ProtocolDataUnit(List <byte> SnmpPacket)
        {
            int Pos = 0;
            int End = BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);

            Version       = BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            CommunityName = BasicEncodingRules.DecodeOctetString(BasicEncodingRules.DecodeOctetString(ref SnmpPacket, ref Pos));
            PduType       = (SnmpType)SnmpPacket[Pos];

            BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, PduType);
            RequestId   = (int)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            ErrorStatus = (ErrorStatus)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            ErrorIndex  = (int)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);

            //Gets PDU Length
            int pduLeng = BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);

            if (Pos >= End)
            {
                return;
            }
            Bindings = new List <Variable>();
            while (Pos < End)
            {
                try
                {
                    BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);
                    Bindings.Add(BasicEncodingRules.DecodeSequence(ref SnmpPacket, ref Pos));
                }
                catch
                {
                    throw;
                }
            }
        }