Skip to main content

Crypto

Struct Crypto 

Source
pub struct Crypto {
    pub tag: u32,
    pub suite: Suite,
    pub key_and_salt: Vec<u8>,
}
Expand description

One a=crypto line.

Fields§

§tag: u32

The tag that identifies this offer among several.

§suite: Suite

The transform.

§key_and_salt: Vec<u8>

Master key followed by master salt, concatenated as RFC 4568 §6.1 requires.

Implementations§

Source§

impl Crypto

Source

pub fn offer(tag: u32, suite: Suite, secure_signalling: bool) -> Option<Self>

A fresh offer, only over a secure signalling path.

None when the signalling is not secure, and that is the point of the signature: RFC 4568 §7.1 makes a secure path a condition of use, and a function that returned a key regardless would leave every caller one forgotten check away from publishing it.

Source

pub fn master_key(&self) -> &[u8]

The master key half.

Source

pub fn master_salt(&self) -> &[u8]

The master salt half.

Source

pub fn parse(value: &str) -> Option<Self>

Read an a=crypto value: <tag> <suite> inline:<base64>[|lifetime][|mki].

None for anything sipx cannot act on — an unknown suite, a key of the wrong length, a key parameter that is not inline:. Returning a half-understood offer would mean answering with a suite that cannot be performed.

Source

pub fn accepting(&self, offered: &Self) -> Option<Self>

This side’s key, presented as the accepted attribute in an answer (RFC 4568 §5.1.2).

The tag and the crypto-suite are the offer’s — §5.1.2 requires the accepted attribute in the answer to “contain … the tag and crypto-suite from the accepted crypto attribute in the offer” — and the key is this side’s own, because each direction is keyed separately (RFC 3711 §3.2).

Answering with a tag of this side’s choosing is not a cosmetic difference. A conformant offerer performs §5.1.3’s check on the way back and MUST fail the negotiation when the tag it sent is not the tag it gets, so an endpoint that always answers 1 interoperates only with peers that happen to have offered 1, and fails with no diagnosis at the end that is wrong.

None when this side’s key cannot be presented under the offered suite — a key of the wrong length for the suite named would be a well-formed answer nobody can decrypt.

Source

pub fn verify_answer<'o>( offered: &'o [Self], answered: Option<&Self>, ) -> Result<&'o Self>

Check an answer against what was offered, and return the offered attribute it accepted (RFC 4568 §5.1.3).

§5.1.3 is a MUST with three parts: the offerer verifies that one of the crypto suites it offered and its accompanying tag were echoed, and that the answer carries a key. “If any of the above fails, the negotiation MUST fail.”

answered is None when the answer carried no a=crypto this side can act on — which is how an answer naming a suite that was never offered arrives, since Crypto::parse refuses a suite sipx cannot perform. That is a failed negotiation and not a call in the clear: a media path that quietly drops to no encryption because the answer disagreed is worse than one that fails, because nothing tells anybody.

What comes back is the offered attribute the answer accepted, so a caller keys with the half it actually sent rather than with whichever of its offers came first.

§Errors

crate::SdpError::Invalid naming the tag, and never the key material: an error string is a log line waiting to happen.

Source

pub fn to_value(&self) -> String

Render as an a=crypto value.

Trait Implementations§

Source§

impl Clone for Crypto

Source§

fn clone(&self) -> Crypto

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Crypto

Source§

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

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

impl PartialEq for Crypto

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Crypto

Source§

impl StructuralPartialEq for Crypto

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,