예제 #1
0
        public Asn1Object(Stream asn1Stream)
        {
            if (!asn1Stream.CanRead)
            {
                throw new ArgumentException("Input data stream must be readable!");
            }

            // Get ID and Length from stream
            identification = new Asn1Tag(asn1Stream);
            length         = new Asn1Length(asn1Stream);

            // Check if has definite length (only kind currently supported)
            if (length.LengthType == Asn1LengthType.LONG_INDEFINITE)
            {
                // Indefinite Length Streams (terminated by EOC)
                throw new ArgumentException("Indefinite length ASN.1 streams are not supported!");
            }
            else
            {
                // Definite length stream
                if (length.Length == 0)
                {
                    contents = null;
                }
                else
                {
                    // Create a new Stream containing just the contents bytes
                    Byte[] bytesRead = new Byte[length.Length];
                    asn1Stream.Read(bytesRead, (Int32)0, (Int32)length.Length);
                    contents = new MemoryStream(bytesRead, false);
                }
            }
        }
예제 #2
0
        public Asn1Object(Stream asn1Stream)
        {
            if (!asn1Stream.CanRead) throw new ArgumentException("Input data stream must be readable!");

              // Get ID and Length from stream
              identification = new Asn1Tag(asn1Stream);
              length = new Asn1Length(asn1Stream);

              // Check if has definite length (only kind currently supported)
              if (length.LengthType == Asn1LengthType.LONG_INDEFINITE)
              {
            // Indefinite Length Streams (terminated by EOC)
            throw new ArgumentException("Indefinite length ASN.1 streams are not supported!");
              }
              else
              {
            // Definite length stream
            if (length.Length == 0)
              contents = null;
            else
            {
              // Create a new Stream containing just the contents bytes
              Byte[] bytesRead = new Byte[length.Length];
              asn1Stream.Read(bytesRead,(Int32)0,(Int32)length.Length);
              contents = new MemoryStream(bytesRead,false);
            }
              }
        }