1use tacacs_plus_protocol::Argument;
2use tacacs_plus_protocol::{authentication, authorization};
3
4#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
6pub enum ResponseStatus {
7 Success,
9 Failure,
11}
12
13#[must_use = "Authentication failure is not reported as an error, so the status field must be checked."]
15#[derive(PartialEq, Eq, Debug, Clone, Hash)]
16pub struct AuthenticationResponse {
17 pub status: ResponseStatus,
19
20 pub user_message: String,
22
23 pub data: Vec<u8>,
25}
26
27#[must_use = "The status of the response should be checked, since a failure is not reported as an error."]
29#[derive(PartialEq, Eq, Debug, Clone, Hash)]
30pub struct AuthorizationResponse {
31 pub status: ResponseStatus,
33
34 pub arguments: Vec<Argument<'static>>,
36
37 pub user_message: String,
39
40 pub admin_message: String,
42}
43
44#[derive(Debug, PartialEq, Eq, Clone, Hash)]
46pub struct AccountingResponse {
47 pub user_message: String,
49
50 pub admin_message: String,
52}
53
54#[doc(hidden)]
55pub struct BadAuthenticationStatus(pub(super) authentication::Status);
56
57#[doc(hidden)]
58impl TryFrom<authentication::Status> for ResponseStatus {
59 type Error = BadAuthenticationStatus;
60
61 fn try_from(value: authentication::Status) -> Result<Self, Self::Error> {
62 match value {
63 authentication::Status::Pass => Ok(ResponseStatus::Success),
64 authentication::Status::Fail => Ok(ResponseStatus::Failure),
65
66 #[allow(deprecated)]
69 authentication::Status::Follow => Ok(ResponseStatus::Failure),
70
71 authentication::Status::Restart => Ok(ResponseStatus::Failure),
74
75 bad_status => Err(BadAuthenticationStatus(bad_status)),
76 }
77 }
78}
79
80#[doc(hidden)]
81pub struct BadAuthorizationStatus(pub(super) authorization::Status);
82
83#[doc(hidden)]
84impl TryFrom<authorization::Status> for ResponseStatus {
85 type Error = BadAuthorizationStatus;
86
87 fn try_from(value: authorization::Status) -> Result<Self, Self::Error> {
88 match value {
89 authorization::Status::PassAdd | authorization::Status::PassReplace => {
90 Ok(ResponseStatus::Success)
91 }
92
93 authorization::Status::Fail => Ok(ResponseStatus::Failure),
94
95 #[allow(deprecated)]
98 authorization::Status::Follow => Ok(ResponseStatus::Failure),
99
100 bad_status => Err(BadAuthorizationStatus(bad_status)),
101 }
102 }
103}