Expose signature subpacket length
Several fields are relevant to this feature request:
- The length of a hashed subpacket area
- The length of an unhashed subpacket area
- The length of a subpacket
For the first two, one could still retrieve the length by calling SubpacketArea::serialized_len, but:
- This has not been made obvious in documentation
- This is not consistent with other fields, which usually have a corresponding getter method (e.g.,
Signature4::pk_algo) - The length so retrieved is not the one originally in the packet, but rather calculated from other parsed fields. The value should (hopefully) be the same, but unnecessary computation occurs
And for the third, one could not retrieve it unless with manual parsing. serialized_len only returns usize, but this field has three different encodings, and that usize does not provide enough information to re-construct the encoding.
A length field, and a corresponding getter could be added to SubpacketArea to expose the first two. Another getter could be added to Subpacket to expose its SubpacketLength, but if that is undesirable, the following data structures could be returned instead:
// (1)
pub enum SubpacketLength {
One(u8),
Two(u8, u8),
Five(u8, u32),
}
// OR
// (2)
pub enum SubpacketLength {
One(u8),
Two(u16),
Five(u32),
}
// OR
// (3)
pub struct SubpacketLength {
pub encoding: SubpacketLengthEncoding,
pub length: u32,
}
pub enum SubpacketLengthEncoding {
One,
Two,
Five,
}
(2) and (3) are IMO less preferable, as downstream crates would need to verify that the length could indeed be encoded in the encoding.
PS: BodyLength also lacks a way for its underlying encoding to be determined, but that encoding can be re-constructed with just the u32 length; a helper function could come in handy though.