//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vta/backup/initiate-export`. Version: `1.0`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///The control-plane account of an out-of-band byte transfer. Shared in shape with initiate-import, where it describes an upload rather than a download.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Bundle descriptor",
/// "description": "The control-plane account of an out-of-band byte transfer. Shared in shape with initiate-import, where it describes an upload rather than a download.",
/// "type": "object",
/// "required": [
/// "algorithm",
/// "bundleId",
/// "expectedSha256",
/// "expectedSizeBytes",
/// "expiresAt",
/// "transportToken",
/// "transportUrl"
/// ],
/// "properties": {
/// "algorithm": {
/// "description": "The mechanism actually used, which is authoritative over what was requested.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
/// },
/// "bundleId": {
/// "description": "Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.",
/// "type": "string",
/// "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
/// },
/// "expectedSha256": {
/// "description": "Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.",
/// "type": "string",
/// "pattern": "^[0-9a-f]{64}$"
/// },
/// "expectedSizeBytes": {
/// "description": "Total byte count. A zero-length bundle is not a degenerate success — nothing was serialized — so the floor is 1.",
/// "type": "integer",
/// "minimum": 1.0
/// },
/// "expiresAt": {
/// "description": "After which the bytes are collected and the token refused. Short by design: the window is how long a fetchable copy of the agent exists.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "transportToken": {
/// "description": "Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.",
/// "type": "string",
/// "maxLength": 1024,
/// "minLength": 1
/// },
/// "transportUrl": {
/// "description": "Where to fetch the bytes. A recipient with no address at which it is reachable cannot produce this and refuses with transportUnavailable rather than returning an unfetchable one.",
/// "type": "string",
/// "format": "uri",
/// "maxLength": 2048
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct BundleDescriptor {
///The mechanism actually used, which is authoritative over what was requested.
pub algorithm: BundleDescriptorAlgorithm,
///Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.
#[serde(rename = "bundleId")]
pub bundle_id: BundleDescriptorBundleId,
///Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.
#[serde(rename = "expectedSha256")]
pub expected_sha256: BundleDescriptorExpectedSha256,
///Total byte count. A zero-length bundle is not a degenerate success — nothing was serialized — so the floor is 1.
#[serde(rename = "expectedSizeBytes")]
pub expected_size_bytes: ::std::num::NonZeroU64,
///After which the bytes are collected and the token refused. Short by design: the window is how long a fetchable copy of the agent exists.
#[serde(rename = "expiresAt")]
pub expires_at: ::chrono::DateTime<::chrono::offset::Utc>,
///Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.
#[serde(rename = "transportToken")]
pub transport_token: BundleDescriptorTransportToken,
///Where to fetch the bytes. A recipient with no address at which it is reachable cannot produce this and refuses with transportUnavailable rather than returning an unfetchable one.
#[serde(rename = "transportUrl")]
pub transport_url: ::std::string::String,
}
impl BundleDescriptor {
pub fn builder() -> builder::BundleDescriptor {
Default::default()
}
}
///The mechanism actually used, which is authoritative over what was requested.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The mechanism actually used, which is authoritative over what was requested.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct BundleDescriptorAlgorithm(::std::string::String);
impl ::std::ops::Deref for BundleDescriptorAlgorithm {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<BundleDescriptorAlgorithm> for ::std::string::String {
fn from(value: BundleDescriptorAlgorithm) -> Self {
value.0
}
}
impl ::std::str::FromStr for BundleDescriptorAlgorithm {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for BundleDescriptorAlgorithm {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for BundleDescriptorAlgorithm {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for BundleDescriptorAlgorithm {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for BundleDescriptorAlgorithm {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.",
/// "type": "string",
/// "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct BundleDescriptorBundleId(::std::string::String);
impl ::std::ops::Deref for BundleDescriptorBundleId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<BundleDescriptorBundleId> for ::std::string::String {
fn from(value: BundleDescriptorBundleId) -> Self {
value.0
}
}
impl ::std::str::FromStr for BundleDescriptorBundleId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
)
.unwrap()
});
if PATTERN.find(value).is_none() {
return Err(
"doesn't match pattern \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\""
.into(),
);
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for BundleDescriptorBundleId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for BundleDescriptorBundleId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for BundleDescriptorBundleId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for BundleDescriptorBundleId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.",
/// "type": "string",
/// "pattern": "^[0-9a-f]{64}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct BundleDescriptorExpectedSha256(::std::string::String);
impl ::std::ops::Deref for BundleDescriptorExpectedSha256 {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<BundleDescriptorExpectedSha256> for ::std::string::String {
fn from(value: BundleDescriptorExpectedSha256) -> Self {
value.0
}
}
impl ::std::str::FromStr for BundleDescriptorExpectedSha256 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^[0-9a-f]{64}$").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[0-9a-f]{64}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for BundleDescriptorExpectedSha256 {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for BundleDescriptorExpectedSha256 {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for BundleDescriptorExpectedSha256 {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for BundleDescriptorExpectedSha256 {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.",
/// "type": "string",
/// "maxLength": 1024,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct BundleDescriptorTransportToken(::std::string::String);
impl ::std::ops::Deref for BundleDescriptorTransportToken {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<BundleDescriptorTransportToken> for ::std::string::String {
fn from(value: BundleDescriptorTransportToken) -> Self {
value.0
}
}
impl ::std::str::FromStr for BundleDescriptorTransportToken {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1024usize {
return Err("longer than 1024 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for BundleDescriptorTransportToken {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for BundleDescriptorTransportToken {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for BundleDescriptorTransportToken {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for BundleDescriptorTransportToken {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Asks the recipient to serialize its entire state into a password-encrypted bundle and return the descriptor that fetches it. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vta/backup/initiate-export/1.0",
/// "title": "Payload",
/// "description": "Asks the recipient to serialize its entire state into a password-encrypted bundle and return the descriptor that fetches it. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "required": [
/// "password"
/// ],
/// "properties": {
/// "algorithm": {
/// "description": "Requested transport mechanism — how the bytes move, not how they are encrypted. `stream` is the only value this version defines and is what an absent member means. Deliberately not an enum: a recipient offering more must be askable for it without a specification revision, and one that does not implement the request refuses with unsupportedAlgorithm.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "includeAudit": {
/// "description": "Serialize the audit trail alongside the operational state. Absent means false — stated in prose rather than as a schema `default`, because a materialised default turns an omitted member into an asserted one in generated bindings, which is a different document.",
/// "type": "boolean"
/// },
/// "password": {
/// "description": "Key-derivation input protecting the bundle. Chosen by the producer and never recoverable from the recipient. `writeOnly` is the machine-readable form of the rule in Data carried: this member goes in and never comes back, so a generated client must not surface it in a response type, and a recipient must never log, echo or persist it. The minLength floor is a shape check only — a recipient may require more, and refuses with weakPassword.",
/// "writeOnly": true,
/// "type": "string",
/// "maxLength": 1024,
/// "minLength": 15,
/// "$comment": "No `format: password` — the annotation is advisory in 2020-12 and says less than writeOnly does. No example value anywhere in this directory: a specimen password is the one thing implementers copy."
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Requested transport mechanism — how the bytes move, not how they are encrypted. `stream` is the only value this version defines and is what an absent member means. Deliberately not an enum: a recipient offering more must be askable for it without a specification revision, and one that does not implement the request refuses with unsupportedAlgorithm.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub algorithm: ::std::option::Option<PayloadAlgorithm>,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Serialize the audit trail alongside the operational state. Absent means false — stated in prose rather than as a schema `default`, because a materialised default turns an omitted member into an asserted one in generated bindings, which is a different document.
#[serde(
rename = "includeAudit",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub include_audit: ::std::option::Option<bool>,
///Key-derivation input protecting the bundle. Chosen by the producer and never recoverable from the recipient. `writeOnly` is the machine-readable form of the rule in Data carried: this member goes in and never comes back, so a generated client must not surface it in a response type, and a recipient must never log, echo or persist it. The minLength floor is a shape check only — a recipient may require more, and refuses with weakPassword.
pub password: PayloadPassword,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Requested transport mechanism — how the bytes move, not how they are encrypted. `stream` is the only value this version defines and is what an absent member means. Deliberately not an enum: a recipient offering more must be askable for it without a specification revision, and one that does not implement the request refuses with unsupportedAlgorithm.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Requested transport mechanism — how the bytes move, not how they are encrypted. `stream` is the only value this version defines and is what an absent member means. Deliberately not an enum: a recipient offering more must be askable for it without a specification revision, and one that does not implement the request refuses with unsupportedAlgorithm.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadAlgorithm(::std::string::String);
impl ::std::ops::Deref for PayloadAlgorithm {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadAlgorithm> for ::std::string::String {
fn from(value: PayloadAlgorithm) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadAlgorithm {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadAlgorithm {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadAlgorithm {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadAlgorithm {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadAlgorithm {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Key-derivation input protecting the bundle. Chosen by the producer and never recoverable from the recipient. `writeOnly` is the machine-readable form of the rule in Data carried: this member goes in and never comes back, so a generated client must not surface it in a response type, and a recipient must never log, echo or persist it. The minLength floor is a shape check only — a recipient may require more, and refuses with weakPassword.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Key-derivation input protecting the bundle. Chosen by the producer and never recoverable from the recipient. `writeOnly` is the machine-readable form of the rule in Data carried: this member goes in and never comes back, so a generated client must not surface it in a response type, and a recipient must never log, echo or persist it. The minLength floor is a shape check only — a recipient may require more, and refuses with weakPassword.",
/// "writeOnly": true,
/// "type": "string",
/// "maxLength": 1024,
/// "minLength": 15,
/// "$comment": "No `format: password` — the annotation is advisory in 2020-12 and says less than writeOnly does. No example value anywhere in this directory: a specimen password is the one thing implementers copy."
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadPassword(::std::string::String);
impl ::std::ops::Deref for PayloadPassword {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadPassword> for ::std::string::String {
fn from(value: PayloadPassword) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadPassword {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1024usize {
return Err("longer than 1024 characters".into());
}
if value.chars().count() < 15usize {
return Err("shorter than 15 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadPassword {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadPassword {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadPassword {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadPassword {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "descriptor"
/// ],
/// "properties": {
/// "completionHint": {
/// "description": "Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.",
/// "type": "string",
/// "maxLength": 1024
/// },
/// "descriptor": {
/// "description": "Where the bytes are, what they should be, and until when.",
/// "$ref": "#/definitions/BundleDescriptor"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.
#[serde(
rename = "completionHint",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub completion_hint: ::std::option::Option<ResponseCompletionHint>,
///Where the bytes are, what they should be, and until when.
pub descriptor: BundleDescriptor,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.",
/// "type": "string",
/// "maxLength": 1024
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseCompletionHint(::std::string::String);
impl ::std::ops::Deref for ResponseCompletionHint {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseCompletionHint> for ::std::string::String {
fn from(value: ResponseCompletionHint) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseCompletionHint {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1024usize {
return Err("longer than 1024 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseCompletionHint {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ResponseCompletionHint {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ResponseCompletionHint {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ResponseCompletionHint {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct BundleDescriptor {
algorithm: ::std::result::Result<super::BundleDescriptorAlgorithm, ::std::string::String>,
bundle_id: ::std::result::Result<super::BundleDescriptorBundleId, ::std::string::String>,
expected_sha256:
::std::result::Result<super::BundleDescriptorExpectedSha256, ::std::string::String>,
expected_size_bytes: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
expires_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
transport_token:
::std::result::Result<super::BundleDescriptorTransportToken, ::std::string::String>,
transport_url: ::std::result::Result<::std::string::String, ::std::string::String>,
}
impl ::std::default::Default for BundleDescriptor {
fn default() -> Self {
Self {
algorithm: Err("no value supplied for algorithm".to_string()),
bundle_id: Err("no value supplied for bundle_id".to_string()),
expected_sha256: Err("no value supplied for expected_sha256".to_string()),
expected_size_bytes: Err("no value supplied for expected_size_bytes".to_string()),
expires_at: Err("no value supplied for expires_at".to_string()),
transport_token: Err("no value supplied for transport_token".to_string()),
transport_url: Err("no value supplied for transport_url".to_string()),
}
}
}
impl BundleDescriptor {
pub fn algorithm<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BundleDescriptorAlgorithm>,
T::Error: ::std::fmt::Display,
{
self.algorithm = value
.try_into()
.map_err(|e| format!("error converting supplied value for algorithm: {e}"));
self
}
pub fn bundle_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BundleDescriptorBundleId>,
T::Error: ::std::fmt::Display,
{
self.bundle_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for bundle_id: {e}"));
self
}
pub fn expected_sha256<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BundleDescriptorExpectedSha256>,
T::Error: ::std::fmt::Display,
{
self.expected_sha256 = value
.try_into()
.map_err(|e| format!("error converting supplied value for expected_sha256: {e}"));
self
}
pub fn expected_size_bytes<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.expected_size_bytes = value.try_into().map_err(|e| {
format!("error converting supplied value for expected_size_bytes: {e}")
});
self
}
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_at: {e}"));
self
}
pub fn transport_token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BundleDescriptorTransportToken>,
T::Error: ::std::fmt::Display,
{
self.transport_token = value
.try_into()
.map_err(|e| format!("error converting supplied value for transport_token: {e}"));
self
}
pub fn transport_url<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.transport_url = value
.try_into()
.map_err(|e| format!("error converting supplied value for transport_url: {e}"));
self
}
}
impl ::std::convert::TryFrom<BundleDescriptor> for super::BundleDescriptor {
type Error = super::error::ConversionError;
fn try_from(
value: BundleDescriptor,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
algorithm: value.algorithm?,
bundle_id: value.bundle_id?,
expected_sha256: value.expected_sha256?,
expected_size_bytes: value.expected_size_bytes?,
expires_at: value.expires_at?,
transport_token: value.transport_token?,
transport_url: value.transport_url?,
})
}
}
impl ::std::convert::From<super::BundleDescriptor> for BundleDescriptor {
fn from(value: super::BundleDescriptor) -> Self {
Self {
algorithm: Ok(value.algorithm),
bundle_id: Ok(value.bundle_id),
expected_sha256: Ok(value.expected_sha256),
expected_size_bytes: Ok(value.expected_size_bytes),
expires_at: Ok(value.expires_at),
transport_token: Ok(value.transport_token),
transport_url: Ok(value.transport_url),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
algorithm: ::std::result::Result<
::std::option::Option<super::PayloadAlgorithm>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
include_audit: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
password: ::std::result::Result<super::PayloadPassword, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
algorithm: Ok(Default::default()),
ext: Ok(Default::default()),
include_audit: Ok(Default::default()),
password: Err("no value supplied for password".to_string()),
}
}
}
impl Payload {
pub fn algorithm<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadAlgorithm>>,
T::Error: ::std::fmt::Display,
{
self.algorithm = value
.try_into()
.map_err(|e| format!("error converting supplied value for algorithm: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn include_audit<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.include_audit = value
.try_into()
.map_err(|e| format!("error converting supplied value for include_audit: {e}"));
self
}
pub fn password<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadPassword>,
T::Error: ::std::fmt::Display,
{
self.password = value
.try_into()
.map_err(|e| format!("error converting supplied value for password: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
algorithm: value.algorithm?,
ext: value.ext?,
include_audit: value.include_audit?,
password: value.password?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
algorithm: Ok(value.algorithm),
ext: Ok(value.ext),
include_audit: Ok(value.include_audit),
password: Ok(value.password),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
completion_hint: ::std::result::Result<
::std::option::Option<super::ResponseCompletionHint>,
::std::string::String,
>,
descriptor: ::std::result::Result<super::BundleDescriptor, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
completion_hint: Ok(Default::default()),
descriptor: Err("no value supplied for descriptor".to_string()),
ext: Ok(Default::default()),
}
}
}
impl Response {
pub fn completion_hint<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ResponseCompletionHint>>,
T::Error: ::std::fmt::Display,
{
self.completion_hint = value
.try_into()
.map_err(|e| format!("error converting supplied value for completion_hint: {e}"));
self
}
pub fn descriptor<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BundleDescriptor>,
T::Error: ::std::fmt::Display,
{
self.descriptor = value
.try_into()
.map_err(|e| format!("error converting supplied value for descriptor: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
completion_hint: value.completion_hint?,
descriptor: value.descriptor?,
ext: value.ext?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
completion_hint: Ok(value.completion_hint),
descriptor: Ok(value.descriptor),
ext: Ok(value.ext),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vta/backup/initiate-export/1.0";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"BundleDescriptor\": {\n \"additionalProperties\": false,\n \"description\": \"The control-plane account of an out-of-band byte transfer. Shared in shape with initiate-import, where it describes an upload rather than a download.\",\n \"properties\": {\n \"algorithm\": {\n \"description\": \"The mechanism actually used, which is authoritative over what was requested.\",\n \"maxLength\": 64,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"bundleId\": {\n \"description\": \"Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.\",\n \"pattern\": \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\",\n \"type\": \"string\"\n },\n \"expectedSha256\": {\n \"description\": \"Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.\",\n \"pattern\": \"^[0-9a-f]{64}$\",\n \"type\": \"string\"\n },\n \"expectedSizeBytes\": {\n \"description\": \"Total byte count. A zero-length bundle is not a degenerate success — nothing was serialized — so the floor is 1.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"expiresAt\": {\n \"description\": \"After which the bytes are collected and the token refused. Short by design: the window is how long a fetchable copy of the agent exists.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"transportToken\": {\n \"description\": \"Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.\",\n \"maxLength\": 1024,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"transportUrl\": {\n \"description\": \"Where to fetch the bytes. A recipient with no address at which it is reachable cannot produce this and refuses with transportUnavailable rather than returning an unfetchable one.\",\n \"format\": \"uri\",\n \"maxLength\": 2048,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"bundleId\",\n \"algorithm\",\n \"transportUrl\",\n \"transportToken\",\n \"expectedSha256\",\n \"expectedSizeBytes\",\n \"expiresAt\"\n ],\n \"title\": \"Bundle descriptor\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"completionHint\": {\n \"description\": \"Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.\",\n \"maxLength\": 1024,\n \"type\": \"string\"\n },\n \"descriptor\": {\n \"$ref\": \"#/$defs/BundleDescriptor\",\n \"description\": \"Where the bytes are, what they should be, and until when.\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n }\n },\n \"required\": [\n \"descriptor\"\n ],\n \"title\": \"VTA Backup Initiate Export — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vta/backup/initiate-export/1.0\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Asks the recipient to serialize its entire state into a password-encrypted bundle and return the descriptor that fetches it. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"algorithm\": {\n \"description\": \"Requested transport mechanism — how the bytes move, not how they are encrypted. `stream` is the only value this version defines and is what an absent member means. Deliberately not an enum: a recipient offering more must be askable for it without a specification revision, and one that does not implement the request refuses with unsupportedAlgorithm.\",\n \"maxLength\": 64,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"includeAudit\": {\n \"description\": \"Serialize the audit trail alongside the operational state. Absent means false — stated in prose rather than as a schema `default`, because a materialised default turns an omitted member into an asserted one in generated bindings, which is a different document.\",\n \"type\": \"boolean\"\n },\n \"password\": {\n \"$comment\": \"No `format: password` — the annotation is advisory in 2020-12 and says less than writeOnly does. No example value anywhere in this directory: a specimen password is the one thing implementers copy.\",\n \"description\": \"Key-derivation input protecting the bundle. Chosen by the producer and never recoverable from the recipient. `writeOnly` is the machine-readable form of the rule in Data carried: this member goes in and never comes back, so a generated client must not surface it in a response type, and a recipient must never log, echo or persist it. The minLength floor is a shape check only — a recipient may require more, and refuses with weakPassword.\",\n \"maxLength\": 1024,\n \"minLength\": 15,\n \"type\": \"string\",\n \"writeOnly\": true\n }\n },\n \"required\": [\n \"password\"\n ],\n \"title\": \"VTA Backup — Initiate Export — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/vta/backup/initiate-export/1.0#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"BundleDescriptor\": {\n \"additionalProperties\": false,\n \"description\": \"The control-plane account of an out-of-band byte transfer. Shared in shape with initiate-import, where it describes an upload rather than a download.\",\n \"properties\": {\n \"algorithm\": {\n \"description\": \"The mechanism actually used, which is authoritative over what was requested.\",\n \"maxLength\": 64,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"bundleId\": {\n \"description\": \"Handle for this bundle across its whole lifecycle. Quoted back by complete-export and abort. Recipient-generated and unguessable, which is what lets an unauthorized reference be answered as not-found without confirming existence.\",\n \"pattern\": \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$\",\n \"type\": \"string\"\n },\n \"expectedSha256\": {\n \"description\": \"Lowercase hex SHA-256 of the byte stream. Independent of the encrypted envelope's own authentication tag, so a truncated or substituted transfer is caught before the password is applied to it.\",\n \"pattern\": \"^[0-9a-f]{64}$\",\n \"type\": \"string\"\n },\n \"expectedSizeBytes\": {\n \"description\": \"Total byte count. A zero-length bundle is not a degenerate success — nothing was serialized — so the floor is 1.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"expiresAt\": {\n \"description\": \"After which the bytes are collected and the token refused. Short by design: the window is how long a fetchable copy of the agent exists.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"transportToken\": {\n \"description\": \"Bearer credential for transportUrl, presented in the X-Backup-Token header. Minted per bundle and never reused. A recipient should store only a hash of it and should accept it once — the token plus the URL is the export.\",\n \"maxLength\": 1024,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"transportUrl\": {\n \"description\": \"Where to fetch the bytes. A recipient with no address at which it is reachable cannot produce this and refuses with transportUnavailable rather than returning an unfetchable one.\",\n \"format\": \"uri\",\n \"maxLength\": 2048,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"bundleId\",\n \"algorithm\",\n \"transportUrl\",\n \"transportToken\",\n \"expectedSha256\",\n \"expectedSizeBytes\",\n \"expiresAt\"\n ],\n \"title\": \"Bundle descriptor\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"completionHint\": {\n \"description\": \"Operator-facing text describing how to complete the download. Advisory: a producer must not parse it or derive behaviour from it, and a recipient must not put a secret in it.\",\n \"maxLength\": 1024,\n \"type\": \"string\"\n },\n \"descriptor\": {\n \"$ref\": \"#/$defs/BundleDescriptor\",\n \"description\": \"Where the bytes are, what they should be, and until when.\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n }\n },\n \"required\": [\n \"descriptor\"\n ],\n \"title\": \"VTA Backup Initiate Export — response payload\",\n \"type\": \"object\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
#[test]
fn request_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000001\",\n \"type\": \"https://trusttasks.org/spec/vta/backup/initiate-export/1.0#request\",\n \"issuer\": \"did:example:operator\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"password\": \"correct horse battery staple\",\n \"includeAudit\": true\n }\n}\n";
let doc: crate::TrustTask<super::Payload> =
serde_json::from_str(JSON).expect("deserialize request example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "request example failed round-trip");
}
#[test]
fn response_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000002\",\n \"type\": \"https://trusttasks.org/spec/vta/backup/initiate-export/1.0#response\",\n \"issuer\": \"did:example:agent\",\n \"recipient\": \"did:example:operator\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"descriptor\": {\n \"bundleId\": \"3f2504e0-4f89-41d3-9a0c-0305e82c3301\",\n \"algorithm\": \"stream\",\n \"transportUrl\": \"https://agent.example/backup/blob/3f2504e0-4f89-41d3-9a0c-0305e82c3301\",\n \"transportToken\": \"dGhpcy1pcy1hLW9uZS1zaG90LWJlYXJlci10b2tlbg\",\n \"expectedSha256\": \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\n \"expectedSizeBytes\": 1048576,\n \"expiresAt\": \"2026-01-01T00:05:01Z\"\n },\n \"completionHint\": \"GET the transportUrl with header X-Backup-Token, then send complete-export.\"\n }\n}\n";
let doc: crate::TrustTask<super::Response> =
serde_json::from_str(JSON).expect("deserialize response example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "response example failed round-trip");
}
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[
(
"Missing `password`. There is no unencrypted export and no recipient-chosen default — an absent password must never read as 'encrypt it with something'.",
"{}",
),
(
"Short `password`. minLength is the shape floor; a recipient may require more and refuses with weakPassword. Caught here so the check happens before any state is serialized.",
"{\n \"password\": \"short\"\n}",
),
(
"Unbounded `algorithm` — §7.3 item 19. The value is echoed into the descriptor and into an audit entry; maxLength is what keeps both bounded.",
"{\n \"algorithm\": \"sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\",\n \"password\": \"a sufficiently long secret\"\n}",
),
(
"`includeAudit` as the string \"true\". A producer that means to exclude the trail and sends \"false\" would otherwise be read as truthy by a lenient consumer, widening the bundle silently.",
"{\n \"includeAudit\": \"true\",\n \"password\": \"a sufficiently long secret\"\n}",
),
(
"Bare/unnamespaced ext key — SPEC §4.5.1 requires every immediate child of ext to be reverse-DNS namespaced.",
"{\n \"ext\": {\n \"bare-key\": {\n \"anything\": \"here\"\n }\n },\n \"password\": \"a sufficiently long secret\"\n}",
),
(
"Unknown top-level member — additionalProperties: false catches `bundleId`. The producer asks for an export; it does not name the bundle, because minting the handle is what the recipient is being asked to do.",
"{\n \"bundleId\": \"3f2504e0-4f89-41d3-9a0c-0305e82c3301\",\n \"password\": \"a sufficiently long secret\"\n}",
),
];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}