Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex constraint expressions are not currently supported #373

Open
Nicceboy opened this issue Nov 22, 2024 · 0 comments
Open

Complex constraint expressions are not currently supported #373

Nicceboy opened this issue Nov 22, 2024 · 0 comments

Comments

@Nicceboy
Copy link
Contributor

Nicceboy commented Nov 22, 2024

In general, ASN.1 supports multiple ranges in a constraint or combination of ranges and single value constraints.

However, rasn constraints support currently only a single constraint value per constraint type (excluding PermittedAlphabetConstraint).

This applies for constraint types that can have a multitude of single value and/or range value constraints applying into them at the same time, where the effective constraint value is not actually continuous and should be described as union.

For example:

#[derive(AsnType, Debug, Clone, Decode, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(delegate, size("3"), size("7"), size("9..15"))]
pub struct RestrictedString(pub OctetString);

The previous sample currently only notes the last constraint ("9..15"). Combining the values to the single size() call is not permitted.
Usually this is described with union or | syntax, so that all values are permitted from these.
If there are layers of types with different constraints, the effective constraint is intersection of all these constraints. Described with or ^ elsewhere as direct notation.

For most use-cases, the current functionality can be enough, but this should be noted some day.

It seems to be a non-trivial problem, if we want to do it mostly in compile-time.

PermittedAlphabetConstraint makes union currently on macro level, since it is easier for alphabets.
However, any additional intersections are not currently possible on compile-time as the constraint value is passed as static reference. Also proper runtime intersection is missing for this type.

Extensible constraint additions should be also noted for intersection/union support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant