Esempio n. 1
0
        private static DecodedObjectMeta DecodeIdentifier(byte[] berBytes)
        {
            var decodedMeta = new DecodedObjectMeta();

            var identifierOctet = berBytes[0];

            if ((identifierOctet & 1 << 7) == 0)
            {
                decodedMeta.Class = (identifierOctet & 1 << 6) == 0
                    ? SmiParser.Model.SmiEnums.DataTypeScope.UNIVERSAL
                    : SmiParser.Model.SmiEnums.DataTypeScope.APPLICATION;
            }
            else
            {
                decodedMeta.Class = (identifierOctet & 1 << 6) == 0
                    ? SmiParser.Model.SmiEnums.DataTypeScope.CONTEXT_SPECIFIC
                    : SmiParser.Model.SmiEnums.DataTypeScope.PRIVATE;
            }

            decodedMeta.Constructed = (identifierOctet & 1 << 5) != 0;
            decodedMeta.Tag         = identifierOctet & 31;
            return(decodedMeta);
        }
Esempio n. 2
0
        private static List <DecodedObjectMeta> DecodeObjects(byte[] bytes)
        {
            List <DecodedObjectMeta> decodedList = new List <DecodedObjectMeta>();

            if (bytes.Any())
            {
                DecodedObjectMeta decodedMeta = DecodeIdentifier(bytes);
                DecodeLength(bytes, out var length, out var dataStart);

                decodedMeta.ValueLength = length;
                decodedMeta.ValueBytes  = bytes.Skip(dataStart).Take((int)length).ToArray();

                if (decodedMeta.Constructed)
                {
                    decodedMeta.Children = DecodeObjects(
                        bytes
                        .Skip(dataStart)
                        .Take((int)length)
                        .ToArray()
                        );
                    foreach (DecodedObjectMeta child in decodedMeta.Children)
                    {
                        child.Parent = decodedMeta;
                    }
                }
                else
                {
                    decodedMeta.Children = new List <DecodedObjectMeta>();
                }

                decodedList.Add(decodedMeta);
                byte[] remainingBytes = bytes.Skip(dataStart + (int)length).ToArray();
                decodedList.AddRange(DecodeObjects(remainingBytes));
            }

            return(decodedList);
        }