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,20 +1342,20 @@ pub enum ConfirmationIdError {
|
|||
}
|
||||
|
||||
pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
||||
let inst_id = CString::new(installation_id).unwrap();
|
||||
let conf_id = [0u8; 49];
|
||||
let result = unsafe { Generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };
|
||||
match result {
|
||||
0 => {}
|
||||
1 => return Err(ConfirmationIdError::TooShort),
|
||||
2 => return Err(ConfirmationIdError::TooLarge),
|
||||
3 => return Err(ConfirmationIdError::InvalidCharacter),
|
||||
4 => return Err(ConfirmationIdError::InvalidCheckDigit),
|
||||
5 => return Err(ConfirmationIdError::UnknownVersion),
|
||||
6 => return Err(ConfirmationIdError::Unlucky),
|
||||
_ => panic!("Unknown error code: {}", result),
|
||||
}
|
||||
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);
|
||||
match result {
|
||||
0 => {}
|
||||
1 => return Err(ConfirmationIdError::TooShort),
|
||||
2 => return Err(ConfirmationIdError::TooLarge),
|
||||
3 => return Err(ConfirmationIdError::InvalidCharacter),
|
||||
4 => return Err(ConfirmationIdError::InvalidCheckDigit),
|
||||
5 => return Err(ConfirmationIdError::UnknownVersion),
|
||||
6 => return Err(ConfirmationIdError::Unlucky),
|
||||
_ => panic!("Unknown error code: {}", result),
|
||||
}
|
||||
Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
|
|
Loading…
Add table
Reference in a new issue