| Crates.io | yourevalid |
| lib.rs | yourevalid |
| version | 0.2.0-alpha.3 |
| created_at | 2025-11-09 17:17:07.866811+00 |
| updated_at | 2026-01-04 01:12:57.350104+00 |
| description | Validation type and trait. For internal use in polyproto-related crates, currently |
| homepage | |
| repository | https://codeberg.org/polyphony/yourevalid |
| max_upload_size | |
| id | 1924303 |
| size | 79,171 |
yourevalidValidation type and trait. For internal use in polyproto-related crates, currently.
yourevalid provides a type-level guarantee system for validated and verified data through the Valid<T> wrapper type and the Validate trait. This crate is used in sonata and polyproto-rs.
Many types in cryptographic and security-sensitive contexts cannot guarantee their own validity. For example, a certificate might be well-formed but expired. yourevalid provides a way to explicitly distinguish between "a value of type T" and "a value of type T that has been verified and validated."
Valid<T> TypeLook, it's you! 🏳️🌈🏳️⚧️❤️
Valid<T> is a wrapper type that signals that the contained type T has been successfully verified and validated. New instances of this type can only be created through the Validate trait, ensuring that the validation logic has been executed.
Wow, it's you again! 🏳️🌈🏳️⚧️❤️
"Verified" means "Verified to be well-formed". A type that is verified must exhibit all the acceptance criteria and none of the rejection criteria according to its specification or documentation.
"Valid" means that, at a given point in time, one can attest that this specific instance of a type is cryptographically and contextually fit/allowed to make the claims that this instance is making. Most importantly, validity is time-sensitive and has only been attested to for a specific point in time. It must be carefully evaluated whether re-validation is necessary to maintain those guarantees if the instance is used to validate information from a different point in time.
Each Valid<T> instance tracks the exact time at which validation was performed (validated_at()). This is done because validity can change over time (e.g. a certificate can be revoked, or a time-bound credential can expire).
ID-Certs have a lifetime from not_valid_before to not_valid_after. Additionally, ID-Certs can be manually revoked or invalidated. This means that the well-formedness of an ID-Cert says nothing about whether it is valid at a certain point in time. The Valid<T> type helps establish that the validity of a specific ID-Cert has been verified at a certain point in time.
Implement the Validate trait on types where validity is not a guaranteed property:
use yourevalid::{Valid, Validate};
use chrono::{DateTime, Utc};
#[derive(Debug)]
struct MyCertificate {
// data...
}
impl Validate<MyCertificate> for MyCertificate {
type Error = MyValidationError;
// Use the default validate() implementation and provide
// your validation logic as a closure/function
}
// Later, validate an instance:
let cert = MyCertificate { /* ... */ };
let valid_cert: Valid<MyCertificate> = MyCertificate::validate(
Some(&db_pool),
cert,
Utc::now(),
|db, cert, time| {
// Your validation logic here
Ok(())
}
).await?;
// Access the validation timestamp
let validated_at = valid_cert.validated_at();
MPL-2.0
🏳️⚧️ Trans rights are human rights. Be gay, do crime!