Narrow the scope of unsafe in confid::generate

This commit is contained in:
Alex Page 2023-06-22 01:44:38 -04:00
parent 2c41fe6c21
commit 6d27106e35

View file

@ -1342,10 +1342,9 @@ pub enum ConfirmationIdError {
}
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
unsafe {
let inst_id = CString::new(installation_id).unwrap();
let conf_id = [0u8; 49];
let result = Generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8);
let result = unsafe { Generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };
match result {
0 => {}
1 => return Err(ConfirmationIdError::TooShort),
@ -1356,6 +1355,7 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
6 => return Err(ConfirmationIdError::Unlucky),
_ => panic!("Unknown error code: {}", result),
}
unsafe {
Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
.to_str()
.unwrap()