Skip to content

Commit

Permalink
Allow backslash in idexchange handles with compat feature. (#305)
Browse files Browse the repository at this point in the history
This PR adjusts the changes made in #304 and allows backslashes in idexchange
handles if the compat feature is enabled. This is necessary to not break
Krill installations that used backslashes in their handles.
  • Loading branch information
partim authored Aug 20, 2024
1 parent 575a321 commit 1426c08
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ca/idexchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ pub type RecipientHandle = Handle<Recipient>;
/// entities. Handles are like strings, but they are restricted to the
/// following - taken from the RELAX NG schema in RFC 8183:
///
/// ```txt
/// handle = xsd:string { maxLength="255" pattern="[\-_A-Za-z0-9/]*" }
/// ```
///
/// Earlier versions of this library allowed backslash characters in the
/// handle as well. This behavior is maintained if the `compat` feature is
/// enabled.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq)]
#[serde(try_from = "String")]
pub struct Handle<T> {
Expand Down Expand Up @@ -139,6 +145,7 @@ impl<T> Handle<T> {
PathBuf::from(s)
}

#[cfg(not(feature = "compat"))]
fn verify_name(s: &str) -> Result<(), InvalidHandle> {
if s.bytes()
.all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_' || b == b'/')
Expand All @@ -150,6 +157,19 @@ impl<T> Handle<T> {
Err(InvalidHandle)
}
}

#[cfg(feature = "compat")]
fn verify_name(s: &str) -> Result<(), InvalidHandle> {
if s.bytes()
.all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_' || b == b'/' || b == b'\\')
&& !s.is_empty()
&& s.len() < 256
{
Ok(())
} else {
Err(InvalidHandle)
}
}
}

impl<T> TryFrom<&PathBuf> for Handle<T> {
Expand Down

0 comments on commit 1426c08

Please sign in to comment.