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");
}
}