コード例 #1
0
 internal PublicSubkeyPacket(
     BcpgInputStream bcpgIn)
     : base(bcpgIn)
 {
 }
コード例 #2
0
 /// <param name="bcpgIn">The stream to read the packet from.</param>
 protected ECPublicBcpgKey(
     BcpgInputStream bcpgIn)
 {
     this.oid   = DerObjectIdentifier.GetInstance(Asn1Object.FromByteArray(ReadBytesOfEncodedLength(bcpgIn)));
     this.point = new MPInteger(bcpgIn).Value;
 }
コード例 #3
0
 public UserIdPacket(
     BcpgInputStream bcpgIn)
 {
     this.idData = bcpgIn.ReadAll();
 }
コード例 #4
0
 internal CompressedDataPacket(
     BcpgInputStream bcpgIn)
     : base(bcpgIn)
 {
     this.algorithm = (CompressionAlgorithmTag)bcpgIn.ReadByte();
 }
コード例 #5
0
        public Packet ReadPacket()
        {
            int hdr = this.ReadByte();

            if (hdr < 0)
            {
                return(null);
            }

            if ((hdr & 0x80) == 0)
            {
                throw new IOException("invalid header encountered");
            }

            bool      newPacket = (hdr & 0x40) != 0;
            PacketTag tag       = 0;
            int       bodyLen   = 0;
            bool      partial   = false;

            if (newPacket)
            {
                tag = (PacketTag)(hdr & 0x3f);

                int l = this.ReadByte();

                if (l < 192)
                {
                    bodyLen = l;
                }
                else if (l <= 223)
                {
                    int b = m_in.ReadByte();
                    bodyLen = ((l - 192) << 8) + (b) + 192;
                }
                else if (l == 255)
                {
                    bodyLen = (m_in.ReadByte() << 24) | (m_in.ReadByte() << 16)
                              | (m_in.ReadByte() << 8) | m_in.ReadByte();
                }
                else
                {
                    partial = true;
                    bodyLen = 1 << (l & 0x1f);
                }
            }
            else
            {
                int lengthType = hdr & 0x3;

                tag = (PacketTag)((hdr & 0x3f) >> 2);

                switch (lengthType)
                {
                case 0:
                    bodyLen = this.ReadByte();
                    break;

                case 1:
                    bodyLen = (this.ReadByte() << 8) | this.ReadByte();
                    break;

                case 2:
                    bodyLen = (this.ReadByte() << 24) | (this.ReadByte() << 16)
                              | (this.ReadByte() << 8) | this.ReadByte();
                    break;

                case 3:
                    partial = true;
                    break;

                default:
                    throw new IOException("unknown length type encountered");
                }
            }

            BcpgInputStream objStream;

            if (bodyLen == 0 && partial)
            {
                objStream = this;
            }
            else
            {
                PartialInputStream pis = new PartialInputStream(this, partial, bodyLen);
                objStream = new BcpgInputStream(pis);
            }

            switch (tag)
            {
            case PacketTag.Reserved:
                return(new InputStreamPacket(objStream));

            case PacketTag.PublicKeyEncryptedSession:
                return(new PublicKeyEncSessionPacket(objStream));

            case PacketTag.Signature:
                return(new SignaturePacket(objStream));

            case PacketTag.SymmetricKeyEncryptedSessionKey:
                return(new SymmetricKeyEncSessionPacket(objStream));

            case PacketTag.OnePassSignature:
                return(new OnePassSignaturePacket(objStream));

            case PacketTag.SecretKey:
                return(new SecretKeyPacket(objStream));

            case PacketTag.PublicKey:
                return(new PublicKeyPacket(objStream));

            case PacketTag.SecretSubkey:
                return(new SecretSubkeyPacket(objStream));

            case PacketTag.CompressedData:
                return(new CompressedDataPacket(objStream));

            case PacketTag.SymmetricKeyEncrypted:
                return(new SymmetricEncDataPacket(objStream));

            case PacketTag.Marker:
                return(new MarkerPacket(objStream));

            case PacketTag.LiteralData:
                return(new LiteralDataPacket(objStream));

            case PacketTag.Trust:
                return(new TrustPacket(objStream));

            case PacketTag.UserId:
                return(new UserIdPacket(objStream));

            case PacketTag.UserAttribute:
                return(new UserAttributePacket(objStream));

            case PacketTag.PublicSubkey:
                return(new PublicSubkeyPacket(objStream));

            case PacketTag.SymmetricEncryptedIntegrityProtected:
                return(new SymmetricEncIntegrityPacket(objStream));

            case PacketTag.ModificationDetectionCode:
                return(new ModDetectionCodePacket(objStream));

            case PacketTag.Experimental1:
            case PacketTag.Experimental2:
            case PacketTag.Experimental3:
            case PacketTag.Experimental4:
                return(new ExperimentalPacket(tag, objStream));

            default:
                throw new IOException("unknown packet type encountered: " + tag);
            }
        }