Struct radius_rust::client::client::Client
source · pub struct Client { /* private fields */ }
Expand description
Represents RADIUS Generic Client instance
Implementations§
source§impl Client
impl Client
sourcepub fn with_dictionary(dictionary: Dictionary) -> Client
pub fn with_dictionary(dictionary: Dictionary) -> Client
Initialise Client instance with dictionary (other fields would be set to default values)
To be called first when creating RADIUS Client instance
sourcepub fn set_server(self, server: String) -> Client
pub fn set_server(self, server: String) -> Client
Required
Sets hostname to which client would attempt to send RADIUS packets
sourcepub fn set_secret(self, secret: String) -> Client
pub fn set_secret(self, secret: String) -> Client
Required
Sets secret which is used to encode/decode RADIUS packet
sourcepub fn set_port(self, msg_type: RadiusMsgType, port: u16) -> Client
pub fn set_port(self, msg_type: RadiusMsgType, port: u16) -> Client
Required/Optional
Sets remote port, that responsible for specific RADIUS Message Type
sourcepub fn set_retries(self, retries: u16) -> Client
pub fn set_retries(self, retries: u16) -> Client
Optional
Sets socket retries, otherwise you would have a default value of 1
sourcepub fn set_timeout(self, timeout: u16) -> Client
pub fn set_timeout(self, timeout: u16) -> Client
Optional
Sets socket timeout, otherwise you would have a default value of 2
sourcepub fn port(&self, code: &TypeCode) -> Option<u16>
pub fn port(&self, code: &TypeCode) -> Option<u16>
Returns port of RADIUS server, that receives given type of RADIUS message/packet
sourcepub fn create_packet(&self, code: TypeCode) -> RadiusPacket
pub fn create_packet(&self, code: TypeCode) -> RadiusPacket
Creates RADIUS packet with any TypeCode without attributes
You would need to set attributes manually via set_attributes() function
sourcepub fn create_auth_packet(&self) -> RadiusPacket
pub fn create_auth_packet(&self) -> RadiusPacket
Creates RADIUS Access Request packet
You would need to set attributes manually via set_attributes() function
sourcepub fn create_acct_packet(&self) -> RadiusPacket
pub fn create_acct_packet(&self) -> RadiusPacket
Creates RADIUS Accounting Request packet without attributes
You would need to set attributes manually via set_attributes() function
sourcepub fn create_coa_packet(&self) -> RadiusPacket
pub fn create_coa_packet(&self) -> RadiusPacket
Creates RADIUS CoA Request packet without attributes
You would need to set attributes manually via set_attributes() function
sourcepub fn create_attribute_by_name(
&self,
attribute_name: &str,
value: Vec<u8>
) -> Result<RadiusAttribute, RadiusError>
pub fn create_attribute_by_name( &self, attribute_name: &str, value: Vec<u8> ) -> Result<RadiusAttribute, RadiusError>
Creates RADIUS packet attribute by name, that is defined in dictionary file
§Examples
use radius_rust::client::client::Client;
use radius_rust::protocol::dictionary::Dictionary;
use radius_rust::protocol::radius_packet::TypeCode;
fn main() {
let dictionary = Dictionary::from_file("./dict_examples/integration_dict").unwrap();
let client = Client::with_dictionary(dictionary)
.set_server(String::from("127.0.0.1"))
.set_secret(String::from("secret"))
.set_retries(1)
.set_timeout(2);
client.create_attribute_by_name("User-Name", String::from("testing").into_bytes());
}
sourcepub fn create_attribute_by_id(
&self,
attribute_id: u8,
value: Vec<u8>
) -> Result<RadiusAttribute, RadiusError>
pub fn create_attribute_by_id( &self, attribute_id: u8, value: Vec<u8> ) -> Result<RadiusAttribute, RadiusError>
Creates RADIUS packet attribute by ID, that is defined in dictionary file
§Examples
use radius_rust::client::client::Client;
use radius_rust::protocol::dictionary::Dictionary;
use radius_rust::protocol::radius_packet::TypeCode;
fn main() {
let dictionary = Dictionary::from_file("./dict_examples/integration_dict").unwrap();
let client = Client::with_dictionary(dictionary)
.set_server(String::from("127.0.0.1"))
.set_secret(String::from("secret"))
.set_retries(1)
.set_timeout(2);
client.create_attribute_by_id(1, String::from("testing").into_bytes());
}
sourcepub fn generate_message_hash(&self, packet: &mut RadiusPacket) -> Vec<u8>
👎Deprecated since 0.4.1: This function may work incorrectly, please use radius_packet’s generate_message_authenticator
instead
pub fn generate_message_hash(&self, packet: &mut RadiusPacket) -> Vec<u8>
generate_message_authenticator
insteadGenerates HMAC-MD5 hash for Message-Authenticator attribute
Note 1: this function assumes that RadiusAttribute Message-Authenticator already exists in RadiusPacket Note 2: this function only works correctly when Message-Authenticator is set to exactly [0;16] Note 3: this function would be removed in 0.5.0
sourcepub fn radius_attr_original_string_value(
&self,
attribute: &RadiusAttribute
) -> Result<String, RadiusError>
pub fn radius_attr_original_string_value( &self, attribute: &RadiusAttribute ) -> Result<String, RadiusError>
Gets the original value as a String
If the RadiusAttribute respresents dictionary attribute of type: string, ipaddr, ipv6addr or ipv6prefix
sourcepub fn radius_attr_original_integer_value(
&self,
attribute: &RadiusAttribute
) -> Result<u32, RadiusError>
pub fn radius_attr_original_integer_value( &self, attribute: &RadiusAttribute ) -> Result<u32, RadiusError>
Gets the original value as an Integer
If the RadiusAttribute respresents dictionary attribute of type: integer or date
sourcepub fn initialise_packet_from_bytes(
&self,
reply: &[u8]
) -> Result<RadiusPacket, RadiusError>
pub fn initialise_packet_from_bytes( &self, reply: &[u8] ) -> Result<RadiusPacket, RadiusError>
Initialises RadiusPacket from bytes
sourcepub fn verify_reply(
&self,
request: &RadiusPacket,
reply: &[u8]
) -> Result<(), RadiusError>
pub fn verify_reply( &self, request: &RadiusPacket, reply: &[u8] ) -> Result<(), RadiusError>
Verifies that reply packet’s ID and authenticator are a match
sourcepub fn verify_message_authenticator(
&self,
packet: &[u8]
) -> Result<(), RadiusError>
pub fn verify_message_authenticator( &self, packet: &[u8] ) -> Result<(), RadiusError>
Verifies that reply packet’s Message-Authenticator attribute is valid
sourcepub fn verify_packet_attributes(&self, packet: &[u8]) -> Result<(), RadiusError>
pub fn verify_packet_attributes(&self, packet: &[u8]) -> Result<(), RadiusError>
Verifies that reply packet’s attributes have valid values