feat(crypto): Rename verified and deleted to is_*

feat(crypto): Rename `verified` and `deleted` to `is_*`
This commit is contained in:
Ivan Enderlin
2022-09-01 10:50:05 +02:00
committed by GitHub
14 changed files with 44 additions and 44 deletions
@@ -173,7 +173,7 @@ impl OlmMachine {
{
match identity {
UserIdentities::Own(i) => i.is_verified(),
UserIdentities::Other(i) => i.verified(),
UserIdentities::Other(i) => i.is_verified(),
}
} else {
false
@@ -58,7 +58,7 @@ impl SessionVerificationController {
}
pub fn is_verified(&self) -> bool {
self.user_identity.verified()
self.user_identity.is_verified()
}
pub fn request_verification(&self) -> anyhow::Result<()> {
+1 -1
View File
@@ -224,7 +224,7 @@ impl BackupMachine {
auth_data: &str,
) -> SignatureState {
if device.has_signed_raw(signatures, auth_data).is_ok() {
if device.verified() {
if device.is_verified() {
SignatureState::ValidAndTrusted
} else {
SignatureState::ValidButNotTrusted
@@ -252,7 +252,7 @@ impl GossipMachine {
Ok(if let Some(device) = device {
if device.user_id() == self.user_id() {
if device.verified() {
if device.is_verified() {
info!(
user_id = device.user_id().as_str(),
device_id = device.device_id().as_str(),
@@ -536,7 +536,7 @@ impl GossipMachine {
// If this is our own, verified device, we share the entire session from the
// earliest known index.
if device.user_id() == self.user_id() && device.verified() {
if device.user_id() == self.user_id() && device.is_verified() {
Ok(None)
// Otherwise, if the records show we previously shared with this device,
// we'll reshare the session from the index we previously shared
@@ -834,7 +834,7 @@ impl GossipMachine {
self.store.get_device_from_curve_key(&event.sender, sender_key).await?
{
// Only accept secrets from one of our own trusted devices.
if device.user_id() == self.user_id() && device.verified() {
if device.user_id() == self.user_id() && device.is_verified() {
self.accept_secret(event, request, secret_name).await?;
} else {
warn!(
@@ -222,8 +222,8 @@ impl Device {
///
/// [`is_locally_trusted()`]: #method.is_locally_trusted
/// [`is_cross_signing_trusted()`]: #method.is_cross_signing_trusted
pub fn verified(&self) -> bool {
self.inner.verified(&self.own_identity, &self.device_owner_identity)
pub fn is_verified(&self) -> bool {
self.inner.is_verified(&self.own_identity, &self.device_owner_identity)
}
/// Is this device considered to be verified using cross signing.
@@ -352,7 +352,7 @@ impl UserDevices {
.filter(|d| {
!(d.user_id() == self.own_user_id() && d.device_id() == self.own_device_id())
})
.any(|d| d.verified(&self.own_identity, &self.device_owner_identity))
.any(|d| d.is_verified(&self.own_identity, &self.device_owner_identity))
}
/// Iterator over all the device ids of the user devices.
@@ -525,11 +525,11 @@ impl ReadOnlyDevice {
}
/// Is the device deleted.
pub fn deleted(&self) -> bool {
pub fn is_deleted(&self) -> bool {
self.deleted.load(Ordering::Relaxed)
}
pub(crate) fn verified(
pub(crate) fn is_verified(
&self,
own_identity: &Option<ReadOnlyOwnUserIdentity>,
device_owner: &Option<ReadOnlyUserIdentities>,
@@ -809,12 +809,12 @@ pub(crate) mod tests {
#[test]
fn delete_a_device() {
let device = get_device();
assert!(!device.deleted());
assert!(!device.is_deleted());
let device_clone = device.clone();
device.mark_as_deleted();
assert!(device.deleted());
assert!(device_clone.deleted());
assert!(device.is_deleted());
assert!(device_clone.is_deleted());
}
}
@@ -207,7 +207,7 @@ impl Deref for UserIdentity {
impl UserIdentity {
/// Is this user identity verified.
pub fn verified(&self) -> bool {
pub fn is_verified(&self) -> bool {
self.own_identity
.as_ref()
.map(|o| o.is_identity_signed(&self.inner).is_ok())
@@ -1046,8 +1046,8 @@ pub(crate) mod tests {
assert!(!first.is_cross_signing_trusted());
identity.mark_as_verified();
assert!(second.verified());
assert!(!first.verified());
assert!(second.is_verified());
assert!(!first.is_verified());
}
#[async_test]
@@ -1075,12 +1075,12 @@ pub(crate) mod tests {
device_owner_identity: Some(public_identity.clone().into()),
};
assert!(!device.verified());
assert!(!device.is_verified());
let mut device_keys = device.as_device_keys().to_owned();
identity.sign_device_keys(&mut device_keys).await.unwrap();
device.inner.update_device(&device_keys).expect("Couldn't update newly signed device keys");
assert!(device.verified());
assert!(device.is_verified());
}
}
+10 -10
View File
@@ -1045,7 +1045,7 @@ impl OlmMachine {
// a) This is our own device, or
// b) The device itself is considered to be trusted.
if device.is_owner_of_session(session)
&& (device.is_our_own_device() || device.verified())
&& (device.is_our_own_device() || device.is_verified())
{
VerificationState::Trusted
} else {
@@ -2118,7 +2118,7 @@ pub(crate) mod tests {
let bob_device =
alice.get_device(bob.user_id(), bob.device_id(), None).await.unwrap().unwrap();
assert!(!bob_device.verified());
assert!(!bob_device.is_verified());
let (alice_sas, request) = bob_device.start_verification().await.unwrap();
@@ -2173,15 +2173,15 @@ pub(crate) mod tests {
let event = request_to_event(alice.user_id(), &contents[0]);
assert!(alice_sas.is_done());
assert!(bob_device.verified());
assert!(bob_device.is_verified());
let alice_device =
bob.get_device(alice.user_id(), alice.device_id(), None).await.unwrap().unwrap();
assert!(!alice_device.verified());
assert!(!alice_device.is_verified());
bob.handle_verification_event(&event).await;
assert!(bob_sas.is_done());
assert!(alice_device.verified());
assert!(alice_device.is_verified());
}
#[async_test]
@@ -2193,7 +2193,7 @@ pub(crate) mod tests {
let bob_device =
alice.get_device(bob.user_id(), bob.device_id(), None).await.unwrap().unwrap();
assert!(!bob_device.verified());
assert!(!bob_device.is_verified());
// Alice sends a verification request with her desired methods to Bob
let (alice_ver_req, request) =
@@ -2333,23 +2333,23 @@ pub(crate) mod tests {
bob.get_device(alice.user_id(), alice.device_id(), None).await.unwrap().unwrap();
assert!(!bob_sas.is_done());
assert!(!alice_device.verified());
assert!(!alice_device.is_verified());
// And Bob receives the Done message of alice.
bob.handle_verification_event(&event_done).await;
assert!(bob_sas.is_done());
assert!(alice_device.verified());
assert!(alice_device.is_verified());
// ----------------------------------------------------------------------------
// On Alice's device:
assert!(!alice_sas.is_done());
assert!(!bob_device.verified());
assert!(!bob_device.is_verified());
// Alices receives the done message
eprintln!("{:?}", event);
alice.handle_verification_event(&event).await;
assert!(alice_sas.is_done());
assert!(bob_device.verified());
assert!(bob_device.is_verified());
}
}
@@ -369,7 +369,7 @@ impl GroupSessionManager {
.devices()
.filter(|d| {
if settings.only_allow_trusted_devices {
!d.is_blacklisted() && d.verified()
!d.is_blacklisted() && d.is_verified()
} else {
!d.is_blacklisted()
}
+2 -2
View File
@@ -150,8 +150,8 @@ module.
To add interactive verification support to your client please see the
[`verification`] module, also check out the documentation for the
[`Device::verified()`] method, which explains in more detail what it means
for a [`Device`] to be verified.
[`Device::is_verified()`] method, which explains in more detail what
it means for a [`Device`] to be verified.
# Client setup
@@ -362,7 +362,7 @@ impl Device {
/// client.encryption().get_device(alice, device_id!("DEVICEID")).await?;
///
/// if let Some(device) = device {
/// if device.verified() {
/// if device.is_verified() {
/// println!(
/// "Device {} of user {} is verified",
/// device.device_id().as_str(),
@@ -381,9 +381,9 @@ impl Device {
///
/// [`UserIdentity::verify()`]:
/// crate::encryption::identities::UserIdentity::verify
/// [verified]: crate::encryption::identities::UserIdentity::verified
pub fn verified(&self) -> bool {
self.inner.verified()
/// [verified]: crate::encryption::identities::UserIdentity::is_verified
pub fn is_verified(&self) -> bool {
self.inner.is_verified()
}
/// Set the local trust state of the device to the given state.
@@ -331,7 +331,7 @@ impl UserIdentity {
/// let user = client.encryption().get_user_identity(alice).await?;
///
/// if let Some(user) = user {
/// if user.verified() {
/// if user.is_verified() {
/// println!("User {} is verified", user.user_id().as_str());
/// } else {
/// println!("User {} is not verified", user.user_id().as_str());
@@ -339,10 +339,10 @@ impl UserIdentity {
/// }
/// # anyhow::Ok(()) });
/// ```
pub fn verified(&self) -> bool {
pub fn is_verified(&self) -> bool {
match &self.inner {
UserIdentities::Own(i) => i.inner.is_verified(),
UserIdentities::Other(i) => i.inner.verified(),
UserIdentities::Other(i) => i.inner.is_verified(),
}
}
+3 -3
View File
@@ -546,9 +546,9 @@ impl Encryption {
/// if let Some(device) =
/// client.encryption().get_device(alice, device_id!("DEVICEID")).await?
/// {
/// println!("{:?}", device.verified());
/// println!("{:?}", device.is_verified());
///
/// if !device.verified() {
/// if !device.is_verified() {
/// let verification = device.request_verification().await?;
/// }
/// }
@@ -628,7 +628,7 @@ impl Encryption {
/// let user = client.encryption().get_user_identity(alice).await?;
///
/// if let Some(user) = user {
/// println!("{:?}", user.verified());
/// println!("{:?}", user.is_verified());
///
/// let verification = user.request_verification().await?;
/// }
+1 -1
View File
@@ -920,7 +920,7 @@ impl Common {
for user_id in user_ids {
let devices = self.client.encryption().get_user_devices(&user_id).await?;
let any_unverified = devices.devices().any(|d| !d.verified());
let any_unverified = devices.devices().any(|d| !d.is_verified());
if any_unverified {
return Ok(false);
+1 -1
View File
@@ -60,7 +60,7 @@ async fn print_devices(user_id: &UserId, client: &Client) {
" {:<10} {:<30} {:<}",
device.device_id(),
device.display_name().unwrap_or("-"),
device.verified()
device.is_verified()
);
}
}