Skip to content

Commit

Permalink
Move to raw bytes for ble_ident
Browse files Browse the repository at this point in the history
The BLE ident isn't currently verified (an issue already exists) so it
didn't break anything. Was unable to double-check with a non-mobile-sdk
wallet.
  • Loading branch information
sbihel committed Aug 30, 2024
1 parent 1cf2243 commit 6143b7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
16 changes: 8 additions & 8 deletions MobileSdkRs/Sources/MobileSdkRs/mobile_sdk_rs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ public struct MdlReaderSessionData {
public var state: MdlSessionManager
public var uuid: Uuid
public var request: Data
public var bleIdent: String
public var bleIdent: Data

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(state: MdlSessionManager, uuid: Uuid, request: Data, bleIdent: String) {
public init(state: MdlSessionManager, uuid: Uuid, request: Data, bleIdent: Data) {
self.state = state
self.uuid = uuid
self.request = request
Expand All @@ -1021,15 +1021,15 @@ public struct FfiConverterTypeMDLReaderSessionData: FfiConverterRustBuffer {
state: FfiConverterTypeMDLSessionManager.read(from: &buf),
uuid: FfiConverterTypeUuid.read(from: &buf),
request: FfiConverterData.read(from: &buf),
bleIdent: FfiConverterString.read(from: &buf)
bleIdent: FfiConverterData.read(from: &buf)
)
}

public static func write(_ value: MdlReaderSessionData, into buf: inout [UInt8]) {
FfiConverterTypeMDLSessionManager.write(value.state, into: &buf)
FfiConverterTypeUuid.write(value.uuid, into: &buf)
FfiConverterData.write(value.request, into: &buf)
FfiConverterString.write(value.bleIdent, into: &buf)
FfiConverterData.write(value.bleIdent, into: &buf)
}
}

Expand Down Expand Up @@ -1085,11 +1085,11 @@ public func FfiConverterTypeRequestData_lower(_ value: RequestData) -> RustBuffe
public struct SessionData {
public var state: SessionManagerEngaged
public var qrCodeUri: String
public var bleIdent: String
public var bleIdent: Data

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(state: SessionManagerEngaged, qrCodeUri: String, bleIdent: String) {
public init(state: SessionManagerEngaged, qrCodeUri: String, bleIdent: Data) {
self.state = state
self.qrCodeUri = qrCodeUri
self.bleIdent = bleIdent
Expand All @@ -1104,14 +1104,14 @@ public struct FfiConverterTypeSessionData: FfiConverterRustBuffer {
try SessionData(
state: FfiConverterTypeSessionManagerEngaged.read(from: &buf),
qrCodeUri: FfiConverterString.read(from: &buf),
bleIdent: FfiConverterString.read(from: &buf)
bleIdent: FfiConverterData.read(from: &buf)
)
}

public static func write(_ value: SessionData, into buf: inout [UInt8]) {
FfiConverterTypeSessionManagerEngaged.write(value.state, into: &buf)
FfiConverterString.write(value.qrCodeUri, into: &buf)
FfiConverterString.write(value.bleIdent, into: &buf)
FfiConverterData.write(value.bleIdent, into: &buf)
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/mdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct SessionManagerEngaged(device::SessionManagerEngaged);
struct SessionData {
state: Arc<SessionManagerEngaged>,
qr_code_uri: String,
ble_ident: String,
ble_ident: Vec<u8>,
}

uniffi::custom_type!(Uuid, String);
Expand Down Expand Up @@ -144,14 +144,12 @@ fn initialise_session(document: Arc<MDoc>, uuid: Uuid) -> Result<SessionData, Se
.map_err(|e| SessionError::Generic {
value: format!("Could not initialize session: {e:?}"),
})?;
let mut ble_ident =
session
.ble_ident()
.map(hex::encode)
.map_err(|e| SessionError::Generic {
value: format!("Could not encode hex BLE ident: {e:?}"),
})?;
ble_ident.insert_str(0, "0x");
let ble_ident = session
.ble_ident()
.map_err(|e| SessionError::Generic {
value: format!("Could not get BLE ident: {e:?}"),
})?
.to_vec();
let (engaged_state, qr_code_uri) =
session.qr_engagement().map_err(|e| SessionError::Generic {
value: format!("Could not generate qr engagement: {e:?}"),
Expand Down
8 changes: 2 additions & 6 deletions src/mdl/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct MDLReaderSessionData {
pub state: Arc<MDLSessionManager>,
uuid: Uuid,
pub request: Vec<u8>,
ble_ident: String,
ble_ident: Vec<u8>,
}

#[uniffi::export]
Expand Down Expand Up @@ -97,14 +97,10 @@ pub fn establish_session(
value: "the device did not transmit a central client uuid".to_string(),
})?;

// TODO this must be wrong -- it's encoded as a hex string, but then advertised as raw bytes
let mut ble_ident = hex::encode(ble_ident);
ble_ident.insert_str(0, "0x");

Ok(MDLReaderSessionData {
state: Arc::new(MDLSessionManager(manager)),
request,
ble_ident,
ble_ident: ble_ident.to_vec(),
uuid: *uuid,
})
}
Expand Down

0 comments on commit 6143b7c

Please sign in to comment.