pub struct Crypto {
pub tag: u32,
pub suite: Suite,
pub key_and_salt: Vec<u8>,
}Expand description
One a=crypto line.
Fields§
§tag: u32The tag that identifies this offer among several.
suite: SuiteThe transform.
key_and_salt: Vec<u8>Master key followed by master salt, concatenated as RFC 4568 §6.1 requires.
Implementations§
Source§impl Crypto
impl Crypto
Sourcepub fn offer(tag: u32, suite: Suite, secure_signalling: bool) -> Option<Self>
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.
Sourcepub fn master_key(&self) -> &[u8] ⓘ
pub fn master_key(&self) -> &[u8] ⓘ
The master key half.
Sourcepub fn master_salt(&self) -> &[u8] ⓘ
pub fn master_salt(&self) -> &[u8] ⓘ
The master salt half.
Sourcepub fn parse(value: &str) -> Option<Self>
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.
Sourcepub fn accepting(&self, offered: &Self) -> Option<Self>
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.
Sourcepub fn verify_answer<'o>(
offered: &'o [Self],
answered: Option<&Self>,
) -> Result<&'o Self>
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.