identifiers: Add a compat flag to allow arbitrary-length IDs

This commit is contained in:
Jonas Platte 2023-09-27 16:25:53 +02:00
parent daea31dbe5
commit 10f651916f
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
4 changed files with 13 additions and 0 deletions

View File

@ -33,6 +33,9 @@ unstable-msc3932 = ["unstable-msc3931"]
unstable-msc3958 = []
unstable-unspecified = []
# Allow IDs to exceed 255 bytes.
compat-arbitrary-length-ids = ["ruma-identifiers-validation/compat-arbitrary-length-ids"]
# Don't validate the version part in `KeyId`.
compat-key-id = ["ruma-identifiers-validation/compat-key-id"]

View File

@ -12,8 +12,12 @@ rust-version = { workspace = true }
all-features = true
[features]
# Allow IDs to exceed 255 bytes.
compat-arbitrary-length-ids = []
# Don't validate the version part in `key_id::validate`.
compat-key-id = []
# Allow some user IDs that are invalid even with the specified historical
# user ID scheme.
compat-user-id = []

View File

@ -18,10 +18,12 @@ pub mod voip_version_id;
pub use error::Error;
/// All identifiers must be 255 bytes or less.
#[cfg(not(feature = "compat-arbitrary-length-ids"))]
const MAX_BYTES: usize = 255;
/// Checks if an identifier is valid.
fn validate_id(id: &str, valid_sigils: &[char]) -> Result<(), Error> {
#[cfg(not(feature = "compat-arbitrary-length-ids"))]
if id.len() > MAX_BYTES {
return Err(Error::MaximumLengthExceeded);
}

View File

@ -102,6 +102,10 @@ compat = [
"compat-signature-id",
"compat-tag-info",
]
# Allow IDs to exceed 255 bytes.
compat-arbitrary-length-ids = ["ruma-common/compat-arbitrary-length-ids"]
# Don't validate the version part in `KeyId`.
compat-key-id = ["ruma-common/compat-key-id"]