コード例 #1
0
 public Asn1Tag(Asn1.Class asn1Class, int identifier, params Asn1Tag[] subTags)
     : this(asn1Class, true, identifier)
 {
     foreach (Asn1Tag subTag in subTags)
     {
         AddSubTag(subTag);
     }
 }
コード例 #2
0
        /// <summary>
        /// Read an ASN.1 tag identifier from a stream (as specified in X.690)
        /// </summary>
        /// <param name="stream">Stream to read from</param>
        /// <param name="tagClass">Tag class of the tag</param>
        /// <param name="constructed">Indicates if the tag is constructed = true (or primitive = false)</param>
        /// <returns></returns>
        private static int ReadIdentifier(Stream stream, out Asn1.Class tagClass, out bool constructed, out int fullIdentifier, out bool forceMultiByteIdentifier)
        {
            int identifier;
            int b = stream.ReadByte();

            if (b < 0)
            {
                throw new IOException("Unexpected end of ASN.1 data while reading identifier.");
            }

            //  8  7 | 6 | 5  4  3  2  1
            // Class |P/C|   Tag number
            tagClass       = (Asn1.Class)(b >> 6);
            constructed    = (b & 0x20) != 0;
            fullIdentifier = 0;

            if ((b & 0x1f) != 0x1f)
            {
                // Single byte identifier
                identifier               = b & 0x1f;
                fullIdentifier           = b;
                forceMultiByteIdentifier = false;
            }
            else
            {
                // Multi byte identifier
                identifier      = 0;
                fullIdentifier |= b;
                // juse to be sure we force encoding this to multiple bytes to maintain the structue as much as we can
                forceMultiByteIdentifier = true;

                do
                {
                    b = stream.ReadByte();
                    if (b < 0)
                    {
                        throw new IOException("Unexpected end of ASN.1 data while reading multi byte identifier.");
                    }

                    identifier <<= 7; // also happens first time, but that's ok, it's still 0
                    identifier  |= b & 0x7F;

                    fullIdentifier <<= 8;
                    fullIdentifier  |= b;

                    if (identifier == 0)
                    {
                        throw new IOException("Invalid ASN.1 identifier (0 while reading constructed identifier).");
                    }
                } while ((b & 0x80) != 0);
            }

            return(identifier);
        }
コード例 #3
0
        protected internal Asn1Tag(Asn1.Class asn1Class, bool constructed, int identifier)
            : this()
        {
            Class       = asn1Class;
            Constructed = constructed;
            Identifier  = identifier;

            //  8  7 | 6 | 5  4  3  2  1
            // Class |P/C|   Tag number
            FullIdentifier = (((int)asn1Class) << 6) | (constructed ? 0x20 : 0x00) | (identifier & 0x1F);
        }
コード例 #4
0
 public Asn1Tag(Asn1.Class asn1Class, int identifier, byte[] data)
     : this(asn1Class, false, identifier)
 {
     Data = (byte[])data.Clone();
 }