Skip to content

Commit

Permalink
Set local trust
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas authored and poljar committed Oct 19, 2022
1 parent 0cfc754 commit c92d946
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
7 changes: 6 additions & 1 deletion bindings/apple/build_crypto_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ lipo -create \
-output "${GENERATED_DIR}/simulator/libmatrix_sdk_crypto_ffi.a"

# Generate uniffi files
uniffi-bindgen generate "${SRC_ROOT}/bindings/${TARGET_CRATE}/src/olm.udl" --language swift --config "${SRC_ROOT}/bindings/${TARGET_CRATE}/uniffi.toml" --out-dir ${GENERATED_DIR}
uniffi-bindgen generate \
--language swift \
--lib-file "${TARGET_DIR}/aarch64-apple-ios-sim/${REL_TYPE_DIR}/libmatrix_sdk_crypto_ffi.a" \
--config "${SRC_ROOT}/bindings/${TARGET_CRATE}/uniffi.toml" \
--out-dir ${GENERATED_DIR} \
"${SRC_ROOT}/bindings/${TARGET_CRATE}/src/olm.udl"

# Move headers to the right place
HEADERS_DIR=${GENERATED_DIR}/headers
Expand Down
5 changes: 4 additions & 1 deletion bindings/matrix-sdk-crypto-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ pub use error::{
use js_int::UInt;
pub use logger::{set_logger, Logger};
pub use machine::{KeyRequestPair, OlmMachine};
use matrix_sdk_crypto::types::{EventEncryptionAlgorithm, SigningKey};
use matrix_sdk_crypto::{
types::{EventEncryptionAlgorithm, SigningKey},
LocalTrust,
};
pub use responses::{
BootstrapCrossSigningResult, DeviceLists, KeysImportResult, OutgoingVerificationRequest,
Request, RequestType, SignatureUploadRequest, UploadSigningKeysRequest,
Expand Down
1 change: 1 addition & 0 deletions bindings/matrix-sdk-crypto-ffi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn set_logger(logger: Box<dyn Logger>) {
let _ = tracing_subscriber::fmt()
.with_writer(logger)
.with_env_filter(filter)
.with_ansi(false)
.without_time()
.try_init();
}
8 changes: 5 additions & 3 deletions bindings/matrix-sdk-crypto-ffi/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,21 @@ impl OlmMachine {
}
}

/// Mark the device of the given user with the given device ID as trusted.
pub fn mark_device_as_trusted(
/// Set local trust state for the device of the given user without creating
/// or uploading any signatures if verified
pub fn set_local_trust(
&self,
user_id: &str,
device_id: &str,
trust_state: LocalTrust,
) -> Result<(), CryptoStoreError> {
let user_id = parse_user_id(user_id)?;

let device =
self.runtime.block_on(self.inner.get_device(&user_id, device_id.into(), None))?;

if let Some(device) = device {
self.runtime.block_on(device.set_local_trust(LocalTrust::Verified))?;
self.runtime.block_on(device.set_local_trust(trust_state))?;
}

Ok(())
Expand Down
9 changes: 8 additions & 1 deletion bindings/matrix-sdk-crypto-ffi/src/olm.udl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ enum RequestType {
"RoomMessage",
};

enum LocalTrust {
"Verified",
"BlackListed",
"Ignored",
"Unset",
};

interface OlmMachine {
[Throws=CryptoStoreError]
constructor(
Expand Down Expand Up @@ -282,7 +289,7 @@ interface OlmMachine {
[Throws=CryptoStoreError]
Device? get_device([ByRef] string user_id, [ByRef] string device_id, u32 timeout);
[Throws=CryptoStoreError]
void mark_device_as_trusted([ByRef] string user_id, [ByRef] string device_id);
void set_local_trust([ByRef] string user_id, [ByRef] string device_id, LocalTrust trust_state);
[Throws=SignatureError]
SignatureUploadRequest verify_device([ByRef] string user_id, [ByRef] string device_id);
[Throws=CryptoStoreError]
Expand Down

0 comments on commit c92d946

Please sign in to comment.