#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "io.atcr.hold.scan",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Scan<S: BosStr = DefaultStr> {
pub critical: i64,
pub high: i64,
pub low: i64,
pub manifest: AtUri<S>,
pub medium: i64,
pub repository: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub sbom_blob: Option<BlobRef<S>>,
pub scanned_at: Datetime,
pub scanner_version: S,
pub total: i64,
pub user_did: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vuln_report_blob: Option<BlobRef<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ScanGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Scan<S>,
}
impl<S: BosStr> Scan<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ScanRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ScanRecord;
impl XrpcResp for ScanRecord {
const NSID: &'static str = "io.atcr.hold.scan";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ScanGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ScanGetRecordOutput<S>> for Scan<S> {
fn from(output: ScanGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Scan<S> {
const NSID: &'static str = "io.atcr.hold.scan";
type Record = ScanRecord;
}
impl Collection for ScanRecord {
const NSID: &'static str = "io.atcr.hold.scan";
type Record = ScanRecord;
}
impl<S: BosStr> LexiconSchema for Scan<S> {
fn nsid() -> &'static str {
"io.atcr.hold.scan"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_io_atcr_hold_scan()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.critical;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("critical"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.high;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("high"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.low;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("low"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.medium;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("medium"),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.repository;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("repository"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.sbom_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["application/spdx+json"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("sbom_blob"),
accepted: vec!["application/spdx+json".to_string()],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.scanner_version;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("scanner_version"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.total;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("total"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.vuln_report_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["application/vnd.atcr.vulnerabilities+json"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("vuln_report_blob"),
accepted: vec![
"application/vnd.atcr.vulnerabilities+json".to_string()
],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
pub mod scan_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Repository;
type Critical;
type Total;
type ScannedAt;
type Manifest;
type Medium;
type UserDid;
type ScannerVersion;
type Low;
type High;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repository = Unset;
type Critical = Unset;
type Total = Unset;
type ScannedAt = Unset;
type Manifest = Unset;
type Medium = Unset;
type UserDid = Unset;
type ScannerVersion = Unset;
type Low = Unset;
type High = Unset;
}
pub struct SetRepository<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRepository<St> {}
impl<St: State> State for SetRepository<St> {
type Repository = Set<members::repository>;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetCritical<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCritical<St> {}
impl<St: State> State for SetCritical<St> {
type Repository = St::Repository;
type Critical = Set<members::critical>;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetTotal<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTotal<St> {}
impl<St: State> State for SetTotal<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = Set<members::total>;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetScannedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetScannedAt<St> {}
impl<St: State> State for SetScannedAt<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = Set<members::scanned_at>;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetManifest<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetManifest<St> {}
impl<St: State> State for SetManifest<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = Set<members::manifest>;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetMedium<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMedium<St> {}
impl<St: State> State for SetMedium<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = Set<members::medium>;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetUserDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUserDid<St> {}
impl<St: State> State for SetUserDid<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = Set<members::user_did>;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = St::High;
}
pub struct SetScannerVersion<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetScannerVersion<St> {}
impl<St: State> State for SetScannerVersion<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = Set<members::scanner_version>;
type Low = St::Low;
type High = St::High;
}
pub struct SetLow<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLow<St> {}
impl<St: State> State for SetLow<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = Set<members::low>;
type High = St::High;
}
pub struct SetHigh<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetHigh<St> {}
impl<St: State> State for SetHigh<St> {
type Repository = St::Repository;
type Critical = St::Critical;
type Total = St::Total;
type ScannedAt = St::ScannedAt;
type Manifest = St::Manifest;
type Medium = St::Medium;
type UserDid = St::UserDid;
type ScannerVersion = St::ScannerVersion;
type Low = St::Low;
type High = Set<members::high>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repository(());
pub struct critical(());
pub struct total(());
pub struct scanned_at(());
pub struct manifest(());
pub struct medium(());
pub struct user_did(());
pub struct scanner_version(());
pub struct low(());
pub struct high(());
}
}
pub struct ScanBuilder<S: BosStr, St: scan_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<i64>,
Option<i64>,
Option<i64>,
Option<AtUri<S>>,
Option<i64>,
Option<S>,
Option<BlobRef<S>>,
Option<Datetime>,
Option<S>,
Option<i64>,
Option<Did<S>>,
Option<BlobRef<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Scan<S> {
pub fn new() -> ScanBuilder<S, scan_state::Empty> {
ScanBuilder::new()
}
}
impl<S: BosStr> ScanBuilder<S, scan_state::Empty> {
pub fn new() -> Self {
ScanBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Critical: scan_state::IsUnset,
{
pub fn critical(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<S, scan_state::SetCritical<St>> {
self._fields.0 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::High: scan_state::IsUnset,
{
pub fn high(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<S, scan_state::SetHigh<St>> {
self._fields.1 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Low: scan_state::IsUnset,
{
pub fn low(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<S, scan_state::SetLow<St>> {
self._fields.2 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Manifest: scan_state::IsUnset,
{
pub fn manifest(
mut self,
value: impl Into<AtUri<S>>,
) -> ScanBuilder<S, scan_state::SetManifest<St>> {
self._fields.3 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Medium: scan_state::IsUnset,
{
pub fn medium(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<S, scan_state::SetMedium<St>> {
self._fields.4 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Repository: scan_state::IsUnset,
{
pub fn repository(
mut self,
value: impl Into<S>,
) -> ScanBuilder<S, scan_state::SetRepository<St>> {
self._fields.5 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: scan_state::State> ScanBuilder<S, St> {
pub fn sbom_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_sbom_blob(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::ScannedAt: scan_state::IsUnset,
{
pub fn scanned_at(
mut self,
value: impl Into<Datetime>,
) -> ScanBuilder<S, scan_state::SetScannedAt<St>> {
self._fields.7 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::ScannerVersion: scan_state::IsUnset,
{
pub fn scanner_version(
mut self,
value: impl Into<S>,
) -> ScanBuilder<S, scan_state::SetScannerVersion<St>> {
self._fields.8 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Total: scan_state::IsUnset,
{
pub fn total(
mut self,
value: impl Into<i64>,
) -> ScanBuilder<S, scan_state::SetTotal<St>> {
self._fields.9 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::UserDid: scan_state::IsUnset,
{
pub fn user_did(
mut self,
value: impl Into<Did<S>>,
) -> ScanBuilder<S, scan_state::SetUserDid<St>> {
self._fields.10 = Option::Some(value.into());
ScanBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: scan_state::State> ScanBuilder<S, St> {
pub fn vuln_report_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_vuln_report_blob(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St> ScanBuilder<S, St>
where
St: scan_state::State,
St::Repository: scan_state::IsSet,
St::Critical: scan_state::IsSet,
St::Total: scan_state::IsSet,
St::ScannedAt: scan_state::IsSet,
St::Manifest: scan_state::IsSet,
St::Medium: scan_state::IsSet,
St::UserDid: scan_state::IsSet,
St::ScannerVersion: scan_state::IsSet,
St::Low: scan_state::IsSet,
St::High: scan_state::IsSet,
{
pub fn build(self) -> Scan<S> {
Scan {
critical: self._fields.0.unwrap(),
high: self._fields.1.unwrap(),
low: self._fields.2.unwrap(),
manifest: self._fields.3.unwrap(),
medium: self._fields.4.unwrap(),
repository: self._fields.5.unwrap(),
sbom_blob: self._fields.6,
scanned_at: self._fields.7.unwrap(),
scanner_version: self._fields.8.unwrap(),
total: self._fields.9.unwrap(),
user_did: self._fields.10.unwrap(),
vuln_report_blob: self._fields.11,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Scan<S> {
Scan {
critical: self._fields.0.unwrap(),
high: self._fields.1.unwrap(),
low: self._fields.2.unwrap(),
manifest: self._fields.3.unwrap(),
medium: self._fields.4.unwrap(),
repository: self._fields.5.unwrap(),
sbom_blob: self._fields.6,
scanned_at: self._fields.7.unwrap(),
scanner_version: self._fields.8.unwrap(),
total: self._fields.9.unwrap(),
user_did: self._fields.10.unwrap(),
vuln_report_blob: self._fields.11,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_io_atcr_hold_scan() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("io.atcr.hold.scan"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Vulnerability scan results for a container manifest. Stored in the hold's embedded PDS. Record key is deterministic: the manifest digest hex without the 'sha256:' prefix, so re-scans upsert the existing record.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("manifest"),
SmolStr::new_static("repository"),
SmolStr::new_static("userDid"),
SmolStr::new_static("critical"),
SmolStr::new_static("high"), SmolStr::new_static("medium"),
SmolStr::new_static("low"), SmolStr::new_static("total"),
SmolStr::new_static("scannerVersion"),
SmolStr::new_static("scannedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("critical"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("high"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("low"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("manifest"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI of the scanned manifest (e.g., at://did:plc:xyz/io.atcr.manifest/abc123...)",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("medium"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("repository"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Repository name (e.g., myapp)"),
),
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sbomBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("scannedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"RFC3339 timestamp of when the scan completed",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("scannerVersion"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Version of the scanner that produced this result (e.g., atcr-scanner-v1.0.0)",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("total"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("userDid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("DID of the image owner"),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("vulnReportBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}