mirror of
https://github.com/cubixle/radius-rs.git
synced 2026-04-30 16:58:39 +01:00
Correct unsuitable signature
This commit is contained in:
+3
-3
@@ -16,7 +16,7 @@ impl Attribute {
|
|||||||
Attribute(v.as_bytes().to_vec())
|
Attribute(v.as_bytes().to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bytes(v: &Vec<u8>) -> Self {
|
pub fn from_bytes(v: &[u8]) -> Self {
|
||||||
Attribute(v.to_vec())
|
Attribute(v.to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ impl Attribute {
|
|||||||
Attribute(v.octets().to_vec())
|
Attribute(v.octets().to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_user_password(plain_text: &Vec<u8>, secret: &Vec<u8>, request_authenticator: &Vec<u8>) -> Result<Self, String> {
|
pub fn from_user_password(plain_text: &[u8], secret: &[u8], request_authenticator: &[u8]) -> Result<Self, String> {
|
||||||
if plain_text.len() > 128 {
|
if plain_text.len() > 128 {
|
||||||
return Err("the length of plain_text has to be within 128, but the given value is longer".to_owned());
|
return Err("the length of plain_text has to be within 128, but the given value is longer".to_owned());
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ impl Attribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_user_password(&self, secret: &Vec<u8>, request_authenticator: &Vec<u8>) -> Result<Vec<u8>, String> {
|
pub fn to_user_password(&self, secret: &[u8], request_authenticator: &[u8]) -> Result<Vec<u8>, String> {
|
||||||
if self.0.len() < 16 || self.0.len() > 128 {
|
if self.0.len() < 16 || self.0.len() > 128 {
|
||||||
return Err(format!("invalid attribute length {}", self.0.len()));
|
return Err(format!("invalid attribute length {}", self.0.len()));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ pub struct AVP {
|
|||||||
pub struct Attributes(pub(crate) Vec<AVP>);
|
pub struct Attributes(pub(crate) Vec<AVP>);
|
||||||
|
|
||||||
impl Attributes {
|
impl Attributes {
|
||||||
pub(crate) fn parse_attributes(bs: &Vec<u8>) -> Result<Attributes, String> {
|
pub(crate) fn parse_attributes(bs: &[u8]) -> Result<Attributes, String> {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut attrs = Vec::new();
|
let mut attrs = Vec::new();
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -17,7 +17,7 @@ pub struct Packet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Packet {
|
impl Packet {
|
||||||
pub fn new(code: Code, secret: &Vec<u8>) -> Self {
|
pub fn new(code: Code, secret: &[u8]) -> Self {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let authenticator = (0..16).map(|_| rng.gen()).collect::<Vec<u8>>();
|
let authenticator = (0..16).map(|_| rng.gen()).collect::<Vec<u8>>();
|
||||||
Packet {
|
Packet {
|
||||||
@@ -33,11 +33,11 @@ impl Packet {
|
|||||||
self.identifier
|
self.identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_secret(&self) -> &Vec<u8> {
|
pub fn get_secret(&self) -> &Vec<u8> { // TODO
|
||||||
&self.secret
|
&self.secret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(bs: &Vec<u8>, secret: &Vec<u8>) -> Result<Self, String> {
|
pub fn parse(bs: &[u8], secret: &[u8]) -> Result<Self, String> {
|
||||||
if bs.len() < 20 {
|
if bs.len() < 20 {
|
||||||
return Err("radius packet doesn't have enough length of bytes; that has to be at least 20 bytes".to_owned());
|
return Err("radius packet doesn't have enough length of bytes; that has to be at least 20 bytes".to_owned());
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ impl Packet {
|
|||||||
].concat()).to_vec().eq(&response[4..20].to_vec())
|
].concat()).to_vec().eq(&response[4..20].to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_authentic_request(request: &Vec<u8>, secret: &Vec<u8>) -> bool {
|
pub fn is_authentic_request(request: &[u8], secret: &[u8]) -> bool {
|
||||||
if request.len() < 20 || secret.len() == 0 {
|
if request.len() < 20 || secret.len() == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ impl Server {
|
|||||||
|
|
||||||
async fn process_request<T: RequestHandler, U: SecretProvider>(
|
async fn process_request<T: RequestHandler, U: SecretProvider>(
|
||||||
conn: Arc<UdpSocket>,
|
conn: Arc<UdpSocket>,
|
||||||
request_data: &Vec<u8>,
|
request_data: &Vec<u8>, // TODO
|
||||||
local_addr: SocketAddr,
|
local_addr: SocketAddr,
|
||||||
remote_addr: SocketAddr,
|
remote_addr: SocketAddr,
|
||||||
undergoing_requests_lock: Arc<RwLock<HashSet<RequestKey>>>,
|
undergoing_requests_lock: Arc<RwLock<HashSet<RequestKey>>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user