pub struct ServerCookie(/* private fields */);
Expand description
A server cookie for DNS cookies.
In the original specification, the server cookie was of variable length between 8 and 32 octets. It was supposed to be generated via some sort of message authentication code from the client cookie and a server secret. Leaving the concrete mechanism to the implementer resulted in interoperability problems if servers from multiple vendors were placed behind the same public address. Thus, RFC 9018 defined a standard mechanism of the content and generation of the cookie.
This standard server cookie consists of a 1 octet version number (currently 1), 3 reserved octets that must be zero, a 4 octet timestamp as seconds since the Unix epoch, and 8 octets of hash value.
In version 1, the hash is calculated feeding the SipHash-2-4 that has been initialized with a server secret the concatenation of client cookie, version, reserved, timestamp, client IP address.
Implementations§
Source§impl ServerCookie
impl ServerCookie
Sourcepub fn from_octets(slice: &[u8]) -> Self
pub fn from_octets(slice: &[u8]) -> Self
Creates a new server cookie from the given octets.
§Panics
The function panics if octets
is shorter than 8 octets or longer
than 32.
Sourcepub fn parse<Octs: AsRef<[u8]> + ?Sized>(
parser: &mut Parser<'_, Octs>,
) -> Result<Self, ParseError>
pub fn parse<Octs: AsRef<[u8]> + ?Sized>( parser: &mut Parser<'_, Octs>, ) -> Result<Self, ParseError>
Parses a server cookie from its wire format.
Sourcepub fn parse_opt<Octs: AsRef<[u8]> + ?Sized>(
parser: &mut Parser<'_, Octs>,
) -> Result<Option<Self>, ParseError>
pub fn parse_opt<Octs: AsRef<[u8]> + ?Sized>( parser: &mut Parser<'_, Octs>, ) -> Result<Option<Self>, ParseError>
Parses an optional server cookie from its wire format.
Sourcepub fn try_to_standard(&self) -> Option<StandardServerCookie>
pub fn try_to_standard(&self) -> Option<StandardServerCookie>
Converts the cookie into a standard cookie if possible.
This is possible if the length of the cookie is 16 octets. Returns
None
otherwise.
Sourcepub fn compose_len(&self) -> u16
pub fn compose_len(&self) -> u16
Returns the length of the wire format of the cookie.
Sourcepub fn compose<Target: OctetsBuilder + ?Sized>(
&self,
target: &mut Target,
) -> Result<(), Target::AppendError>
pub fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
Appends the wire format of the cookie to the target.
Trait Implementations§
Source§impl AsRef<[u8]> for ServerCookie
impl AsRef<[u8]> for ServerCookie
Source§impl Clone for ServerCookie
impl Clone for ServerCookie
Source§fn clone(&self) -> ServerCookie
fn clone(&self) -> ServerCookie
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more