feat: add ssh agnet(not yet work)
This commit is contained in:
20
src/sshutil.rs
Normal file
20
src/sshutil.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
pub fn with_sign(mut vec: Vec<u8>) -> Vec<u8> {
|
||||
if vec.len() > 0 && vec[0] >= 128 {
|
||||
vec.insert(0, 0x00);
|
||||
}
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn generate_ssh_string(e: &[u8], n: &[u8], comment: &str) -> String {
|
||||
let mut ssh_key = vec![];
|
||||
let ssh_rsa_bytes = "ssh-rsa".as_bytes();
|
||||
ssh_key.extend_from_slice(&(ssh_rsa_bytes.len() as u32).to_be_bytes()[..]);
|
||||
ssh_key.extend_from_slice(ssh_rsa_bytes);
|
||||
let e = with_sign(e.to_vec());
|
||||
ssh_key.extend_from_slice(&(e.len() as u32).to_be_bytes()[..]);
|
||||
ssh_key.extend_from_slice(&e);
|
||||
let n = with_sign(n.to_vec());
|
||||
ssh_key.extend_from_slice(&(n.len() as u32).to_be_bytes()[..]);
|
||||
ssh_key.extend_from_slice(&n);
|
||||
format!("ssh-rsa {} {}", base64::encode(&ssh_key), comment)
|
||||
}
|
||||
Reference in New Issue
Block a user