Skip to main content

gpg_inspector_lib/packet/
user_id.rs

1//! User ID packet parsing.
2//!
3//! This module parses User ID packets (tag 13), which contain a UTF-8
4//! string identifying the key owner. The typical format is
5//! "Name (Comment) <email@example.com>".
6
7use crate::error::Result;
8use crate::packet::Field;
9use crate::stream::ByteStream;
10
11/// A parsed User ID packet.
12///
13/// Contains a single UTF-8 string identifying the key owner.
14#[derive(Debug, Clone)]
15pub struct UserIdPacket {
16    /// The user ID string (typically "Name \<email\>").
17    pub user_id: String,
18}
19
20/// Parses a User ID packet body.
21pub fn parse_user_id(
22    stream: &mut ByteStream,
23    fields: &mut Vec<Field>,
24    offset: usize,
25) -> Result<UserIdPacket> {
26    let start = offset + stream.pos();
27    let user_id = stream.utf8(stream.remaining())?;
28    let end = offset + stream.pos();
29
30    fields.push(Field::field("User ID", user_id.clone(), (start, end)));
31
32    Ok(UserIdPacket { user_id })
33}