Loading system/gd/rust/linux/client/src/command_handler.rs +3 −5 Original line number Diff line number Diff line Loading @@ -772,12 +772,10 @@ impl CommandHandler { name: String::from(""), }; let pin = get_arg(args, 2)?; let (accept, pin) = match (&pin[..], String::from(pin).parse::<u32>()) { (_, Ok(p)) => (true, Vec::from(p.to_ne_bytes())), let (accept, pin) = match (&pin[..], pin) { ("reject", _) => (false, vec![]), _ => { return Err(format!("Failed to parse '{}'", pin).into()); } (_, p) => (true, p.as_bytes().iter().cloned().collect::<Vec<u8>>()), }; self.lock_context().adapter_dbus.as_mut().unwrap().set_pin( Loading system/gd/rust/linux/stack/src/bluetooth.rs +3 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,13 @@ use bt_topshim::{ topstack, }; use bt_utils::array_utils; use btif_macros::{btif_callback, btif_callbacks_dispatcher}; use log::{debug, warn}; use num_traits::cast::ToPrimitive; use std::collections::HashMap; use std::convert::TryInto; use std::fs::File; use std::hash::Hash; use std::io::Write; Loading Loading @@ -1597,8 +1599,7 @@ impl IBluetooth for Bluetooth { return false; } let mut btpin: BtPinCode = BtPinCode { pin: [0; 16] }; btpin.pin.copy_from_slice(pin_code.as_slice()); let mut btpin = BtPinCode { pin: array_utils::to_sized_array(&pin_code) }; self.intf.lock().unwrap().pin_reply( &addr.unwrap(), Loading system/gd/rust/linux/stack/src/bluetooth_gatt.rs +2 −8 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use bt_topshim::profiles::gatt::{ }; use bt_topshim::topstack; use bt_utils::adv_parser; use bt_utils::array_utils; use crate::async_helper::{AsyncHelper, CallbackSender}; use crate::bluetooth::{Bluetooth, IBluetooth}; Loading Loading @@ -2485,14 +2486,7 @@ impl IBluetoothGatt for BluetoothGatt { let handle = self.server_context_map.get_request_handle_from_id(request_id)?; let len = value.len() as u16; let data: [u8; 600] = value .iter() .chain(std::iter::repeat(&0)) .take(600) .cloned() .collect::<Vec<u8>>() .try_into() .ok()?; let data: [u8; 600] = array_utils::to_sized_array(&value); self.gatt.as_ref().unwrap().lock().unwrap().server.send_response( conn_id, Loading system/gd/rust/linux/utils/src/array_utils.rs 0 → 100644 +10 −0 Original line number Diff line number Diff line //! This library provides array utils. /// Converts a vector of bytes to a fixed sized array. /// If the vector is longer it will be truncated and if shorter /// zero padding will be added at the end. pub fn to_sized_array<const S: usize>(v: &Vec<u8>) -> [u8; S] { // Okay to do naked unwrap since we enforce at compile time that // the iter length is the same as the destination array length. v.iter().chain(std::iter::repeat(&0)).take(S).cloned().collect::<Vec<u8>>().try_into().unwrap() } system/gd/rust/linux/utils/src/lib.rs +1 −0 Original line number Diff line number Diff line //! Utilities pub mod adv_parser; pub mod array_utils; pub mod socket; pub mod uinput; Loading
system/gd/rust/linux/client/src/command_handler.rs +3 −5 Original line number Diff line number Diff line Loading @@ -772,12 +772,10 @@ impl CommandHandler { name: String::from(""), }; let pin = get_arg(args, 2)?; let (accept, pin) = match (&pin[..], String::from(pin).parse::<u32>()) { (_, Ok(p)) => (true, Vec::from(p.to_ne_bytes())), let (accept, pin) = match (&pin[..], pin) { ("reject", _) => (false, vec![]), _ => { return Err(format!("Failed to parse '{}'", pin).into()); } (_, p) => (true, p.as_bytes().iter().cloned().collect::<Vec<u8>>()), }; self.lock_context().adapter_dbus.as_mut().unwrap().set_pin( Loading
system/gd/rust/linux/stack/src/bluetooth.rs +3 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,13 @@ use bt_topshim::{ topstack, }; use bt_utils::array_utils; use btif_macros::{btif_callback, btif_callbacks_dispatcher}; use log::{debug, warn}; use num_traits::cast::ToPrimitive; use std::collections::HashMap; use std::convert::TryInto; use std::fs::File; use std::hash::Hash; use std::io::Write; Loading Loading @@ -1597,8 +1599,7 @@ impl IBluetooth for Bluetooth { return false; } let mut btpin: BtPinCode = BtPinCode { pin: [0; 16] }; btpin.pin.copy_from_slice(pin_code.as_slice()); let mut btpin = BtPinCode { pin: array_utils::to_sized_array(&pin_code) }; self.intf.lock().unwrap().pin_reply( &addr.unwrap(), Loading
system/gd/rust/linux/stack/src/bluetooth_gatt.rs +2 −8 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use bt_topshim::profiles::gatt::{ }; use bt_topshim::topstack; use bt_utils::adv_parser; use bt_utils::array_utils; use crate::async_helper::{AsyncHelper, CallbackSender}; use crate::bluetooth::{Bluetooth, IBluetooth}; Loading Loading @@ -2485,14 +2486,7 @@ impl IBluetoothGatt for BluetoothGatt { let handle = self.server_context_map.get_request_handle_from_id(request_id)?; let len = value.len() as u16; let data: [u8; 600] = value .iter() .chain(std::iter::repeat(&0)) .take(600) .cloned() .collect::<Vec<u8>>() .try_into() .ok()?; let data: [u8; 600] = array_utils::to_sized_array(&value); self.gatt.as_ref().unwrap().lock().unwrap().server.send_response( conn_id, Loading
system/gd/rust/linux/utils/src/array_utils.rs 0 → 100644 +10 −0 Original line number Diff line number Diff line //! This library provides array utils. /// Converts a vector of bytes to a fixed sized array. /// If the vector is longer it will be truncated and if shorter /// zero padding will be added at the end. pub fn to_sized_array<const S: usize>(v: &Vec<u8>) -> [u8; S] { // Okay to do naked unwrap since we enforce at compile time that // the iter length is the same as the destination array length. v.iter().chain(std::iter::repeat(&0)).take(S).cloned().collect::<Vec<u8>>().try_into().unwrap() }
system/gd/rust/linux/utils/src/lib.rs +1 −0 Original line number Diff line number Diff line //! Utilities pub mod adv_parser; pub mod array_utils; pub mod socket; pub mod uinput;