1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::sync::atomic::AtomicBool;
use crate::encryption::ChaCha20Poly1305;
use crate::error::SshErrorKind;
use crate::SshError;
pub(crate) static IS_ENCRYPT: AtomicBool = AtomicBool::new(false);
pub(crate) static mut ENCRYPTION_KEY: Option<ChaCha20Poly1305> = None;
pub(crate) fn encryption_key() -> Result<&'static mut ChaCha20Poly1305, SshError> {
unsafe {
match &mut ENCRYPTION_KEY {
None => Err(SshError::from(SshErrorKind::EncryptionError)),
Some(v) => Ok(v)
}
}
}
pub(crate) fn update_encryption_key(v: Option<ChaCha20Poly1305>) {
unsafe {
ENCRYPTION_KEY = v
}
}