Struct domain::base::opt::cookie::Cookie

source ·
pub struct Cookie { /* private fields */ }
Expand description

Option data for a DNS cookie.

A value of this type carries two parts: A mandatory ClientCookie and an optional ServerCookie. The client cookie is chosen by, yes, the client and added to a request when contacting a specific server for the first time. When responding, a server calculates a server cookie from the client cookie and adds both of them to the response. The client remembers both and includes them in subsequent requests. The server can now check that the the server cookie was indeed calculated by it and treat the repeat customer differently.

While you can create a new cookie using the new method, shortcuts are available for the standard workflow. A new initial cookie can be created via create_initial. As this will be a random client cookie, it needs the rand feature. The server can check whether a received cookie includes a server cookie created by it via the [check_server_hash][Self::check_server_hash] method. It needs the SipHash-2-4 algorithm and is thus available if the siphasher feature is enabled. The same feature also enables the [create_response][Self::create_response] method which creates the server cookie to be included in a response.

Implementations§

source

pub fn new(client: ClientCookie, server: Option<ServerCookie>) -> Self

Creates a new cookie from client and optional server cookie.

source

pub fn client(&self) -> ClientCookie

Returns the client cookie.

source

pub fn server(&self) -> Option<&ServerCookie>

Returns a reference to the server cookie if present.

source

pub fn parse<Octs: AsRef<[u8]> + ?Sized>( parser: &mut Parser<'_, Octs> ) -> Result<Self, ParseError>

Parses the cookie from its wire format.

source

pub fn create_initial() -> Self

Creates a random client cookie for including in an initial request.

Trait Implementations§

source§

fn clone(&self) -> Cookie

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

fn compose_len(&self) -> u16

source§

fn compose_option<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target ) -> Result<(), Target::AppendError>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

fn default() -> Cookie

Returns the “default value” for a type. Read more
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Octs, Name> From<Cookie> for AllOptData<Octs, Name>

source§

fn from(value: Cookie) -> Self

Converts to this type from the input type.
source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

fn code(&self) -> OptionCode

Returns the option code associated with this option.
source§

fn cmp(&self, other: &Cookie) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

fn parse_option( code: OptionCode, parser: &mut Parser<'a, Octs> ) -> Result<Option<Self>, ParseError>

Parses the option code data. Read more
source§

fn eq(&self, other: &Cookie) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

fn partial_cmp(&self, other: &Cookie) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Targetwhere Self::Error: Into<Infallible>,

Performs an infallible conversion.
§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

fn vzip(self) -> V