MCPcopy Index your code
hub / github.com/3eif/gitmotion / decrypt_token

Function decrypt_token

api/src/main.rs:97–118  ·  view source on GitHub ↗
(encrypted_token: &str, secret_key: &str)

Source from the content-addressed store, hash-verified

95}
96
97fn 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
120fn 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));

Callers 1

process_gourceFunction · 0.85

Calls 1

derive_keyFunction · 0.85

Tested by

no test coverage detected