Example #1
0
        public OidNode Add(int[] oid, int oidOffset, string description)
        {
            if (oidOffset >= oid.Length)
            {
                throw new ArgumentException("oidOffset cannot be >= oid.Length.");
            }

            int id = oid[oidOffset];

            if (oidOffset == oid.Length - 1)
            { // Final node
                if (SubNodes.ContainsKey(id))
                {
                    throw new ArgumentException(string.Concat("OID ", id, "already present in " + OidString));
                }
            }

            if (!SubNodes.ContainsKey(id))
            {
                OidNode node = new OidNode();
                node.Id        = id;
                node.OidString = OidToString(oid, 0, oid.Length);
                SubNodes.Add(id, node);

                if (oidOffset == oid.Length - 1)
                {
                    node.Description = description;
                    return(node);
                }
            }

            return(SubNodes[id].Add(oid, oidOffset + 1, description));
        }
Example #2
0
        public OidNode Add(int[] oid, int oidOffset, string description)
        {
            if (oidOffset >= oid.Length)
            {
                throw new ArgumentException("oidOffset cannot be >= oid.Length.");
            }

            int id = oid[oidOffset];

            if (oidOffset == oid.Length - 1)
            { // Final node
                if (SubNodes.ContainsKey(id))
                {
                    throw new ArgumentException(string.Concat("OID ", id, "already present in " + OidString));
                }
            }

            if (!SubNodes.ContainsKey(id))
            {
                OidNode node = new OidNode();
                node.Id = id;
                node.OidString = OidToString(oid, 0, oid.Length);
                SubNodes.Add(id, node);

                if (oidOffset == oid.Length - 1)
                {
                    node.Description = description;
                    return node;
                }
            }

            return SubNodes[id].Add(oid, oidOffset + 1, description);
        }
Example #3
0
        private static string GetOidDataString(Asn1Tag tag)
        {
            StringBuilder oidBuf = new StringBuilder();
            bool          first  = true;
            int           value  = 0;

            OidNode oidNode = OidDb;

            for (int i = 0; i < tag.Data.Length; ++i)
            {
                value <<= 7;
                value  |= (tag.Data[i] & 0x7F);

                if ((tag.Data[i] & 0x80) == 0)
                {
                    if (first)
                    {
                        oidBuf.Append(value / 40);
                        oidBuf.Append('.');
                        oidBuf.Append(value % 40);
                        first = false;

                        if (oidNode != null)
                        {
                            oidNode = oidNode.Get(value / 40);
                        }
                        if (oidNode != null)
                        {
                            oidNode = oidNode.Get(value % 40);
                        }
                    }
                    else
                    {
                        oidBuf.Append('.');
                        oidBuf.Append(value);

                        if (oidNode != null)
                        {
                            oidNode = oidNode.Get(value);
                        }
                    }

                    value = 0;
                }
            }

            if (oidNode != null)
            {
                oidBuf.Append(" (").Append(oidNode.Description).Append(")");
            }

            return(oidBuf.ToString());
        }