identifiers: Add a compat flag to allow arbitrary-length IDs
This commit is contained in:
parent
daea31dbe5
commit
10f651916f
@ -33,6 +33,9 @@ unstable-msc3932 = ["unstable-msc3931"]
|
|||||||
unstable-msc3958 = []
|
unstable-msc3958 = []
|
||||||
unstable-unspecified = []
|
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`.
|
# Don't validate the version part in `KeyId`.
|
||||||
compat-key-id = ["ruma-identifiers-validation/compat-key-id"]
|
compat-key-id = ["ruma-identifiers-validation/compat-key-id"]
|
||||||
|
|
||||||
|
@ -12,8 +12,12 @@ rust-version = { workspace = true }
|
|||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# Allow IDs to exceed 255 bytes.
|
||||||
|
compat-arbitrary-length-ids = []
|
||||||
|
|
||||||
# Don't validate the version part in `key_id::validate`.
|
# Don't validate the version part in `key_id::validate`.
|
||||||
compat-key-id = []
|
compat-key-id = []
|
||||||
|
|
||||||
# Allow some user IDs that are invalid even with the specified historical
|
# Allow some user IDs that are invalid even with the specified historical
|
||||||
# user ID scheme.
|
# user ID scheme.
|
||||||
compat-user-id = []
|
compat-user-id = []
|
||||||
|
@ -18,10 +18,12 @@ pub mod voip_version_id;
|
|||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|
||||||
/// All identifiers must be 255 bytes or less.
|
/// All identifiers must be 255 bytes or less.
|
||||||
|
#[cfg(not(feature = "compat-arbitrary-length-ids"))]
|
||||||
const MAX_BYTES: usize = 255;
|
const MAX_BYTES: usize = 255;
|
||||||
|
|
||||||
/// Checks if an identifier is valid.
|
/// Checks if an identifier is valid.
|
||||||
fn validate_id(id: &str, valid_sigils: &[char]) -> Result<(), Error> {
|
fn validate_id(id: &str, valid_sigils: &[char]) -> Result<(), Error> {
|
||||||
|
#[cfg(not(feature = "compat-arbitrary-length-ids"))]
|
||||||
if id.len() > MAX_BYTES {
|
if id.len() > MAX_BYTES {
|
||||||
return Err(Error::MaximumLengthExceeded);
|
return Err(Error::MaximumLengthExceeded);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,10 @@ compat = [
|
|||||||
"compat-signature-id",
|
"compat-signature-id",
|
||||||
"compat-tag-info",
|
"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`.
|
# Don't validate the version part in `KeyId`.
|
||||||
compat-key-id = ["ruma-common/compat-key-id"]
|
compat-key-id = ["ruma-common/compat-key-id"]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user