Skip to content

Commit

Permalink
fix User-Password authentication (eclipse-zenoh#776)
Browse files Browse the repository at this point in the history
* fix User-Password authentication 

Update usrpwd.rs to handle whitespace and blank lines in credentials.txt

* Format usrpwd.rs file
  • Loading branch information
vivekpandey02 authored and jerry73204 committed Mar 6, 2024
1 parent 2e824b3 commit e939975
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions io/zenoh-transport/src/unicast/establishment/ext/auth/usrpwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ impl AuthUsrPwd {
// usr3:pwd3
// I.e.: one <user>:<password> entry per line
for l in content.lines() {
let idx = l.find(':').ok_or_else(|| {
let line = l.trim();
if line.is_empty() {
continue;
}
let idx = line.find(':').ok_or_else(|| {
zerror!("{S} Invalid user-password dictionary file: invalid format.")
})?;
let user = l[..idx].as_bytes().to_owned();
let user = line[..idx].trim().as_bytes().to_owned();
if user.is_empty() {
bail!("{S} Invalid user-password dictionary file: empty user.")
}
let password = l[idx + 1..].as_bytes().to_owned();
let password = line[idx + 1..].trim().as_bytes().to_owned();
if password.is_empty() {
bail!("{S} Invalid user-password dictionary file: empty password.")
}
Expand Down

0 comments on commit e939975

Please sign in to comment.