Skip to content

Commit

Permalink
Limit key name length
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Dec 23, 2024
1 parent e95fa3a commit 95d8b32
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/soroban-cli/src/config/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ pub enum Error {
Secret(#[from] secret::Error),
#[error("Address cannot be used to sign {0}")]
CannotSign(xdr::MuxedAccount),
#[error("Invalid key name: {0}\n only alphanumeric characters, `_`and `-` are allowed")]
#[error("Invalid key name: {0}\n only alphanumeric characters, underscores (_), and hyphens (-) are allowed.")]
InvalidKeyNameCharacters(String),
#[error("Invalid key name: {0}\n keys cannot exceed 250 characters")]
InvalidKeyNameLength(String),
#[error("Invalid key name: {0}\n keys cannot be the word \"ledger\"")]
InvalidKeyName(String),
}

Expand Down Expand Up @@ -93,11 +97,14 @@ impl std::str::FromStr for KeyName {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if !s.chars().all(allowed_char) {
return Err(Error::InvalidKeyName(s.to_string()));
return Err(Error::InvalidKeyNameCharacters(s.to_string()));
}
if s == "ledger" {
return Err(Error::InvalidKeyName(s.to_string()));
}
if s.len() > 250 {
return Err(Error::InvalidKeyNameLength(s.to_string()));
}
Ok(KeyName(s.to_string()))
}
}
Expand Down

0 comments on commit 95d8b32

Please sign in to comment.