Пример #1
0
 /**
  * @param explicit true if an explicitly tagged object.
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 public DERTaggedObject(
     bool explicitly,
     int tagNo,
     ASN1Encodable obj)
     : base(explicitly, tagNo, obj)
 {
 }
Пример #2
0
 /**
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 public ASN1TaggedObject(
     int tagNo,
     ASN1Encodable obj)
 {
     this.explicitly = true;
     this.tagNo      = tagNo;
     this.obj        = obj;
 }
Пример #3
0
 /**
  * @param explicit true if the object is explicitly tagged.
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 public ASN1TaggedObject(
     bool explicitly,
     int tagNo,
     ASN1Encodable obj)
 {
     this.explicitly = explicitly;
     this.tagNo      = tagNo;
     this.obj        = obj;
 }
Пример #4
0
        public override bool Equals(
            object o)
        {
            if ((o == null) || !(o is ASN1Encodable))
            {
                return(false);
            }

            ASN1Encodable other = (ASN1Encodable)o;

            return(this.toASN1Object().Equals(other.toASN1Object()));
        }
Пример #5
0
        public DERApplicationSpecific(
            int tag,
            ASN1Encodable obj)
        {
            this.tag = tag | ASN1Tags.CONSTRUCTED;

            MemoryStream    baos = new MemoryStream();
            DEROutputStream dos  = new DEROutputStream(baos);

            dos.writeObject(obj);

            this.octets = baos.ToArray();
        }
Пример #6
0
        protected ASN1OctetString(
            ASN1Encodable obj)
        {
            try
            {
                MemoryStream    bOut = new MemoryStream();
                DEROutputStream dOut = new DEROutputStream(bOut);

                dOut.writeObject(obj);
                dOut.Close();

                this.str = bOut.ToArray();
            }
            catch (IOException e)
            {
                throw new ArgumentException("Error processing object : " + e.ToString());
            }
        }
Пример #7
0
 /**
  * @param tagNo the tag number for this object.
  * @param obj the tagged object.
  */
 public DERTaggedObject(
     int tagNo,
     ASN1Encodable obj)
     : base(tagNo, obj)
 {
 }
Пример #8
0
 /**
  * @param obj - a single object that makes up the set.
  */
 public DERSet(
     ASN1Encodable obj)
 {
     this.addObject(obj);
 }
Пример #9
0
 /**
  * create a sequence containing one object
  */
 public BERSequence(ASN1Encodable obj) : base(obj)
 {
 }
Пример #10
0
 public void add(
     ASN1Encodable obj)
 {
     v.Add(obj);
 }
Пример #11
0
 /**
  * create a set containing one object
  */
 public BERSet(ASN1Encodable obj) : base(obj)
 {
 }
Пример #12
0
 public BEROctetString(ASN1Encodable obj) : base(obj.toASN1Object())
 {
 }
Пример #13
0
 protected void addObject(
     ASN1Encodable obj)
 {
     seq.Add(obj);
 }
Пример #14
0
        /**
         * build an object given its tag and a byte stream to construct it
         * from.
         */
        protected ASN1Object buildObject(
            int derTags,
            byte[]    bytes)
        {
            int tag = derTags;

            if ((tag & ASN1Tags.APPLICATION) != 0)
            {
                return(new DERApplicationSpecific(derTags, bytes));
            }

            switch (tag)
            {
            case ASN1Tags.NULL:
                return(new DERNull());

            case ASN1Tags.SEQUENCE | ASN1Tags.CONSTRUCTED:
                MemoryStream        bIn = new MemoryStream(bytes);
                ASN1InputStream     aIn = new ASN1InputStream(bIn);
                ASN1EncodableVector v   = new ASN1EncodableVector();

                ASN1Object obj = aIn.readObject();

                while (obj != null)
                {
                    v.add(obj);
                    obj = aIn.readObject();
                }

                return(new DERSequence(v));

            case ASN1Tags.SET | ASN1Tags.CONSTRUCTED:
                bIn = new MemoryStream(bytes);
                aIn = new ASN1InputStream(bIn);
                v   = new ASN1EncodableVector();

                obj = aIn.readObject();

                while (obj != null)
                {
                    v.add(obj);
                    obj = aIn.readObject();
                }

                return(new DERSet(v, false));

            case ASN1Tags.BOOLEAN:
                return(new DERBoolean(bytes));

            case ASN1Tags.INTEGER:
                return(new DERInteger(bytes));

            case ASN1Tags.ENUMERATED:
                return(new DEREnumerated(bytes));

            case ASN1Tags.OBJECT_IDENTIFIER:
                return(new DERObjectIdentifier(bytes));

            case ASN1Tags.BIT_STRING:
                int    padBits = bytes[0];
                byte[] data    = new byte[bytes.Length - 1];

                Array.Copy(bytes, 1, data, 0, bytes.Length - 1);

                return(new DERBitString(data, padBits));

            case ASN1Tags.NUMERIC_STRING:
                return(new DERNumericString(bytes));

            case ASN1Tags.UTF8_STRING:
                return(new DERUTF8String(bytes));

            case ASN1Tags.PRINTABLE_STRING:
                return(new DERPrintableString(bytes));

            case ASN1Tags.IA5_STRING:
                return(new DERIA5String(bytes));

            case ASN1Tags.T61_STRING:
                return(new DERT61String(bytes));

            case ASN1Tags.VISIBLE_STRING:
                return(new DERVisibleString(bytes));

            case ASN1Tags.GENERAL_STRING:
                return(new DERGeneralString(bytes));

            case ASN1Tags.UNIVERSAL_STRING:
                return(new DERUniversalString(bytes));

            case ASN1Tags.BMP_STRING:
                return(new DERBMPString(bytes));

            case ASN1Tags.OCTET_STRING:
                return(new DEROctetString(bytes));

            case ASN1Tags.UTC_TIME:
                return(new DERUTCTime(bytes));

            case ASN1Tags.GENERALIZED_TIME:
                return(new DERGeneralizedTime(bytes));

            default:
                //
                // with tagged object tag number is bottom 5 bits
                //
                if ((tag & (int)ASN1Tags.TAGGED) != 0)
                {
                    int tagNo = tag & 0x1f;

                    if (tagNo == 0x1f)
                    {
                        int idx = 0;

                        tagNo = 0;

                        while ((bytes[idx] & 0x80) != 0)
                        {
                            tagNo  |= (bytes[idx++] & 0x7f);
                            tagNo <<= 7;
                        }

                        tagNo |= (bytes[idx] & 0x7f);

                        byte[] tmp = bytes;

                        bytes = new byte[tmp.Length - (idx + 1)];
                        Array.Copy(tmp, idx + 1, bytes, 0, bytes.Length);
                    }

                    if (bytes.Length == 0)        // empty tag!
                    {
                        if ((tag & (int)ASN1Tags.CONSTRUCTED) == 0)
                        {
                            return(new DERTaggedObject(false, tagNo, new DERNull()));
                        }
                        else
                        {
                            return(new DERTaggedObject(false, tagNo, new DERSequence()));
                        }
                    }

                    //
                    // simple type - implicit... return an octet string
                    //
                    if ((tag & (int)ASN1Tags.CONSTRUCTED) == 0)
                    {
                        return(new DERTaggedObject(false, tagNo, new DEROctetString(bytes)));
                    }

                    bIn = new MemoryStream(bytes);
                    aIn = new ASN1InputStream(bIn);

                    ASN1Encodable dObj = aIn.readObject();

                    //
                    // explicitly tagged (probably!) - if it isn't we'd have to
                    // tell from the context
                    //

//                    if (aIn.available() == 0)
                    if (aIn.Position == bytes.Length) //FIXME?
                    {
                        return(new DERTaggedObject(tagNo, dObj));
                    }

                    //
                    // another implicit object, we'll create a sequence...
                    //
                    v = new ASN1EncodableVector();

                    while (dObj != null)
                    {
                        v.add(dObj);
                        dObj = aIn.readObject();
                    }

                    return(new DERTaggedObject(false, tagNo, new DERSequence(v)));
                }

                return(new DERUnknownTag(tag, bytes));
            }
        }