Skip to content

Commit

Permalink
Move SshError into BuiltinError
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Nov 5, 2024
1 parent 95e74c6 commit 5f51612
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 12 additions & 0 deletions rust/src/nasl/builtin/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ macro_rules! builtin_error_variant (
NaslError::Builtin(BuiltinError::$variant(value))
}
}

impl TryFrom<NaslError> for $ty {
type Error = ();

fn try_from(value: NaslError) -> Result<Self, Self::Error> {
match value {
NaslError::Builtin(BuiltinError::$variant(e)) => Ok(e),
_ => Err(()),
}
}
}
}
);

builtin_error_variant!(StringError, String);
builtin_error_variant!(MiscError, Misc);
builtin_error_variant!(SocketError, Socket);
builtin_error_variant!(CryptographicError, Cryptographic);
builtin_error_variant!(SshError, Ssh);
1 change: 0 additions & 1 deletion rust/src/nasl/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mod string;
mod tests;

pub use error::BuiltinError;
pub use ssh::SshError;

use crate::nasl::syntax::{Loader, NoOpLoader};
use crate::nasl::utils::{Context, Executor, NaslVarRegister, NaslVarRegisterBuilder, Register};
Expand Down
8 changes: 0 additions & 8 deletions rust/src/nasl/builtin/ssh/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::fmt;

use thiserror::Error;

use crate::nasl::NaslError;

use super::SessionId;

/// A cloneable representation of the Error type of the underlying SSH lib
Expand Down Expand Up @@ -162,9 +160,3 @@ impl SshError {
m.attach_error_info(self)
}
}

impl From<SshError> for NaslError {
fn from(e: SshError) -> Self {
NaslError::Ssh(e)
}
}
8 changes: 4 additions & 4 deletions rust/src/nasl/builtin/ssh/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ async fn ssh_connect() {
check_err_matches!(
t,
format!(r#"id = ssh_connect(port:{}, keytype: "ssh-rsa");"#, PORT),
NaslError::Ssh(SshError {
SshError {
kind: SshErrorKind::Connect,
..
})
}
);
},
default_config(),
Expand Down Expand Up @@ -115,10 +115,10 @@ async fn ssh_userauth() {
check_err_matches!(
t,
r#"ssh_userauth(session_id);"#,
NaslError::Ssh(SshError {
SshError {
kind: SshErrorKind::NoAuthenticationGiven,
..
}),
},
);
userauth(&mut t);
},
Expand Down
5 changes: 1 addition & 4 deletions rust/src/nasl/utils/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Defines function error kinds
use thiserror::Error;

use crate::nasl::builtin::{BuiltinError, SshError};
use crate::nasl::builtin::BuiltinError;
use crate::nasl::prelude::NaslValue;

use crate::storage::StorageError;
Expand All @@ -22,9 +22,6 @@ pub enum NaslError {
/// An example would be that there is no free memory left in the system
#[error("{0}")]
Dirty(String),
/// An Error originating from an SSH-specific NASL function
#[error("SSH error: {0}")]
Ssh(SshError),
#[error("{0}")]
Argument(#[from] ArgumentError),
#[error("{0}")]
Expand Down

0 comments on commit 5f51612

Please sign in to comment.