Compare commits
12 commits
8c17e3a11a
...
0c17e706ba
Author | SHA1 | Date | |
---|---|---|---|
0c17e706ba | |||
11cd3e137d | |||
c696803702 | |||
3070732ab5 | |||
7684957ada | |||
77d347b51f | |||
4671819397 | |||
c310018847 | |||
4e25f1080e | |||
6f4cd8ecf5 | |||
171e913138 | |||
280e1c7d5f |
2 changed files with 276 additions and 462 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,3 @@
|
|||
use std::ffi::{CStr, CString};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
mod black_box;
|
||||
|
@ -27,9 +25,9 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
|
|||
if installation_id.len() > 54 {
|
||||
return Err(ConfirmationIdError::TooLarge);
|
||||
}
|
||||
let inst_id = CString::new(installation_id).unwrap();
|
||||
let conf_id = [0u8; 49];
|
||||
let result = unsafe { black_box::generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };
|
||||
let inst_id = installation_id.as_bytes();
|
||||
let mut conf_id = [0u8; 48];
|
||||
let result = black_box::generate(inst_id, &mut conf_id);
|
||||
match result {
|
||||
0 => {}
|
||||
1 => return Err(ConfirmationIdError::TooShort),
|
||||
|
@ -40,12 +38,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()
|
||||
.to_string())
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&conf_id).into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Reference in a new issue