public MimeEntity Decrypt (OpenPgpContext ctx, out DigitalSignatureCollection signatures)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
var protocol = ContentType.Parameters["protocol"];
if (string.IsNullOrEmpty (protocol))
throw new FormatException ();
protocol = protocol.Trim ().ToLowerInvariant ();
if (!ctx.Supports (protocol))
throw new NotSupportedException ();
if (Count < 2)
throw new FormatException ();
var version = this[0] as MimePart;
if (version == null)
throw new FormatException ();
var ctype = version.ContentType;
var value = string.Format ("{0}/{1}", ctype.MediaType, ctype.MediaSubtype);
if (value.ToLowerInvariant () != protocol)
throw new FormatException ();
var encrypted = this[1] as MimePart;
if (encrypted == null || encrypted.ContentObject == null)
throw new FormatException ();
if (!encrypted.ContentType.IsMimeType ("application", "octet-stream"))
throw new FormatException ();
using (var memory = new MemoryBlockStream ()) {
encrypted.ContentObject.DecodeTo (memory);
memory.Position = 0;
return ctx.Decrypt (memory, out signatures);
}
}