Struct sequoia_openpgp::parse::map::Field
source · pub struct Field<'a> { /* private fields */ }
Expand description
Implementations§
source§impl<'a> Field<'a>
impl<'a> Field<'a>
sourcepub fn name(&self) -> &'a str
pub fn name(&self) -> &'a str
Returns the name of the field.
Note: The returned names are for display purposes only and may change in the future.
Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().name(), "CTB");
assert_eq!(map.iter().nth(1).unwrap().name(), "length");
assert_eq!(map.iter().nth(2).unwrap().name(), "format");
sourcepub fn offset(&self) -> usize
pub fn offset(&self) -> usize
Returns the offset of the field in the packet.
Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().offset(), 0);
assert_eq!(map.iter().nth(1).unwrap().offset(), 1);
assert_eq!(map.iter().nth(2).unwrap().offset(), 2);
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns the value of the field.
Examples
use sequoia_openpgp as openpgp;
use openpgp::parse::{Parse, PacketParserBuilder};
let message_data = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.";
let pp = PacketParserBuilder::from_bytes(message_data)?
.map(true) // Enable mapping.
.build()?
.expect("One packet, not EOF");
let map = pp.map().expect("Mapping is enabled");
assert_eq!(map.iter().nth(0).unwrap().as_bytes(), &[0xcb]);
assert_eq!(map.iter().nth(1).unwrap().as_bytes(), &[0x12]);
assert_eq!(map.iter().nth(2).unwrap().as_bytes(), "t".as_bytes());