Narrow the scope of unsafe in confid::generate
This commit is contained in:
parent
2c41fe6c21
commit
6d27106e35
1 changed files with 13 additions and 13 deletions
|
@ -1342,10 +1342,9 @@ pub enum ConfirmationIdError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||||
unsafe {
|
|
||||||
let inst_id = CString::new(installation_id).unwrap();
|
let inst_id = CString::new(installation_id).unwrap();
|
||||||
let conf_id = [0u8; 49];
|
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 {
|
match result {
|
||||||
0 => {}
|
0 => {}
|
||||||
1 => return Err(ConfirmationIdError::TooShort),
|
1 => return Err(ConfirmationIdError::TooShort),
|
||||||
|
@ -1356,6 +1355,7 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||||
6 => return Err(ConfirmationIdError::Unlucky),
|
6 => return Err(ConfirmationIdError::Unlucky),
|
||||||
_ => panic!("Unknown error code: {}", result),
|
_ => panic!("Unknown error code: {}", result),
|
||||||
}
|
}
|
||||||
|
unsafe {
|
||||||
Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
|
Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
Loading…
Add table
Reference in a new issue