public static ByteBlock Process(string PGPFile) { var Root = new ByteBlock(); PGPPacket pgp; PublicKeyPacket PrimaryKeyPacket = null; PublicKeyPacket SubKeyPacket = null; UserIDPacket UIDPacket = null; Stack <OnePassSignaturePacket> OPSigPacketStack = new Stack <OnePassSignaturePacket>(); HashAlgorithm[] HashAlgorithms = null; using (var PacketReader = new PGPReader(PGPFile)) { PacketReader.DoIndexUpdate += IndexUpdate; while ((pgp = PacketReader.ReadNextPacket()) != null) { TreeBuilder Tree = new TreeBuilder(PacketReader); pgp.Parse(Tree); if (pgp is LiteralDataPacket litPgp) { if (HashAlgorithms == null) { HashAlgorithms = GetHashAlgorithms(OPSigPacketStack); } litPgp.ProgressUpdate += StatusUpdate; litPgp.DoHash(PacketReader, HashAlgorithms); } else { if (pgp is OnePassSignaturePacket OPSig) { OPSigPacketStack.Push(OPSig); } else if (pgp.PacketTag == 6 || pgp.PacketTag == 5) { PrimaryKeyPacket = (PublicKeyPacket)pgp; } else if (pgp is UserIDPacket) { UIDPacket = (UserIDPacket)pgp; } else if (pgp.PacketTag == 14 || pgp.PacketTag == 7) { SubKeyPacket = (PublicKeyPacket)pgp; } else if (pgp is SignaturePacket Sig) { if ((Sig.SignatureType == 0x18 || Sig.SignatureType == 0x19) && PrimaryKeyPacket != null && SubKeyPacket != null && SubKeyPacket.PacketDataPublicKey != null) { Sig.GenerateSubKeyBindingHash(PrimaryKeyPacket, SubKeyPacket); } if (Sig.SignatureType >= 0x10 && Sig.SignatureType <= 0x13 && PrimaryKeyPacket != null && UIDPacket != null) { Sig.GenerateCertifyHash(PrimaryKeyPacket, UIDPacket); } // Signature of a Binary Document if (Sig.SignatureType == 0x00) { // Are we generating hash for One Pass Signature Packet if (OPSigPacketStack.Count() > 0) { var OnePassSignaturePacket = OPSigPacketStack.Pop(); if (OnePassSignaturePacket.HashAlgorithm == Sig.HashAlgorithm) { Sig.GenerateBinaryHash(HashAlgorithmTypes.GetHashAlgoManaged(Sig.HashAlgorithm, HashAlgorithms)); } } } } } PacketBlock pb = new PacketBlock(pgp); pb.AddChildBlock(Tree.StartBlock); Root.AddChildBlock(pb); _PacketNodes.Add(pb); } } return(Root.ChildBlock); }