(encrypted_token: &str, secret_key: &str)
| 95 | } |
| 96 | |
| 97 | fn decrypt_token(encrypted_token: &str, secret_key: &str) -> Result<String, GourceError> { |
| 98 | let parts: Vec<&str> = encrypted_token.split(':').collect(); |
| 99 | if parts.len() != 2 { |
| 100 | return Err(GourceError::DecryptionFailed); |
| 101 | } |
| 102 | |
| 103 | let iv = hex::decode(parts[0]).map_err(|_| GourceError::DecryptionFailed)?; |
| 104 | let ciphertext = hex::decode(parts[1]).map_err(|_| GourceError::DecryptionFailed)?; |
| 105 | |
| 106 | let key = derive_key(secret_key); |
| 107 | |
| 108 | let mut decryptor = aes::ctr(aes::KeySize::KeySize256, &key, &iv); |
| 109 | let mut buffer = vec![0; ciphertext.len()]; |
| 110 | let mut read_buffer = buffer::RefReadBuffer::new(&ciphertext); |
| 111 | let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer); |
| 112 | |
| 113 | decryptor |
| 114 | .decrypt(&mut read_buffer, &mut write_buffer, true) |
| 115 | .map_err(|_| GourceError::DecryptionFailed)?; |
| 116 | |
| 117 | String::from_utf8(buffer).map_err(|_| GourceError::DecryptionFailed) |
| 118 | } |
| 119 | |
| 120 | fn log_message(level: log::Level, message: &str, job_id: Option<&str>) { |
| 121 | let target = job_id.map_or("gitmotion_api".to_string(), |id| format!("job-{}", id)); |
no test coverage detected