Пример #1
0
        internal override void encode(
            DEROutputStream derOut)
        {
            if (derOut is ASN1OutputStream || derOut is BEROutputStream)
            {
                derOut.WriteByte((byte)(ASN1Tags.CONSTRUCTED | ASN1Tags.OCTET_STRING));

                derOut.WriteByte(0x80);

                //
                // write out the octet array
                //
                if (octs != null)
                {
                    for (int i = 0; i != octs.Count; i++)
                    {
                        derOut.writeObject(octs[i]);
                    }
                }
                else
                {
                    int start = 0;
                    int end   = 0;

                    while ((end + 1) < str.Length)
                    {
                        if (str[end] == 0 && str[end + 1] == 0)
                        {
                            byte[] nStr = new byte[end - start + 1];

                            Array.Copy(str, start, nStr, 0, nStr.Length);

                            derOut.writeObject(new DEROctetString(nStr));
                            start = end + 1;
                        }
                        end++;
                    }

                    byte[] nStr2 = new byte[str.Length - start];

                    Array.Copy(str, start, nStr2, 0, nStr2.Length);

                    derOut.writeObject(new DEROctetString(nStr2));
                }

                derOut.WriteByte(0x00);
                derOut.WriteByte(0x00);
            }
            else
            {
                base.encode(derOut);
            }
        }
Пример #2
0
        /*
         */
        internal override void encode(
            DEROutputStream derOut)
        {
            if (derOut is ASN1OutputStream || derOut is BEROutputStream)
            {
                derOut.WriteByte((byte)(ASN1Tags.SEQUENCE | ASN1Tags.CONSTRUCTED));
                derOut.WriteByte(0x80);

                IEnumerator e = getObjects();
                while (e.MoveNext())
                {
                    derOut.writeObject(e.Current);
                }

                derOut.WriteByte(0x00);
                derOut.WriteByte(0x00);
            }
            else
            {
                base.encode(derOut);
            }
        }
Пример #3
0
        internal override void encode(
            DEROutputStream derOut)
        {
            if (derOut is ASN1OutputStream || derOut is BEROutputStream)
            {
                derOut.WriteByte((byte)(((int)(ASN1Tags.CONSTRUCTED | ASN1Tags.TAGGED)) | tagNo));
                derOut.WriteByte(0x80);

                if (!empty)
                {
                    if (!explicitly)
                    {
                        if (obj is ASN1OctetString)
                        {
                            IEnumerator e;

                            if (obj is BEROctetString)
                            {
                                e = ((BEROctetString)obj).getObjects();
                            }
                            else
                            {
                                ASN1OctetString octs = (ASN1OctetString)obj;
                                BEROctetString  berO = new BEROctetString(octs.getOctets());

                                e = berO.getObjects();
                            }

                            while (e.MoveNext())
                            {
                                derOut.writeObject(e.Current);
                            }
                        }
                        else if (obj is ASN1Sequence)
                        {
                            IEnumerator e = ((ASN1Sequence)obj).getObjects();

                            while (e.MoveNext())
                            {
                                derOut.writeObject(e.Current);
                            }
                        }
                        else if (obj is ASN1Set)
                        {
                            IEnumerator e = ((ASN1Set)obj).getObjects();

                            while (e.MoveNext())
                            {
                                derOut.writeObject(e.Current);
                            }
                        }
                        else
                        {
                            throw new Exception("not implemented: " + obj.GetType().Name);
                        }
                    }
                    else
                    {
                        derOut.writeObject(obj);
                    }
                }

                derOut.WriteByte(0x00);
                derOut.WriteByte(0x00);
            }
            else
            {
                base.encode(derOut);
            }
        }