Exemplo n.º 1
0
        internal virtual Asn1EncodableVector ReadVector(DefiniteLengthInputStream dIn)
        {
            if (dIn.Remaining < 1)
            {
                return(new Asn1EncodableVector(0));
            }

            Asn1InputStream     subStream = new Asn1InputStream(dIn);
            Asn1EncodableVector v         = new Asn1EncodableVector();
            Asn1Object          o;

            while ((o = subStream.ReadObject()) != null)
            {
                v.Add(o);
            }

            return(v);
        }
Exemplo n.º 2
0
 /// <summary>Create a base ASN.1 object from a byte array.</summary>
 /// <param name="data">The byte array to parse.</param>
 /// <returns>The base ASN.1 object represented by the byte array.</returns>
 /// <exception cref="IOException">
 /// If there is a problem parsing the data, or parsing an object did not exhaust the available data.
 /// </exception>
 public static Asn1Object FromByteArray(
     byte[] data)
 {
     try
     {
         MemoryStream    input  = new MemoryStream(data, false);
         Asn1InputStream asn1   = new Asn1InputStream(input, data.Length);
         Asn1Object      result = asn1.ReadObject();
         if (input.Position != input.Length)
         {
             throw new IOException("extra data found after object");
         }
         return(result);
     }
     catch (InvalidCastException)
     {
         throw new IOException("cannot recognise object in byte array");
     }
 }