Correct unsuitable signature

This commit is contained in:
moznion
2020-11-24 01:37:36 +09:00
parent 139afbee25
commit 7a036d58ad
4 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -16,7 +16,7 @@ impl Attribute {
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())
}
@@ -28,7 +28,7 @@ impl Attribute {
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 {
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 {
return Err(format!("invalid attribute length {}", self.0.len()));
}
+1 -1
View File
@@ -14,7 +14,7 @@ pub struct AVP {
pub struct Attributes(pub(crate) Vec<AVP>);
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 attrs = Vec::new();
+4 -4
View File
@@ -17,7 +17,7 @@ pub struct 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 authenticator = (0..16).map(|_| rng.gen()).collect::<Vec<u8>>();
Packet {
@@ -33,11 +33,11 @@ impl Packet {
self.identifier
}
pub fn get_secret(&self) -> &Vec<u8> {
pub fn get_secret(&self) -> &Vec<u8> { // TODO
&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 {
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())
}
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 {
return false;
}
+1 -1
View File
@@ -88,7 +88,7 @@ impl Server {
async fn process_request<T: RequestHandler, U: SecretProvider>(
conn: Arc<UdpSocket>,
request_data: &Vec<u8>,
request_data: &Vec<u8>, // TODO
local_addr: SocketAddr,
remote_addr: SocketAddr,
undergoing_requests_lock: Arc<RwLock<HashSet<RequestKey>>>,