sas: Allow to just get the emoji index instead of the emoji and descryption
parent
80d01b23c4
commit
1bda3659ce
|
@ -436,6 +436,43 @@ pub fn get_emoji(
|
||||||
bytes_to_emoji(bytes)
|
bytes_to_emoji(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the index of the emoji of the short authentication string.
|
||||||
|
///
|
||||||
|
/// Returns seven u8 numbers in the range from 0 to 63 inclusive, those numbers
|
||||||
|
/// can be converted to a unique emoji defined by the spec using the
|
||||||
|
/// [emoji_from_index](#method.emoji_from_index) method.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `sas` - The Olm SAS object that can be used to generate bytes using the
|
||||||
|
/// shared secret.
|
||||||
|
///
|
||||||
|
/// * `ids` - The ids that are used for this SAS authentication flow.
|
||||||
|
///
|
||||||
|
/// * `flow_id` - The unique id that identifies this SAS verification process.
|
||||||
|
///
|
||||||
|
/// * `we_started` - Flag signaling if the SAS process was started on our side.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This will panic if the public key of the other side wasn't set.
|
||||||
|
pub fn get_emoji_index(
|
||||||
|
sas: &OlmSas,
|
||||||
|
ids: &SasIds,
|
||||||
|
their_pubkey: &str,
|
||||||
|
flow_id: &str,
|
||||||
|
we_started: bool,
|
||||||
|
) -> [u8; 7] {
|
||||||
|
let bytes = sas
|
||||||
|
.generate_bytes(
|
||||||
|
&extra_info_sas(&ids, &sas.public_key(), their_pubkey, &flow_id, we_started),
|
||||||
|
6,
|
||||||
|
)
|
||||||
|
.expect("Can't generate bytes");
|
||||||
|
|
||||||
|
bytes_to_emoji_index(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
fn bytes_to_emoji_index(bytes: Vec<u8>) -> [u8; 7] {
|
fn bytes_to_emoji_index(bytes: Vec<u8>) -> [u8; 7] {
|
||||||
let bytes: Vec<u64> = bytes.iter().map(|b| *b as u64).collect();
|
let bytes: Vec<u64> = bytes.iter().map(|b| *b as u64).collect();
|
||||||
// Join the 6 bytes into one 64 bit unsigned int. This u64 will contain 48
|
// Join the 6 bytes into one 64 bit unsigned int. This u64 will contain 48
|
||||||
|
|
|
@ -351,6 +351,14 @@ impl InnerSas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn emoji_index(&self) -> Option<[u8; 7]> {
|
||||||
|
match self {
|
||||||
|
InnerSas::KeyRecieved(s) => Some(s.get_emoji_index()),
|
||||||
|
InnerSas::MacReceived(s) => Some(s.get_emoji_index()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn decimals(&self) -> Option<(u16, u16, u16)> {
|
pub fn decimals(&self) -> Option<(u16, u16, u16)> {
|
||||||
match self {
|
match self {
|
||||||
InnerSas::KeyRecieved(s) => Some(s.get_decimal()),
|
InnerSas::KeyRecieved(s) => Some(s.get_decimal()),
|
||||||
|
|
|
@ -633,6 +633,16 @@ impl Sas {
|
||||||
self.inner.lock().unwrap().emoji()
|
self.inner.lock().unwrap().emoji()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the index of the emoji representing the short auth string
|
||||||
|
///
|
||||||
|
/// Returns None if we can't yet present the short auth string, otherwise
|
||||||
|
/// seven u8 numbers in the range from 0 to 63 inclusive which can be
|
||||||
|
/// converted to an emoji using the
|
||||||
|
/// [relevant spec entry](https://spec.matrix.org/unstable/client-server-api/#sas-method-emoji).
|
||||||
|
pub fn emoji_index(&self) -> Option<[u8; 7]> {
|
||||||
|
self.inner.lock().unwrap().emoji_index()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the decimal version of the short auth string.
|
/// Get the decimal version of the short auth string.
|
||||||
///
|
///
|
||||||
/// Returns None if we can't yet present the short auth string, otherwise a
|
/// Returns None if we can't yet present the short auth string, otherwise a
|
||||||
|
|
|
@ -47,7 +47,8 @@ use super::{
|
||||||
AcceptContent, CancelContent, DoneContent, KeyContent, MacContent, StartContent,
|
AcceptContent, CancelContent, DoneContent, KeyContent, MacContent, StartContent,
|
||||||
},
|
},
|
||||||
helpers::{
|
helpers::{
|
||||||
calculate_commitment, get_decimal, get_emoji, get_mac_content, receive_mac_event, SasIds,
|
calculate_commitment, get_decimal, get_emoji, get_emoji_index, get_mac_content,
|
||||||
|
receive_mac_event, SasIds,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -757,6 +758,20 @@ impl SasState<KeyReceived> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the index of the emoji of the short authentication string.
|
||||||
|
///
|
||||||
|
/// Returns seven u8 numbers in the range from 0 to 63 inclusive, those numbers
|
||||||
|
/// can be converted to a unique emoji defined by the spec.
|
||||||
|
pub fn get_emoji_index(&self) -> [u8; 7] {
|
||||||
|
get_emoji_index(
|
||||||
|
&self.inner.lock().unwrap(),
|
||||||
|
&self.ids,
|
||||||
|
&self.state.their_pubkey,
|
||||||
|
self.verification_flow_id.as_str(),
|
||||||
|
self.state.we_started,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the decimal version of the short authentication string.
|
/// Get the decimal version of the short authentication string.
|
||||||
///
|
///
|
||||||
/// Returns a tuple containing three 4 digit integer numbers that represent
|
/// Returns a tuple containing three 4 digit integer numbers that represent
|
||||||
|
@ -978,6 +993,20 @@ impl SasState<MacReceived> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the index of the emoji of the short authentication string.
|
||||||
|
///
|
||||||
|
/// Returns seven u8 numbers in the range from 0 to 63 inclusive, those numbers
|
||||||
|
/// can be converted to a unique emoji defined by the spec.
|
||||||
|
pub fn get_emoji_index(&self) -> [u8; 7] {
|
||||||
|
get_emoji_index(
|
||||||
|
&self.inner.lock().unwrap(),
|
||||||
|
&self.ids,
|
||||||
|
&self.state.their_pubkey,
|
||||||
|
self.verification_flow_id.as_str(),
|
||||||
|
self.state.we_started,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the decimal version of the short authentication string.
|
/// Get the decimal version of the short authentication string.
|
||||||
///
|
///
|
||||||
/// Returns a tuple containing three 4 digit integer numbers that represent
|
/// Returns a tuple containing three 4 digit integer numbers that represent
|
||||||
|
|
Loading…
Reference in New Issue