#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod checksum;
pub mod discovery;
pub mod enums;
pub mod error;
pub mod http_cache;
pub mod ids;
pub mod lifecycle;
pub mod lock;
pub mod model;
pub mod pep440;
pub mod policy;
pub mod purl;
pub mod signature_format;
pub mod tei;
pub mod vers;
pub mod version;
pub use semver;
pub use url;
pub use uuid;
pub use checksum::{
verify_checksums, verify_checksums_with_policy, Checksum, ChecksumCheck, ChecksumPolicy,
ChecksumVerifier, IntegrityOutcome, IntegrityReport,
};
pub use discovery::{is_json_content_type, tea_error_code, DiscoveryInfo, WellKnownDocument};
pub use enums::{ChecksumAlgorithm, SortOrder};
pub use error::{escape_control_chars, ModelError, PolicyError, TeiError};
pub use ids::{
ArtifactId, CollectionId, ComponentId, ComponentReleaseId, DistributionId, ProductId,
ProductReleaseId, TeaTimestamp, TeaUuid,
};
pub use lifecycle::{LifecycleStatus, Unevaluated};
pub use lock::{
diff as diff_locks, ChangedArtifact, FieldChange, LockDiff, LockFile, LockedArtifact,
LockedChecksum, LockedIntegrity, LOCK_SCHEMA_VERSION,
};
pub use model::{
parse_artifact, parse_collection, parse_component_release, parse_product_release, Artifact,
ArtifactFormat, Cle, Collection, Component, ComponentRef, ComponentRelease,
ComponentReleaseWithCollection, Identifier, Page, Product, ProductRelease,
ProductReleaseWithCollection, TeaErrorBody, TokenResponse,
};
pub use pep440::{Pep440Error, Pep440Version};
pub use policy::{classify_ip, origin_key, parse_api_base, DestinationPolicy, IpClass};
pub use purl::{same_package_url, CanonicalPurl, Purl, PurlError, PurlRules, PurlTypeError};
pub use signature_format::{detect_signature_format, SignatureFormat};
pub use tei::{encode_query_component, Tei};
pub use version::{
select_endpoints, versioned_api_prefix, ApiVersion, SelectedEndpoint, SupportedApi,
};
pub mod spec {
pub const REPOSITORY: &str = "https://github.com/CycloneDX/transparency-exchange-api";
pub const BRANCH: &str = "main";
pub const COMMIT: &str = "962a0228af1bfcc1232ac3f79239317ff33fdb04";
pub const COMMIT_DATE: &str = "2026-10-08T06:28:26Z";
pub const RETRIEVAL_DATE: &str = "2026-10-10";
pub const SPEC_VERSION: &str = "1.0.0";
pub const OPENAPI_VERSION: &str = "3.1.1";
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ListParams<S> {
pub page_size: Option<u32>,
pub page_token: Option<String>,
pub sort_field: Option<S>,
pub sort_order: Option<enums::SortOrder>,
pub id_type: Option<enums::IdentifierType>,
pub id_value: Option<String>,
}
impl<S> Default for ListParams<S> {
fn default() -> Self {
Self {
page_size: None,
page_token: None,
sort_field: None,
sort_order: None,
id_type: None,
id_value: None,
}
}
}
impl<S> ListParams<S> {
#[must_use]
pub fn with_page_size(mut self, size: u32) -> Self {
self.page_size = Some(size);
self
}
#[must_use]
pub fn with_page_token(mut self, token: impl Into<String>) -> Self {
self.page_token = Some(token.into());
self
}
#[must_use]
pub fn with_sort_field(mut self, field: S) -> Self {
self.sort_field = Some(field);
self
}
#[must_use]
pub fn with_sort_order(mut self, order: enums::SortOrder) -> Self {
self.sort_order = Some(order);
self
}
#[must_use]
pub fn with_id_type(mut self, id_type: enums::IdentifierType) -> Self {
self.id_type = Some(id_type);
self
}
#[must_use]
pub fn with_id_value(mut self, id_value: impl Into<String>) -> Self {
self.id_value = Some(id_value.into());
self
}
pub fn validate(&self) -> Result<(), ModelError> {
if let Some(size) = self.page_size {
if !(1..=100).contains(&size) {
return Err(ModelError::Invalid("pageSize must be from 1 to 100".into()));
}
}
if self.id_value.is_some() && self.id_type.is_none() {
return Err(ModelError::Invalid("idValue requires idType".into()));
}
Ok(())
}
}
#[cfg(doctest)]
mod non_exhaustive_guards;
#[cfg(test)]
mod tests {
use super::ListParams;
use crate::enums::{ComponentSort, IdentifierType, SortOrder};
struct SortWithoutDefault;
fn params(id_type: Option<IdentifierType>, id_value: Option<&str>) -> ListParams<()> {
ListParams {
page_size: None,
page_token: None,
sort_field: None,
sort_order: None,
id_type,
id_value: id_value.map(str::to_owned),
}
}
#[test]
fn neither_identifier_field_is_accepted() {
assert!(params(None, None).validate().is_ok());
}
#[test]
fn both_identifier_fields_are_accepted() {
assert!(
params(Some(IdentifierType::Purl), Some("pkg:generic/widget@1"))
.validate()
.is_ok()
);
}
#[test]
fn id_type_without_id_value_is_accepted() {
assert!(params(Some(IdentifierType::ComplianceDocument), None)
.validate()
.is_ok());
}
#[test]
fn id_value_without_id_type_requires_id_type() {
let error = params(None, Some("pkg:generic/widget@1"))
.validate()
.unwrap_err();
assert_eq!(error.to_string(), "idValue requires idType");
}
#[test]
fn default_leaves_every_field_unset_without_a_default_sort() {
let query = ListParams::<SortWithoutDefault>::default();
assert!(query.page_size.is_none());
assert!(query.page_token.is_none());
assert!(query.sort_field.is_none());
assert!(query.sort_order.is_none());
assert!(query.id_type.is_none());
assert!(query.id_value.is_none());
assert!(query.validate().is_ok());
let components = ListParams::<ComponentSort>::default();
assert!(components.sort_field.is_none());
assert!(components.validate().is_ok());
let value_only = ListParams::<ComponentSort> {
id_value: Some("pkg:generic/widget@1".to_owned()),
..ListParams::default()
};
assert_eq!(
value_only.validate().unwrap_err().to_string(),
"idValue requires idType"
);
}
#[test]
fn page_size_bounds_are_unchanged_for_a_type_only_filter() {
let mut query = params(Some(IdentifierType::ComplianceDocument), None);
query.page_size = Some(0);
query.sort_order = Some(SortOrder::Desc);
assert!(query.validate().is_err());
query.page_size = Some(101);
assert!(query.validate().is_err());
query.page_size = Some(1);
assert!(query.validate().is_ok());
query.page_size = Some(100);
assert!(query.validate().is_ok());
}
}