Skip to content

Commit

Permalink
Clean crl, default builder values
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicceboy committed Dec 1, 2024
1 parent e56349e commit cd75c40
Show file tree
Hide file tree
Showing 6 changed files with 681 additions and 517 deletions.
14 changes: 11 additions & 3 deletions src/error/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub enum InnerSubtypeConstraintError {
},

/// Subtype constraint violation: required component is missing
#[snafu(display(
"Missing required component in {type_name}: at least one of {components:?} must be present"
))]
#[snafu(display("Missing required components in {type_name}: all must be present:"))]
MissingRequiredComponent {
/// The name of the type where the required component is missing.
type_name: &'static str,
Expand All @@ -42,4 +40,14 @@ pub enum InnerSubtypeConstraintError {
/// List of mutually exclusive components that are present.
components: &'static [&'static str],
},
/// Invalid value for a component
#[snafu(display("Invalid value for component {component_name} in {type_name}: {details}"))]
InvalidComponentValue {
/// The name of the type where the invalid component value was found.
type_name: &'static str,
/// The name of the component with the invalid value.
component_name: &'static str,
/// Detailed information about the invalid component value.
details: alloc::string::String,
},
}
13 changes: 12 additions & 1 deletion src/types/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
//! Constraints of values on a given type.
use super::IntegerType;
use crate::Codec;
use num_bigint::BigInt;

/// A marker trait for types that have inner subtype constraints.
pub trait InnerSubtypeConstraint: Sized {
/// Validates the inner subtype constraints and returns the type on success.
fn validated(self) -> Result<Self, crate::error::InnerSubtypeConstraintError>;
fn validate_components(self) -> Result<Self, crate::error::InnerSubtypeConstraintError>;

/// Validates the inner subtype constraints and attempts to decode internal ASN.1 `CONTAINING` constraints as a marked type.
/// Usually this means that some field has `OPAQUE` data, and we need to decode it further as a specific type, as defined in the inner subtype constraint.
#[allow(unused_variables)]
fn validate_and_decode_containing(
self,
decoder: Codec,
) -> Result<Self, crate::error::InnerSubtypeConstraintError> {
Ok(self)
}
}

/// A set of constraints for a given type on what kinds of values are allowed.
Expand Down
6 changes: 5 additions & 1 deletion standards/ieee1609dot2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ The standard can be found [here](https://standards.ieee.org/ieee/1609.2/10258/).
The crate contains `rasn` ASN.1 data structures for the IEEE 1609.2-2022 standard.
The data structures have been partially constructed with compiler, but they have been manually modified and verified to make them more usable. They also haven been modified to be more idiomatic Rust.

Comments have been edited and shortened to be more suitable for Rust documentation.
Claude 3.5 has been used on this process. The output has been reviewed.
You should always rely on the original standard for the most accurate information.

Basic features:
* All `newtype`'s implement `Deref` and `DerefMut` the inner type.
* `From` and `Into` implementations for converting between similar types.
* Most structs use `builder` pattern for construction with [bon](https://github.com/elastio/bon) crate.
* For types with inner subtype constraints `validated()` trait method is available. It is automatically used on type construction, but for decoded types, this is left to the user.
* For types with inner subtype constraints `validate_components()` trait method is available. It is automatically used on type construction, but for decoded types, this is left to the user.
2 changes: 1 addition & 1 deletion standards/ieee1609dot2/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ pub struct SequenceOfPsidSsp(pub SequenceOf<PsidSsp>);

delegate!(SequenceOf<PsidSsp>, SequenceOfPsidSsp);

/// This type represents the PSID defined in IEEE Std 1609.12.
/// This type represents the PSID defined in IEEE Std 1609.2.
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, value("0.."))]
pub struct Psid(pub Integer);
Expand Down
Loading

0 comments on commit cd75c40

Please sign in to comment.