Esempio n. 1
0
        private string GetOcspUrlFromCertificate(X509Certificate cert)
        {
            var derId = new DerObjectIdentifier(X509Extensions.AuthorityInfoAccess.Id);

            byte[] extensionValue = cert.GetExtensionValue(derId).GetOctets();

            Asn1Sequence asn1Seq = (Asn1Sequence)Asn1Object.FromByteArray(extensionValue); // AuthorityInfoAccessSyntax
            // Enumeration <?> objects = asn1Seq.Objects;
            string result = null;

            foreach (Asn1Sequence obj in asn1Seq)
            {
                DerObjectIdentifier oid      = (DerObjectIdentifier)obj[0]; // accessMethod
                DerTaggedObject     location = (DerTaggedObject)obj[1];     // accessLocation

                if (location.TagNo == GeneralName.UniformResourceIdentifier)
                {
                    DerOctetString uri = (DerOctetString)location.GetObject();
                    String         str = Encoding.Default.GetString(uri.GetOctets());
                    if (oid.Equals(X509ObjectIdentifiers.IdADOcsp))
                    {
                        result = str;
                        break;
                    }
                }
            }
            //while (objects.hasMoreElements())
            //{
            //    ASN1Sequence obj = (ASN1Sequence)objects.nextElement(); // AccessDescription
            //}

            return(result);
        }
Esempio n. 2
0
 public OtherInfo(Asn1Sequence seq)
 {
     global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
     enumerator.MoveNext();
     keyInfo = new KeySpecificInfo((Asn1Sequence)enumerator.get_Current());
     while (enumerator.MoveNext())
     {
         DerTaggedObject derTaggedObject = (DerTaggedObject)enumerator.get_Current();
         if (derTaggedObject.TagNo == 0)
         {
             partyAInfo = (Asn1OctetString)derTaggedObject.GetObject();
         }
         else if (derTaggedObject.TagNo == 2)
         {
             suppPubInfo = (Asn1OctetString)derTaggedObject.GetObject();
         }
     }
 }
Esempio n. 3
0
        public OtherInfo(Asn1Sequence seq)
        {
            IEnumerator enumerator = seq.GetEnumerator();

            enumerator.MoveNext();
            this.keyInfo = new KeySpecificInfo((Asn1Sequence)enumerator.Current);
            while (enumerator.MoveNext())
            {
                DerTaggedObject derTaggedObject = (DerTaggedObject)enumerator.Current;
                if (derTaggedObject.TagNo == 0)
                {
                    this.partyAInfo = (Asn1OctetString)derTaggedObject.GetObject();
                }
                else if (derTaggedObject.TagNo == 2)
                {
                    this.suppPubInfo = (Asn1OctetString)derTaggedObject.GetObject();
                }
            }
        }
Esempio n. 4
0
        public OtherInfo(
            Asn1Sequence seq)
        {
            IEnumerator e = seq.GetEnumerator();

            e.MoveNext();
            keyInfo = new KeySpecificInfo((Asn1Sequence)e.Current);

            while (e.MoveNext())
            {
                DerTaggedObject o = (DerTaggedObject)e.Current;

                if (o.TagNo == 0)
                {
                    partyAInfo = (Asn1OctetString)o.GetObject();
                }
                else if ((int)o.TagNo == 2)
                {
                    suppPubInfo = (Asn1OctetString)o.GetObject();
                }
            }
        }
Esempio n. 5
0
        private string GetResponderName(ResponderID responderId, ref bool byKey)
        {
            DerTaggedObject derTaggedObject = (DerTaggedObject)responderId.ToAsn1Object();

            if (derTaggedObject.TagNo != 1)
            {
                if (derTaggedObject.TagNo != 2)
                {
                    return(null);
                }
                Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)responderId.ToAsn1Object();
                Asn1OctetString  asn1OctetString  = (Asn1OctetString)asn1TaggedObject.GetObject();
                byKey = true;
                return(Convert.ToBase64String(asn1OctetString.GetOctets()));
            }
            X509Name instance = X509Name.GetInstance(derTaggedObject.GetObject());

            byKey = false;
            return(instance.ToString());
        }
        private string GetResponderName(ResponderID responderId, ref bool byKey)
        {
            DerTaggedObject dt = (DerTaggedObject)responderId.ToAsn1Object();

            if (dt.TagNo == 1)
            {
                byKey = false;

                return(new X500DistinguishedName(dt.GetObject().GetEncoded()).Name);
            }
            else if (dt.TagNo == 2)
            {
                Asn1TaggedObject tagger  = (Asn1TaggedObject)responderId.ToAsn1Object();
                Asn1OctetString  pubInfo = (Asn1OctetString)tagger.GetObject();
                byKey = true;

                return(Convert.ToBase64String(pubInfo.GetOctets()));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        /**
         * dump a Der object as a formatted string with indentation
         *
         * @param obj the Asn1Object to be dumped out.
         */
        private static void AsString(
            string indent,
            bool verbose,
            Asn1Object obj,
            StringBuilder buf)
        {
            if (obj is Asn1Sequence)
            {
                string tab = indent + Tab;
                buf.Append(indent);
                if (obj is BerSequence)
                {
                    buf.Append("BER Sequence");
                }
                else if (obj is DerSequence)
                {
                    buf.Append("DER Sequence");
                }
                else
                {
                    buf.Append("Sequence");
                }

                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Sequence)obj))
                {
                    if (o == null || o is Asn1Null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        AsString(tab, verbose, o.ToAsn1Object(), buf);
                    }
                }
            }
            else if (obj is DerTaggedObject)
            {
                string tab = indent + Tab;
                buf.Append(indent);
                if (obj is BerTaggedObject)
                {
                    buf.Append("BER Tagged [");
                }
                else
                {
                    buf.Append("Tagged [");
                }

                DerTaggedObject o = (DerTaggedObject)obj;

                buf.Append(((int)o.TagNo).ToString());
                buf.Append(']');

                if (!o.IsExplicit())
                {
                    buf.Append(" IMPLICIT ");
                }

                buf.Append(NewLine);

                if (o.IsEmpty())
                {
                    buf.Append(tab);
                    buf.Append("EMPTY");
                    buf.Append(NewLine);
                }
                else
                {
                    AsString(tab, verbose, o.GetObject(), buf);
                }
            }
            else if (obj is BerSet)
            {
                string tab = indent + Tab;

                buf.Append(indent);
                buf.Append("BER Set");
                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        AsString(tab, verbose, o.ToAsn1Object(), buf);
                    }
                }
            }
            else if (obj is DerSet)
            {
                string tab = indent + Tab;

                buf.Append(indent);
                buf.Append("DER Set");
                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        AsString(tab, verbose, o.ToAsn1Object(), buf);
                    }
                }
            }
            else if (obj is DerObjectIdentifier)
            {
                buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine);
            }
            else if (obj is DerBoolean)
            {
                buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine);
            }
            else if (obj is DerInteger)
            {
                buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine);
            }
            else if (obj is BerOctetString)
            {
                byte[] octets = ((Asn1OctetString)obj).GetOctets();
                string extra  = verbose ? dumpBinaryDataAsString(indent, octets) : "";
                buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
            }
            else if (obj is DerOctetString)
            {
                byte[] octets = ((Asn1OctetString)obj).GetOctets();
                string extra  = verbose ? dumpBinaryDataAsString(indent, octets) : "";
                buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
            }
            else if (obj is DerBitString)
            {
                DerBitString bt    = (DerBitString)obj;
                byte[]       bytes = bt.GetBytes();
                string       extra = verbose ? dumpBinaryDataAsString(indent, bytes) : "";
                buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine);
            }
            else if (obj is DerIA5String)
            {
                buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerUtf8String)
            {
                buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerPrintableString)
            {
                buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerVisibleString)
            {
                buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerBmpString)
            {
                buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerT61String)
            {
                buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerUtcTime)
            {
                buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine);
            }
            else if (obj is DerGeneralizedTime)
            {
                buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine);
            }
            else if (obj is DerUnknownTag)
            {
                string hex = Hex.ToHexString(((DerUnknownTag)obj).GetData());
                buf.Append(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + hex + NewLine);
            }
            else if (obj is BerApplicationSpecific)
            {
                buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
            }
            else if (obj is DerApplicationSpecific)
            {
                buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
            }
            else if (obj is DerEnumerated)
            {
                DerEnumerated en = (DerEnumerated)obj;
                buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine);
            }
            else if (obj is DerExternal)
            {
                DerExternal ext = (DerExternal)obj;
                buf.Append(indent + "External " + NewLine);
                string tab = indent + Tab;

                if (ext.DirectReference != null)
                {
                    buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine);
                }
                if (ext.IndirectReference != null)
                {
                    buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine);
                }
                if (ext.DataValueDescriptor != null)
                {
                    AsString(tab, verbose, ext.DataValueDescriptor, buf);
                }
                buf.Append(tab + "Encoding: " + ext.Encoding + NewLine);
                AsString(tab, verbose, ext.ExternalContent, buf);
            }
            else
            {
                buf.Append(indent + obj.ToString() + NewLine);
            }
        }
Esempio n. 8
0
        /// <summary>Gives back the CRL URI meta-data found within the given X509 certificate.
        ///     </summary>
        /// <remarks>Gives back the CRL URI meta-data found within the given X509 certificate.
        ///     </remarks>
        /// <param name="certificate">the X509 certificate.</param>
        /// <returns>the CRL URI, or <code>null</code> if the extension is not present.</returns>
        /// <exception cref="System.UriFormatException">System.UriFormatException</exception>
        public virtual string GetCrlUri(X509Certificate certificate)
        {
            //byte[] crlDistributionPointsValue = certificate.GetExtensionValue(X509Extensions.
            //    CrlDistributionPoints);
            Asn1OctetString crlDistributionPointsValue = certificate.GetExtensionValue(X509Extensions.
                                                                                       CrlDistributionPoints);

            if (null == crlDistributionPointsValue)
            {
                return(null);
            }
            Asn1Sequence seq;

            try
            {
                DerOctetString oct;
                //oct = (DEROctetString)(new ASN1InputStream(new ByteArrayInputStream(crlDistributionPointsValue
                //    )).ReadObject());
                oct = (DerOctetString)crlDistributionPointsValue;
                seq = (Asn1Sequence) new Asn1InputStream(oct.GetOctets()).ReadObject();
            }
            catch (IOException e)
            {
                throw new RuntimeException("IO error: " + e.Message, e);
            }
            CrlDistPoint distPoint = CrlDistPoint.GetInstance(seq);

            DistributionPoint[] distributionPoints = distPoint.GetDistributionPoints();
            foreach (DistributionPoint distributionPoint in distributionPoints)
            {
                DistributionPointName distributionPointName = distributionPoint.DistributionPointName;
                if (DistributionPointName.FullName != distributionPointName.PointType)
                {
                    continue;
                }
                GeneralNames  generalNames = (GeneralNames)distributionPointName.Name;
                GeneralName[] names        = generalNames.GetNames();
                foreach (GeneralName name in names)
                {
                    if (name.TagNo != GeneralName.UniformResourceIdentifier)
                    {
                        LOG.Info("not a uniform resource identifier");
                        continue;
                    }
                    string str = null;
                    if (name.ToAsn1Object() is DerTaggedObject)
                    {
                        DerTaggedObject taggedObject = (DerTaggedObject)name.ToAsn1Object();
                        DerIA5String    derStr       = DerIA5String.GetInstance(taggedObject.GetObject());
                        str = derStr.GetString();
                    }
                    else
                    {
                        DerIA5String derStr = DerIA5String.GetInstance(name.ToAsn1Object());
                        str = derStr.GetString();
                    }
                    if (str != null && (str.StartsWith("http://") || str.StartsWith("https://")) &&
                        str.ToUpperInvariant().Contains("CRL"))    //jbonilla - El URL del CRL para el BCE está en la tercera posición y solo se puede acceder desde HTTP.
                    {
                        return(str);
                    }
                    else
                    {
                        LOG.Info("Supports only http:// and https:// protocol for CRL");
                    }
                }
            }

            //jbonilla
            #region BCE
            if (certificate.SubjectDN.ToString()
                .Contains("AC BANCO CENTRAL DEL ECUADOR"))
            {
                return(this.IntermediateAcUrl);
            }
            #endregion

            return(null);
        }
Esempio n. 9
0
 private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf)
 {
     if (obj is Asn1Sequence)
     {
         string text = indent + "    ";
         buf.Append(indent);
         if (obj is BerSequence)
         {
             buf.Append("BER Sequence");
         }
         else if (obj is DerSequence)
         {
             buf.Append("DER Sequence");
         }
         else
         {
             buf.Append("Sequence");
         }
         buf.Append(NewLine);
         foreach (Asn1Encodable item in (Asn1Sequence)obj)
         {
             if (item == null || item is Asn1Null)
             {
                 buf.Append(text);
                 buf.Append("NULL");
                 buf.Append(NewLine);
             }
             else
             {
                 AsString(text, verbose, item.ToAsn1Object(), buf);
             }
         }
     }
     else if (obj is DerTaggedObject)
     {
         string text2 = indent + "    ";
         buf.Append(indent);
         if (obj is BerTaggedObject)
         {
             buf.Append("BER Tagged [");
         }
         else
         {
             buf.Append("Tagged [");
         }
         DerTaggedObject derTaggedObject = (DerTaggedObject)obj;
         buf.Append(derTaggedObject.TagNo.ToString());
         buf.Append(']');
         if (!derTaggedObject.IsExplicit())
         {
             buf.Append(" IMPLICIT ");
         }
         buf.Append(NewLine);
         if (derTaggedObject.IsEmpty())
         {
             buf.Append(text2);
             buf.Append("EMPTY");
             buf.Append(NewLine);
         }
         else
         {
             AsString(text2, verbose, derTaggedObject.GetObject(), buf);
         }
     }
     else if (obj is BerSet)
     {
         string text3 = indent + "    ";
         buf.Append(indent);
         buf.Append("BER Set");
         buf.Append(NewLine);
         foreach (Asn1Encodable item2 in (Asn1Set)obj)
         {
             if (item2 == null)
             {
                 buf.Append(text3);
                 buf.Append("NULL");
                 buf.Append(NewLine);
             }
             else
             {
                 AsString(text3, verbose, item2.ToAsn1Object(), buf);
             }
         }
     }
     else if (obj is DerSet)
     {
         string text4 = indent + "    ";
         buf.Append(indent);
         buf.Append("DER Set");
         buf.Append(NewLine);
         foreach (Asn1Encodable item3 in (Asn1Set)obj)
         {
             if (item3 == null)
             {
                 buf.Append(text4);
                 buf.Append("NULL");
                 buf.Append(NewLine);
             }
             else
             {
                 AsString(text4, verbose, item3.ToAsn1Object(), buf);
             }
         }
     }
     else if (obj is DerObjectIdentifier)
     {
         buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine);
     }
     else if (obj is DerBoolean)
     {
         buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine);
     }
     else if (obj is DerInteger)
     {
         buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine);
     }
     else if (obj is BerOctetString)
     {
         byte[] octets = ((Asn1OctetString)obj).GetOctets();
         string text5  = verbose ? dumpBinaryDataAsString(indent, octets) : "";
         buf.Append(indent + "BER Octet String[" + octets.Length + "] " + text5 + NewLine);
     }
     else if (obj is DerOctetString)
     {
         byte[] octets2 = ((Asn1OctetString)obj).GetOctets();
         string text6   = verbose ? dumpBinaryDataAsString(indent, octets2) : "";
         buf.Append(indent + "DER Octet String[" + octets2.Length + "] " + text6 + NewLine);
     }
     else if (obj is DerBitString)
     {
         DerBitString derBitString = (DerBitString)obj;
         byte[]       bytes        = derBitString.GetBytes();
         string       text7        = verbose ? dumpBinaryDataAsString(indent, bytes) : "";
         buf.Append(indent + "DER Bit String[" + bytes.Length + ", " + derBitString.PadBits + "] " + text7 + NewLine);
     }
     else if (obj is DerIA5String)
     {
         buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerUtf8String)
     {
         buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerPrintableString)
     {
         buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerVisibleString)
     {
         buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerBmpString)
     {
         buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerT61String)
     {
         buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerGraphicString)
     {
         buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerVideotexString)
     {
         buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine);
     }
     else if (obj is DerUtcTime)
     {
         buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine);
     }
     else if (obj is DerGeneralizedTime)
     {
         buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine);
     }
     else if (obj is BerApplicationSpecific)
     {
         buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
     }
     else if (obj is DerApplicationSpecific)
     {
         buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
     }
     else if (obj is DerEnumerated)
     {
         DerEnumerated derEnumerated = (DerEnumerated)obj;
         buf.Append(indent + "DER Enumerated(" + derEnumerated.Value + ")" + NewLine);
     }
     else if (obj is DerExternal)
     {
         DerExternal derExternal = (DerExternal)obj;
         buf.Append(indent + "External " + NewLine);
         string text8 = indent + "    ";
         if (derExternal.DirectReference != null)
         {
             buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + NewLine);
         }
         if (derExternal.IndirectReference != null)
         {
             buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + NewLine);
         }
         if (derExternal.DataValueDescriptor != null)
         {
             AsString(text8, verbose, derExternal.DataValueDescriptor, buf);
         }
         buf.Append(text8 + "Encoding: " + derExternal.Encoding + NewLine);
         AsString(text8, verbose, derExternal.ExternalContent, buf);
     }
     else
     {
         buf.Append(indent + obj.ToString() + NewLine);
     }
 }
        /**
         * dump a Der object as a formatted string with indentation
         *
         * @param obj the Asn1Object to be dumped out.
         */
        private static string AsString(
            string indent,
            bool verbose,
            Asn1Object obj)
        {
            if (obj is Asn1Sequence)
            {
                StringBuilder buf = new StringBuilder(indent);

                string tab = indent + Tab;

                if (obj is BerSequence)
                {
                    buf.Append("BER Sequence");
                }
                else if (obj is DerSequence)
                {
                    buf.Append("DER Sequence");
                }
                else
                {
                    buf.Append("Sequence");
                }

                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Sequence)obj))
                {
                    if (o == null || o is Asn1Null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        buf.Append(AsString(tab, verbose, o.ToAsn1Object()));
                    }
                }
                return(buf.ToString());
            }
            else if (obj is DerTaggedObject)
            {
                StringBuilder buf = new StringBuilder();
                string        tab = indent + Tab;

                buf.Append(indent);
                if (obj is BerTaggedObject)
                {
                    buf.Append("BER Tagged [");
                }
                else
                {
                    buf.Append("Tagged [");
                }

                DerTaggedObject o = (DerTaggedObject)obj;

                buf.Append(((int)o.TagNo).ToString());
                buf.Append(']');

                if (!o.IsExplicit())
                {
                    buf.Append(" IMPLICIT ");
                }

                buf.Append(NewLine);

                if (o.IsEmpty())
                {
                    buf.Append(tab);
                    buf.Append("EMPTY");
                    buf.Append(NewLine);
                }
                else
                {
                    buf.Append(AsString(tab, verbose, o.GetObject()));
                }

                return(buf.ToString());
            }
            else if (obj is BerSet)
            {
                StringBuilder buf = new StringBuilder();
                string        tab = indent + Tab;

                buf.Append(indent);
                buf.Append("BER Set");
                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        buf.Append(AsString(tab, verbose, o.ToAsn1Object()));
                    }
                }

                return(buf.ToString());
            }
            else if (obj is DerSet)
            {
                StringBuilder buf = new StringBuilder();
                string        tab = indent + Tab;

                buf.Append(indent);
                buf.Append("DER Set");
                buf.Append(NewLine);

                foreach (Asn1Encodable o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        buf.Append(tab);
                        buf.Append("NULL");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        buf.Append(AsString(tab, verbose, o.ToAsn1Object()));
                    }
                }

                return(buf.ToString());
            }
            else if (obj is DerObjectIdentifier)
            {
                return(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine);
            }
            else if (obj is DerBoolean)
            {
                return(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine);
            }
            else if (obj is DerInteger)
            {
                return(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine);
            }
            else if (obj is BerOctetString)
            {
                byte[] octets = ((Asn1OctetString)obj).GetOctets();
                string extra  = verbose ? dumpBinaryDataAsString(indent, octets) : "";
                return(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
            }
            else if (obj is DerOctetString)
            {
                byte[] octets = ((Asn1OctetString)obj).GetOctets();
                string extra  = verbose ? dumpBinaryDataAsString(indent, octets) : "";
                return(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine);
            }
            else if (obj is DerBitString)
            {
                DerBitString bt    = (DerBitString)obj;
                byte[]       bytes = bt.GetBytes();
                string       extra = verbose ? dumpBinaryDataAsString(indent, bytes) : "";
                return(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine);
            }
            else if (obj is DerIA5String)
            {
                return(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerUtf8String)
            {
                return(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerPrintableString)
            {
                return(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerVisibleString)
            {
                return(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerBmpString)
            {
                return(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerT61String)
            {
                return(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine);
            }
            else if (obj is DerUtcTime)
            {
                return(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine);
            }
            else if (obj is DerGeneralizedTime)
            {
                return(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine);
            }
            else if (obj is DerUnknownTag)
            {
                byte[] hex = Hex.Encode(((DerUnknownTag)obj).GetData());
                return(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " "
                       + Encoding.ASCII.GetString(hex, 0, hex.Length) + NewLine);
            }
            else if (obj is BerApplicationSpecific)
            {
                return(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
            }
            else if (obj is DerApplicationSpecific)
            {
                return(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
            }
            else
            {
                return(indent + obj.ToString() + NewLine);
            }
        }
Esempio n. 11
0
 private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf)
 {
     if (obj is Asn1Sequence)
     {
         string text = indent + "    ";
         buf.Append(indent);
         if (obj is BerSequence)
         {
             buf.Append("BER Sequence");
         }
         else if (obj is DerSequence)
         {
             buf.Append("DER Sequence");
         }
         else
         {
             buf.Append("Sequence");
         }
         buf.Append(Asn1Dump.NewLine);
         using (IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current;
                 if (asn1Encodable == null || asn1Encodable is Asn1Null)
                 {
                     buf.Append(text);
                     buf.Append("NULL");
                     buf.Append(Asn1Dump.NewLine);
                 }
                 else
                 {
                     Asn1Dump.AsString(text, verbose, asn1Encodable.ToAsn1Object(), buf);
                 }
             }
             return;
         }
     }
     if (obj is DerTaggedObject)
     {
         string text2 = indent + "    ";
         buf.Append(indent);
         if (obj is BerTaggedObject)
         {
             buf.Append("BER Tagged [");
         }
         else
         {
             buf.Append("Tagged [");
         }
         DerTaggedObject derTaggedObject = (DerTaggedObject)obj;
         buf.Append(derTaggedObject.TagNo.ToString());
         buf.Append(']');
         if (!derTaggedObject.IsExplicit())
         {
             buf.Append(" IMPLICIT ");
         }
         buf.Append(Asn1Dump.NewLine);
         if (derTaggedObject.IsEmpty())
         {
             buf.Append(text2);
             buf.Append("EMPTY");
             buf.Append(Asn1Dump.NewLine);
             return;
         }
         Asn1Dump.AsString(text2, verbose, derTaggedObject.GetObject(), buf);
         return;
     }
     else
     {
         if (obj is BerSet)
         {
             string text3 = indent + "    ";
             buf.Append(indent);
             buf.Append("BER Set");
             buf.Append(Asn1Dump.NewLine);
             using (IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator())
             {
                 while (enumerator2.MoveNext())
                 {
                     Asn1Encodable asn1Encodable2 = (Asn1Encodable)enumerator2.Current;
                     if (asn1Encodable2 == null)
                     {
                         buf.Append(text3);
                         buf.Append("NULL");
                         buf.Append(Asn1Dump.NewLine);
                     }
                     else
                     {
                         Asn1Dump.AsString(text3, verbose, asn1Encodable2.ToAsn1Object(), buf);
                     }
                 }
                 return;
             }
         }
         if (obj is DerSet)
         {
             string text4 = indent + "    ";
             buf.Append(indent);
             buf.Append("DER Set");
             buf.Append(Asn1Dump.NewLine);
             using (IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator())
             {
                 while (enumerator3.MoveNext())
                 {
                     Asn1Encodable asn1Encodable3 = (Asn1Encodable)enumerator3.Current;
                     if (asn1Encodable3 == null)
                     {
                         buf.Append(text4);
                         buf.Append("NULL");
                         buf.Append(Asn1Dump.NewLine);
                     }
                     else
                     {
                         Asn1Dump.AsString(text4, verbose, asn1Encodable3.ToAsn1Object(), buf);
                     }
                 }
                 return;
             }
         }
         if (obj is DerObjectIdentifier)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "ObjectIdentifier(",
                 ((DerObjectIdentifier)obj).Id,
                 ")",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerBoolean)
         {
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "Boolean(",
                 ((DerBoolean)obj).IsTrue,
                 ")",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerInteger)
         {
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "Integer(",
                 ((DerInteger)obj).Value,
                 ")",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is BerOctetString)
         {
             byte[] octets = ((Asn1OctetString)obj).GetOctets();
             string text5  = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets) : "";
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "BER Octet String[",
                 octets.Length,
                 "] ",
                 text5,
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerOctetString)
         {
             byte[] octets2 = ((Asn1OctetString)obj).GetOctets();
             string text6   = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets2) : "";
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "DER Octet String[",
                 octets2.Length,
                 "] ",
                 text6,
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerBitString)
         {
             DerBitString derBitString = (DerBitString)obj;
             byte[]       bytes        = derBitString.GetBytes();
             string       text7        = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, bytes) : "";
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "DER Bit String[",
                 bytes.Length,
                 ", ",
                 derBitString.PadBits,
                 "] ",
                 text7,
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerIA5String)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "IA5String(",
                 ((DerIA5String)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerUtf8String)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "UTF8String(",
                 ((DerUtf8String)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerPrintableString)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "PrintableString(",
                 ((DerPrintableString)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerVisibleString)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "VisibleString(",
                 ((DerVisibleString)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerBmpString)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "BMPString(",
                 ((DerBmpString)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerT61String)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "T61String(",
                 ((DerT61String)obj).GetString(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerUtcTime)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "UTCTime(",
                 ((DerUtcTime)obj).TimeString,
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerGeneralizedTime)
         {
             buf.Append(string.Concat(new string[]
             {
                 indent,
                 "GeneralizedTime(",
                 ((DerGeneralizedTime)obj).GetTime(),
                 ") ",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is BerApplicationSpecific)
         {
             buf.Append(Asn1Dump.outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
             return;
         }
         if (obj is DerApplicationSpecific)
         {
             buf.Append(Asn1Dump.outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
             return;
         }
         if (obj is DerEnumerated)
         {
             DerEnumerated derEnumerated = (DerEnumerated)obj;
             buf.Append(string.Concat(new object[]
             {
                 indent,
                 "DER Enumerated(",
                 derEnumerated.Value,
                 ")",
                 Asn1Dump.NewLine
             }));
             return;
         }
         if (obj is DerExternal)
         {
             DerExternal derExternal = (DerExternal)obj;
             buf.Append(indent + "External " + Asn1Dump.NewLine);
             string text8 = indent + "    ";
             if (derExternal.DirectReference != null)
             {
                 buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + Asn1Dump.NewLine);
             }
             if (derExternal.IndirectReference != null)
             {
                 buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + Asn1Dump.NewLine);
             }
             if (derExternal.DataValueDescriptor != null)
             {
                 Asn1Dump.AsString(text8, verbose, derExternal.DataValueDescriptor, buf);
             }
             buf.Append(string.Concat(new object[]
             {
                 text8,
                 "Encoding: ",
                 derExternal.Encoding,
                 Asn1Dump.NewLine
             }));
             Asn1Dump.AsString(text8, verbose, derExternal.ExternalContent, buf);
             return;
         }
         buf.Append(indent + obj.ToString() + Asn1Dump.NewLine);
     }
 }
Esempio n. 12
0
        /**
         * dump a Der object as a formatted string with indentation
         *
         * @param obj the Asn1Object to be dumped out.
         */
        private static string AsString(
            string indent,
            Asn1Object obj)
        {
            if (obj is Asn1Sequence)
            {
                StringBuilder Buffer = new StringBuilder();
                string        tab    = indent + TAB;

                Buffer.Append(indent);
                if (obj is DerSequence)
                {
                    Buffer.Append("DER Sequence");
                }
                else if (obj is BerSequence)
                {
                    Buffer.Append("BER Sequence");
                }
                else
                {
                    Buffer.Append("Sequence");
                }

                Buffer.Append(Environment.NewLine);

                foreach (object o in ((Asn1Sequence)obj))
                {
                    if (o == null || o.Equals(DerNull.Instance))
                    {
                        Buffer.Append(tab);
                        Buffer.Append("Null");
                        Buffer.Append(Environment.NewLine);
                    }
                    else if (o is Asn1Object)
                    {
                        Buffer.Append(AsString(tab, (Asn1Object)o));
                    }
                    else
                    {
                        Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object()));
                    }
                }
                return(Buffer.ToString());
            }
            else if (obj is DerTaggedObject)
            {
                StringBuilder Buffer = new StringBuilder();
                string        tab    = indent + TAB;

                Buffer.Append(indent);
                if (obj is BerTaggedObject)
                {
                    Buffer.Append("BER Tagged [");
                }
                else
                {
                    Buffer.Append("Tagged [");
                }

                DerTaggedObject o = (DerTaggedObject)obj;

                Buffer.Append(((int)o.TagNo).ToString());
                Buffer.Append(']');

                if (!o.IsExplicit())
                {
                    Buffer.Append(" IMPLICIT ");
                }

                Buffer.Append(Environment.NewLine);

                if (o.IsEmpty())
                {
                    Buffer.Append(tab);
                    Buffer.Append("EMPTY");
                    Buffer.Append(Environment.NewLine);
                }
                else
                {
                    Buffer.Append(AsString(tab, o.GetObject()));
                }

                return(Buffer.ToString());
            }
            else if (obj is BerSet)
            {
                StringBuilder Buffer = new StringBuilder();
                string        tab    = indent + TAB;

                Buffer.Append(indent);
                Buffer.Append("BER Set");
                Buffer.Append(Environment.NewLine);

                foreach (object o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        Buffer.Append(tab);
                        Buffer.Append("Null");
                        Buffer.Append(Environment.NewLine);
                    }
                    else if (o is Asn1Object)
                    {
                        Buffer.Append(AsString(tab, (Asn1Object)o));
                    }
                    else
                    {
                        Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object()));
                    }
                }
                return(Buffer.ToString());
            }
            else if (obj is DerSet)
            {
                StringBuilder Buffer = new StringBuilder();
                string        tab    = indent + TAB;

                Buffer.Append(indent);
                Buffer.Append("DER Set");
                Buffer.Append(Environment.NewLine);

                foreach (object o in ((Asn1Set)obj))
                {
                    if (o == null)
                    {
                        Buffer.Append(tab);
                        Buffer.Append("Null");
                        Buffer.Append(Environment.NewLine);
                    }
                    else if (o is Asn1Object)
                    {
                        Buffer.Append(AsString(tab, (Asn1Object)o));
                    }
                    else
                    {
                        Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object()));
                    }
                }

                return(Buffer.ToString());
            }
            else if (obj is DerObjectIdentifier)
            {
                return(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + Environment.NewLine);
            }
            else if (obj is DerBoolean)
            {
                return(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + Environment.NewLine);
            }
            else if (obj is DerInteger)
            {
                return(indent + "Integer(" + ((DerInteger)obj).Value + ")" + Environment.NewLine);
            }
            else if (obj is DerOctetString)
            {
                return(indent + obj.ToString() + "[" + ((Asn1OctetString)obj).GetOctets().Length + "] " + Environment.NewLine);
            }
            else if (obj is DerIA5String)
            {
                return(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + Environment.NewLine);
            }
            else if (obj is DerPrintableString)
            {
                return(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + Environment.NewLine);
            }
            else if (obj is DerVisibleString)
            {
                return(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + Environment.NewLine);
            }
            else if (obj is DerBmpString)
            {
                return(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + Environment.NewLine);
            }
            else if (obj is DerT61String)
            {
                return(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + Environment.NewLine);
            }
            else if (obj is DerUtcTime)
            {
                return(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + Environment.NewLine);
            }
            else if (obj is DerUnknownTag)
            {
                return(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " "
                       + Encoding.ASCII.GetString(Hex.Encode(((DerUnknownTag)obj).GetData())) + Environment.NewLine);
            }
            else
            {
                return(indent + obj.ToString() + Environment.NewLine);
            }
        }
Esempio n. 13
0
        private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf)
        {
            switch (obj)
            {
            case (Asn1Sequence _):
            {
                string str = indent + "    ";
                buf.Append(indent);
                if (obj is BerSequence)
                {
                    buf.Append("BER Sequence");
                }
                else if (obj is DerSequence)
                {
                    buf.Append("DER Sequence");
                }
                else
                {
                    buf.Append("Sequence");
                }
                buf.Append(NewLine);
                IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        Asn1Encodable current = (Asn1Encodable)enumerator.Current;
                        if ((current == null) || (current is Asn1Null))
                        {
                            buf.Append(str);
                            buf.Append("NULL");
                            buf.Append(NewLine);
                        }
                        else
                        {
                            AsString(str, verbose, current.ToAsn1Object(), buf);
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable disposable)
                    {
                        IDisposable disposable;
                        disposable.Dispose();
                    }
                }
                break;
            }

            default:
                if (obj is DerTaggedObject)
                {
                    string str2 = indent + "    ";
                    buf.Append(indent);
                    if (obj is BerTaggedObject)
                    {
                        buf.Append("BER Tagged [");
                    }
                    else
                    {
                        buf.Append("Tagged [");
                    }
                    DerTaggedObject obj2 = (DerTaggedObject)obj;
                    buf.Append(obj2.TagNo.ToString());
                    buf.Append(']');
                    if (!obj2.IsExplicit())
                    {
                        buf.Append(" IMPLICIT ");
                    }
                    buf.Append(NewLine);
                    if (obj2.IsEmpty())
                    {
                        buf.Append(str2);
                        buf.Append("EMPTY");
                        buf.Append(NewLine);
                    }
                    else
                    {
                        AsString(str2, verbose, obj2.GetObject(), buf);
                    }
                }
                else
                {
                    switch (obj)
                    {
                    case (BerSet _):
                    {
                        string str3 = indent + "    ";
                        buf.Append(indent);
                        buf.Append("BER Set");
                        buf.Append(NewLine);
                        IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                Asn1Encodable current = (Asn1Encodable)enumerator2.Current;
                                if (current == null)
                                {
                                    buf.Append(str3);
                                    buf.Append("NULL");
                                    buf.Append(NewLine);
                                }
                                else
                                {
                                    AsString(str3, verbose, current.ToAsn1Object(), buf);
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator2 is IDisposable disposable2)
                            {
                                IDisposable disposable2;
                                disposable2.Dispose();
                            }
                        }
                        break;
                    }

                    default:
                        if (obj is DerSet)
                        {
                            string str4 = indent + "    ";
                            buf.Append(indent);
                            buf.Append("DER Set");
                            buf.Append(NewLine);
                            IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator();
                            try
                            {
                                while (enumerator3.MoveNext())
                                {
                                    Asn1Encodable current = (Asn1Encodable)enumerator3.Current;
                                    if (current == null)
                                    {
                                        buf.Append(str4);
                                        buf.Append("NULL");
                                        buf.Append(NewLine);
                                    }
                                    else
                                    {
                                        AsString(str4, verbose, current.ToAsn1Object(), buf);
                                    }
                                }
                            }
                            finally
                            {
                                if (enumerator3 is IDisposable disposable3)
                                {
                                    IDisposable disposable3;
                                    disposable3.Dispose();
                                }
                            }
                        }
                        else if (obj is DerObjectIdentifier)
                        {
                            buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine);
                        }
                        else if (obj is DerBoolean)
                        {
                            buf.Append(string.Concat(new object[] { indent, "Boolean(", ((DerBoolean)obj).IsTrue, ")", NewLine }));
                        }
                        else if (obj is DerInteger)
                        {
                            buf.Append(string.Concat(new object[] { indent, "Integer(", ((DerInteger)obj).Value, ")", NewLine }));
                        }
                        else if (obj is BerOctetString)
                        {
                            byte[] octets = ((Asn1OctetString)obj).GetOctets();
                            string str5   = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets);
                            buf.Append(string.Concat(new object[] { indent, "BER Octet String[", octets.Length, "] ", str5, NewLine }));
                        }
                        else if (obj is DerOctetString)
                        {
                            byte[] octets = ((Asn1OctetString)obj).GetOctets();
                            string str6   = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets);
                            buf.Append(string.Concat(new object[] { indent, "DER Octet String[", octets.Length, "] ", str6, NewLine }));
                        }
                        else if (obj is DerBitString)
                        {
                            DerBitString str7  = (DerBitString)obj;
                            byte[]       bytes = str7.GetBytes();
                            string       str8  = !verbose ? string.Empty : dumpBinaryDataAsString(indent, bytes);
                            buf.Append(string.Concat(new object[] { indent, "DER Bit String[", bytes.Length, ", ", str7.PadBits, "] ", str8, NewLine }));
                        }
                        else if (obj is DerIA5String)
                        {
                            buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerUtf8String)
                        {
                            buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerPrintableString)
                        {
                            buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerVisibleString)
                        {
                            buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerBmpString)
                        {
                            buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerT61String)
                        {
                            buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerGraphicString)
                        {
                            buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerVideotexString)
                        {
                            buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine);
                        }
                        else if (obj is DerUtcTime)
                        {
                            buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine);
                        }
                        else if (obj is DerGeneralizedTime)
                        {
                            buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine);
                        }
                        else if (obj is BerApplicationSpecific)
                        {
                            buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj));
                        }
                        else if (obj is DerApplicationSpecific)
                        {
                            buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj));
                        }
                        else if (obj is DerEnumerated)
                        {
                            DerEnumerated enumerated = (DerEnumerated)obj;
                            buf.Append(string.Concat(new object[] { indent, "DER Enumerated(", enumerated.Value, ")", NewLine }));
                        }
                        else if (obj is DerExternal)
                        {
                            DerExternal external = (DerExternal)obj;
                            buf.Append(indent + "External " + NewLine);
                            string str9 = indent + "    ";
                            if (external.DirectReference != null)
                            {
                                buf.Append(str9 + "Direct Reference: " + external.DirectReference.Id + NewLine);
                            }
                            if (external.IndirectReference != null)
                            {
                                buf.Append(str9 + "Indirect Reference: " + external.IndirectReference.ToString() + NewLine);
                            }
                            if (external.DataValueDescriptor != null)
                            {
                                AsString(str9, verbose, external.DataValueDescriptor, buf);
                            }
                            buf.Append(string.Concat(new object[] { str9, "Encoding: ", external.Encoding, NewLine }));
                            AsString(str9, verbose, external.ExternalContent, buf);
                        }
                        else
                        {
                            buf.Append(indent + obj.ToString() + NewLine);
                        }
                        break;
                    }
                }
                break;
            }
        }