//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vtc/auth/recognise`. Version: `0.2`.
#[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())
}
}
}
///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())
})
}
}
///`Payload`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vtc/auth/recognise/0.2",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "presentation"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "presentation": {
/// "description": "\nA holder-signed W3C Verifiable Presentation embedding the foreign membership and endorsement credentials in `verifiableCredential`.\n\nThe holder proof MUST use `proofPurpose: authentication`, MUST commit to the single-use `nonce` issued by `vtc/auth/recognise/challenge`, and MUST name the recognising community's DID as `domain`. A consumer MUST verify the holder proof, verify each embedded credential's issuer proof, and refuse unless the presentation's holder is the credentials' subject.",
/// "type": "object"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
/**
A holder-signed W3C Verifiable Presentation embedding the foreign membership and endorsement credentials in `verifiableCredential`.
The holder proof MUST use `proofPurpose: authentication`, MUST commit to the single-use `nonce` issued by `vtc/auth/recognise/challenge`, and MUST name the recognising community's DID as `domain`. A consumer MUST verify the holder proof, verify each embedded credential's issuer proof, and refuse unless the presentation's holder is the credentials' subject.*/
pub presentation: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "data",
/// "sessionId"
/// ],
/// "properties": {
/// "data": {
/// "type": "object",
/// "required": [
/// "accessExpiresAt",
/// "accessToken",
/// "foreignIssuerDid",
/// "mappedRole"
/// ],
/// "properties": {
/// "accessExpiresAt": {
/// "description": "Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "accessToken": {
/// "type": "string"
/// },
/// "foreignIssuerDid": {
/// "type": "string"
/// },
/// "mappedRole": {
/// "description": "The LOCAL role from cross_community_roles policy — not the foreign role.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "sessionId": {
/// "description": "A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.",
/// "type": "string",
/// "pattern": "^xc-"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
pub data: ResponseData,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.
#[serde(rename = "sessionId")]
pub session_id: ResponseSessionId,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseData`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "accessExpiresAt",
/// "accessToken",
/// "foreignIssuerDid",
/// "mappedRole"
/// ],
/// "properties": {
/// "accessExpiresAt": {
/// "description": "Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "accessToken": {
/// "type": "string"
/// },
/// "foreignIssuerDid": {
/// "type": "string"
/// },
/// "mappedRole": {
/// "description": "The LOCAL role from cross_community_roles policy — not the foreign role.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ResponseData {
///Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).
#[serde(rename = "accessExpiresAt")]
pub access_expires_at: u64,
#[serde(rename = "accessToken")]
pub access_token: ::std::string::String,
#[serde(rename = "foreignIssuerDid")]
pub foreign_issuer_did: ::std::string::String,
///The LOCAL role from cross_community_roles policy — not the foreign role.
#[serde(rename = "mappedRole")]
pub mapped_role: ::std::string::String,
}
impl ResponseData {
pub fn builder() -> builder::ResponseData {
Default::default()
}
}
///A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.",
/// "type": "string",
/// "pattern": "^xc-"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseSessionId(::std::string::String);
impl ::std::ops::Deref for ResponseSessionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseSessionId> for ::std::string::String {
fn from(value: ResponseSessionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseSessionId {
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("^xc-").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^xc-\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseSessionId {
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 ResponseSessionId {
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 ResponseSessionId {
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 ResponseSessionId {
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 Payload {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
presentation: ::std::result::Result<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
presentation: Err("no value supplied for presentation".to_string()),
}
}
}
impl Payload {
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 presentation<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
>,
T::Error: ::std::fmt::Display,
{
self.presentation = value
.try_into()
.map_err(|e| format!("error converting supplied value for presentation: {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 {
ext: value.ext?,
presentation: value.presentation?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
presentation: Ok(value.presentation),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
data: ::std::result::Result<super::ResponseData, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
session_id: ::std::result::Result<super::ResponseSessionId, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
data: Err("no value supplied for data".to_string()),
ext: Ok(Default::default()),
session_id: Err("no value supplied for session_id".to_string()),
}
}
}
impl Response {
pub fn data<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseData>,
T::Error: ::std::fmt::Display,
{
self.data = value
.try_into()
.map_err(|e| format!("error converting supplied value for data: {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 session_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseSessionId>,
T::Error: ::std::fmt::Display,
{
self.session_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_id: {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 {
data: value.data?,
ext: value.ext?,
session_id: value.session_id?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
data: Ok(value.data),
ext: Ok(value.ext),
session_id: Ok(value.session_id),
}
}
}
#[derive(Clone, Debug)]
pub struct ResponseData {
access_expires_at: ::std::result::Result<u64, ::std::string::String>,
access_token: ::std::result::Result<::std::string::String, ::std::string::String>,
foreign_issuer_did: ::std::result::Result<::std::string::String, ::std::string::String>,
mapped_role: ::std::result::Result<::std::string::String, ::std::string::String>,
}
impl ::std::default::Default for ResponseData {
fn default() -> Self {
Self {
access_expires_at: Err("no value supplied for access_expires_at".to_string()),
access_token: Err("no value supplied for access_token".to_string()),
foreign_issuer_did: Err("no value supplied for foreign_issuer_did".to_string()),
mapped_role: Err("no value supplied for mapped_role".to_string()),
}
}
}
impl ResponseData {
pub fn access_expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.access_expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for access_expires_at: {e}"));
self
}
pub fn access_token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.access_token = value
.try_into()
.map_err(|e| format!("error converting supplied value for access_token: {e}"));
self
}
pub fn foreign_issuer_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.foreign_issuer_did = value.try_into().map_err(|e| {
format!("error converting supplied value for foreign_issuer_did: {e}")
});
self
}
pub fn mapped_role<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::string::String>,
T::Error: ::std::fmt::Display,
{
self.mapped_role = value
.try_into()
.map_err(|e| format!("error converting supplied value for mapped_role: {e}"));
self
}
}
impl ::std::convert::TryFrom<ResponseData> for super::ResponseData {
type Error = super::error::ConversionError;
fn try_from(
value: ResponseData,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
access_expires_at: value.access_expires_at?,
access_token: value.access_token?,
foreign_issuer_did: value.foreign_issuer_did?,
mapped_role: value.mapped_role?,
})
}
}
impl ::std::convert::From<super::ResponseData> for ResponseData {
fn from(value: super::ResponseData) -> Self {
Self {
access_expires_at: Ok(value.access_expires_at),
access_token: Ok(value.access_token),
foreign_issuer_did: Ok(value.foreign_issuer_did),
mapped_role: Ok(value.mapped_role),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vtc/auth/recognise/0.2";
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"data\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"accessExpiresAt\": {\n \"description\": \"Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"accessToken\": {\n \"type\": \"string\"\n },\n \"foreignIssuerDid\": {\n \"type\": \"string\"\n },\n \"mappedRole\": {\n \"description\": \"The LOCAL role from cross_community_roles policy — not the foreign role.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"accessToken\",\n \"accessExpiresAt\",\n \"foreignIssuerDid\",\n \"mappedRole\"\n ],\n \"type\": \"object\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"sessionId\": {\n \"description\": \"A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.\",\n \"pattern\": \"^xc-\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"sessionId\",\n \"data\"\n ],\n \"title\": \"VTC Auth Recognise — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vtc/auth/recognise/0.2\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"presentation\": {\n \"description\": \"A holder-signed W3C Verifiable Presentation embedding the foreign membership and endorsement credentials in `verifiableCredential`.\\n\\nThe holder proof MUST use `proofPurpose: authentication`, MUST commit to the single-use `nonce` issued by `vtc/auth/recognise/challenge`, and MUST name the recognising community's DID as `domain`. A consumer MUST verify the holder proof, verify each embedded credential's issuer proof, and refuse unless the presentation's holder is the credentials' subject.\",\n \"type\": \"object\"\n }\n },\n \"required\": [\n \"presentation\"\n ],\n \"title\": \"VTC Auth Recognise — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vtc/auth/recognise/0.2#response";
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"data\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"accessExpiresAt\": {\n \"description\": \"Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"accessToken\": {\n \"type\": \"string\"\n },\n \"foreignIssuerDid\": {\n \"type\": \"string\"\n },\n \"mappedRole\": {\n \"description\": \"The LOCAL role from cross_community_roles policy — not the foreign role.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"accessToken\",\n \"accessExpiresAt\",\n \"foreignIssuerDid\",\n \"mappedRole\"\n ],\n \"type\": \"object\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"sessionId\": {\n \"description\": \"A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.\",\n \"pattern\": \"^xc-\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"sessionId\",\n \"data\"\n ],\n \"title\": \"VTC Auth Recognise — 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).
/// 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)] = &[
(
"Unknown top-level member is rejected.",
"{\n \"__x__\": true,\n \"presentation\": {}\n}",
),
("`presentation` is required.", "{}"),
(
"A 0.1-shaped body is rejected: `vec` and `vmc` were replaced by a holder-signed presentation in 0.2, and are now unknown members. Pins that a bare credential pair — the replayable form — cannot reach a 0.2 consumer.",
"{\n \"vec\": {},\n \"vmc\": {}\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
);
}
}
}