Org.BouncyCastle.Bcpg.UserAttributeSubpacketsParser.ReadPacket C# (CSharp) Method

ReadPacket() public method

public ReadPacket ( ) : UserAttributeSubpacket
return UserAttributeSubpacket
		public UserAttributeSubpacket ReadPacket()
		{
			int l = input.ReadByte();
			if (l < 0)
				return null;

			int bodyLen = 0;
			if (l < 192)
			{
				bodyLen = l;
			}
			else if (l <= 223)
			{
				bodyLen = ((l - 192) << 8) + (input.ReadByte()) + 192;
			}
			else if (l == 255)
			{
				bodyLen = (input.ReadByte() << 24) | (input.ReadByte() << 16)
					|  (input.ReadByte() << 8)  | input.ReadByte();
			}
			else
			{
				// TODO Error?
			}

			int tag = input.ReadByte();
			if (tag < 0)
				throw new EndOfStreamException("unexpected EOF reading user attribute sub packet");

			byte[] data = new byte[bodyLen - 1];
			if (Streams.ReadFully(input, data) < data.Length)
				throw new EndOfStreamException();

			UserAttributeSubpacketTag type = (UserAttributeSubpacketTag) tag;
			switch (type)
			{
				case UserAttributeSubpacketTag.ImageAttribute:
					return new ImageAttrib(data);
			}
			return new UserAttributeSubpacket(type, data);
		}
	}

Usage Example

        public UserAttributePacket(BcpgInputStream bcpgIn)
        {
            var sIn = new UserAttributeSubpacketsParser(bcpgIn);
            UserAttributeSubpacket sub;

            var v = Platform.CreateArrayList<IUserAttributeSubpacket>();
            while ((sub = sIn.ReadPacket()) != null)
            {
                v.Add(sub);
            }
            _subpackets = v.ToArray();
        }
All Usage Examples Of Org.BouncyCastle.Bcpg.UserAttributeSubpacketsParser::ReadPacket
UserAttributeSubpacketsParser