1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use nom::multi::length_data;
use nom::number::streaming::be_u16;
use nom::IResult;
use nom_derive::Nom;

/// Diffie-Hellman parameters, defined in [RFC5246] section 7.4.3
#[derive(PartialEq, Nom)]
pub struct ServerDHParams<'a> {
    /// The prime modulus used for the Diffie-Hellman operation.
    #[nom(Parse = "length_data(be_u16)")]
    pub dh_p: &'a [u8],
    /// The generator used for the Diffie-Hellman operation.
    #[nom(Parse = "length_data(be_u16)")]
    pub dh_g: &'a [u8],
    /// The server's Diffie-Hellman public value (g^X mod p).
    #[nom(Parse = "length_data(be_u16)")]
    pub dh_ys: &'a [u8],
}

#[inline]
pub fn parse_dh_params(i: &[u8]) -> IResult<&[u8], ServerDHParams> {
    ServerDHParams::parse(i)
}