the base
This commit is contained in:
41
lib/osal/ssh_key.v
Normal file
41
lib/osal/ssh_key.v
Normal file
@@ -0,0 +1,41 @@
|
||||
module osal
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import os
|
||||
|
||||
@[noinit]
|
||||
pub struct SSHKey {
|
||||
pub:
|
||||
name string
|
||||
directory string
|
||||
}
|
||||
|
||||
// returns the public ssh key's path of the keypair
|
||||
pub fn (key SSHKey) public_key_path() !pathlib.Path {
|
||||
path_str := os.join_path(key.directory, '${key.name}.pub')
|
||||
return pathlib.get_file(path: path_str) or {
|
||||
return error('Failed to get public key path: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
// returns the private ssh key's path of the keypair
|
||||
pub fn (key SSHKey) private_key_path() !pathlib.Path {
|
||||
path_str := os.join_path(key.directory, '${key.name}')
|
||||
return pathlib.get_file(path: path_str) or {
|
||||
return error('Failed to get public key path: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
// returns the public ssh key of the keypair
|
||||
pub fn (key SSHKey) public_key() !string {
|
||||
mut path := key.public_key_path()!
|
||||
content := path.read()!
|
||||
return content
|
||||
}
|
||||
|
||||
// returns the private ssh key of the keypair
|
||||
pub fn (key SSHKey) private_key() !string {
|
||||
mut path := key.private_key_path()!
|
||||
content := path.read()!
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user