Compare commits
	
		
			No commits in common. "0c17e706bae12baa4088663334e8bb84b9c9417c" and "8c17e3a11a18b01fdb9088f659042c51343d647c" have entirely different histories.
		
	
	
		
			0c17e706ba
			...
			8c17e3a11a
		
	
		
					 2 changed files with 462 additions and 276 deletions
				
			
		
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
use std::ffi::{CStr, CString};
 | 
			
		||||
 | 
			
		||||
use thiserror::Error;
 | 
			
		||||
 | 
			
		||||
mod black_box;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,9 +27,9 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
 | 
			
		|||
    if installation_id.len() > 54 {
 | 
			
		||||
        return Err(ConfirmationIdError::TooLarge);
 | 
			
		||||
    }
 | 
			
		||||
    let inst_id = installation_id.as_bytes();
 | 
			
		||||
    let mut conf_id = [0u8; 48];
 | 
			
		||||
    let result = black_box::generate(inst_id, &mut conf_id);
 | 
			
		||||
    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) };
 | 
			
		||||
    match result {
 | 
			
		||||
        0 => {}
 | 
			
		||||
        1 => return Err(ConfirmationIdError::TooShort),
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +40,12 @@ pub fn generate(installation_id: &str) -> Result<String, ConfirmationIdError> {
 | 
			
		|||
        6 => return Err(ConfirmationIdError::Unlucky),
 | 
			
		||||
        _ => panic!("Unknown error code: {}", result),
 | 
			
		||||
    }
 | 
			
		||||
    Ok(String::from_utf8_lossy(&conf_id).into())
 | 
			
		||||
    unsafe {
 | 
			
		||||
        Ok(CStr::from_ptr(conf_id.as_ptr() as *const i8)
 | 
			
		||||
            .to_str()
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .to_string())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue