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;
 | 
					use thiserror::Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod black_box;
 | 
					mod black_box;
 | 
				
			||||||
| 
						 | 
					@ -27,9 +25,9 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
 | 
				
			||||||
    if installation_id.len() > 54 {
 | 
					    if installation_id.len() > 54 {
 | 
				
			||||||
        return Err(ConfirmationIdError::TooLarge);
 | 
					        return Err(ConfirmationIdError::TooLarge);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let inst_id = CString::new(installation_id).unwrap();
 | 
					    let inst_id = installation_id.as_bytes();
 | 
				
			||||||
    let conf_id = [0u8; 49];
 | 
					    let mut conf_id = [0u8; 48];
 | 
				
			||||||
    let result = unsafe { black_box::generate(inst_id.as_ptr(), conf_id.as_ptr() as *mut i8) };
 | 
					    let result = black_box::generate(inst_id, &mut conf_id);
 | 
				
			||||||
    match result {
 | 
					    match result {
 | 
				
			||||||
        0 => {}
 | 
					        0 => {}
 | 
				
			||||||
        1 => return Err(ConfirmationIdError::TooShort),
 | 
					        1 => return Err(ConfirmationIdError::TooShort),
 | 
				
			||||||
| 
						 | 
					@ -40,12 +38,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(String::from_utf8_lossy(&conf_id).into())
 | 
				
			||||||
        Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
 | 
					 | 
				
			||||||
            .to_str()
 | 
					 | 
				
			||||||
            .unwrap()
 | 
					 | 
				
			||||||
            .to_string())
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue