//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vtc/auth/recognise`. Version: `0.1`.
#![allow(deprecated)]
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = Some("retired; use vtc/auth/recognise/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.
///
#[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`
///
#[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`
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "retired; use vtc/auth/recognise/0.2")]
pub struct Payload {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///A foreign-issued Verifiable Endorsement Credential carrying the role grant, with its own eddsa-jcs-2022 proof (opaque here).
pub vec: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
///A foreign-issued Verifiable Membership Credential proving membership, optionally with credentialStatus for live revocation (opaque here).
pub vmc: ::serde_json::Map<::std::string::String, ::serde_json::Value>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`Response`
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "retired; use vtc/auth/recognise/0.2")]
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`
///
#[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.
///
#[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>,
vec: ::std::result::Result<
::serde_json::Map<::std::string::String, ::serde_json::Value>,
::std::string::String,
>,
vmc: ::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()),
vec: Err("no value supplied for vec".to_string()),
vmc: Err("no value supplied for vmc".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 vec<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.vec = value
.try_into()
.map_err(|e| format!("error converting supplied value for vec: {e}"));
self
}
pub fn vmc<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.vmc = value
.try_into()
.map_err(|e| format!("error converting supplied value for vmc: {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?,
vec: value.vec?,
vmc: value.vmc?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
vec: Ok(value.vec),
vmc: Ok(value.vmc),
}
}
}
#[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.1";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"properties\":{\"data\":{\"additionalProperties\":false,\"properties\":{\"accessExpiresAt\":{\"description\":\"Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).\",\"minimum\":0,\"type\":\"integer\"},\"accessToken\":{\"type\":\"string\"},\"foreignIssuerDid\":{\"type\":\"string\"},\"mappedRole\":{\"description\":\"The LOCAL role from cross_community_roles policy — not the foreign role.\",\"type\":\"string\"}},\"required\":[\"accessToken\",\"accessExpiresAt\",\"foreignIssuerDid\",\"mappedRole\"],\"type\":\"object\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"sessionId\":{\"description\":\"A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.\",\"pattern\":\"^xc-\",\"type\":\"string\"}},\"required\":[\"sessionId\",\"data\"],\"title\":\"VTC Auth Recognise — response payload\",\"type\":\"object\"}},\"$id\":\"https://trusttasks.org/spec/vtc/auth/recognise/0.1\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"properties\":{\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"vec\":{\"description\":\"A foreign-issued Verifiable Endorsement Credential carrying the role grant, with its own eddsa-jcs-2022 proof (opaque here).\",\"type\":\"object\"},\"vmc\":{\"description\":\"A foreign-issued Verifiable Membership Credential proving membership, optionally with credentialStatus for live revocation (opaque here).\",\"type\":\"object\"}},\"required\":[\"vec\",\"vmc\"],\"title\":\"VTC Auth Recognise — payload\",\"type\":\"object\"}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vtc/auth/recognise/0.1#response";
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"properties\":{\"data\":{\"additionalProperties\":false,\"properties\":{\"accessExpiresAt\":{\"description\":\"Unix-seconds expiry, clamped to min(local default, earliest of the vec/vmc validUntil).\",\"minimum\":0,\"type\":\"integer\"},\"accessToken\":{\"type\":\"string\"},\"foreignIssuerDid\":{\"type\":\"string\"},\"mappedRole\":{\"description\":\"The LOCAL role from cross_community_roles policy — not the foreign role.\",\"type\":\"string\"}},\"required\":[\"accessToken\",\"accessExpiresAt\",\"foreignIssuerDid\",\"mappedRole\"],\"type\":\"object\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"sessionId\":{\"description\":\"A cross-community session id (xc-<uuid>), distinguishing it from local-member sessions.\",\"pattern\":\"^xc-\",\"type\":\"string\"}},\"required\":[\"sessionId\",\"data\"],\"title\":\"VTC Auth Recognise — response payload\",\"type\":\"object\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[
error_codes::CREDENTIAL_INVALID,
error_codes::ISSUER_NOT_RECOGNISED,
error_codes::ROLE_NOT_MAPPED,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `vtc/auth/recognise:credentialInvalid`
///
/// The vec or vmc failed proof verification, was expired, or was revoked via credentialStatus.
///
/// Declared `retryable: false`.
pub const CREDENTIAL_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "vtc/auth/recognise:credentialInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `vtc/auth/recognise:issuerNotRecognised`
///
/// The foreign issuer DID is not in this community's cross_community_roles policy.
///
/// Declared `retryable: false`.
pub const ISSUER_NOT_RECOGNISED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "vtc/auth/recognise:issuerNotRecognised",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `vtc/auth/recognise:roleNotMapped`
///
/// The foreign role has no mapping to a local role under policy.
///
/// Declared `retryable: false`.
pub const ROLE_NOT_MAPPED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "vtc/auth/recognise:roleNotMapped",
retryable: false,
details_schema: ::core::option::Option::None,
};
}