//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `auth/revoke-session`. 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())
})
}
}
///Invalidate one named session, every session of the producer, or every session of a named subject the producer may manage. The auth service drops the targeted session(s); any future use of their access or refresh tokens MUST fail. Exactly one of `sessionId`, `all` and `subject` is present.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/auth/revoke-session/0.2",
/// "title": "Payload",
/// "description": "Invalidate one named session, every session of the producer, or every session of a named subject the producer may manage. The auth service drops the targeted session(s); any future use of their access or refresh tokens MUST fail. Exactly one of `sessionId`, `all` and `subject` is present.",
/// "type": "object",
/// "properties": {
/// "all": {
/// "description": "When true, revoke every active session the consumer holds for the producer's own subject — equivalent to `subject` naming the producer. `false` targets nothing and is refused as malformedRequest; it stays schema-valid only because 0.1 admitted it. Mutually exclusive with `sessionId` and `subject`.",
/// "type": "boolean"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "reason": {
/// "description": "Optional human-readable rationale (e.g. \"logout\", \"device-lost\", \"access-withdrawn\"). Surfaced in audit logs; the framework imposes no vocabulary.",
/// "type": "string",
/// "maxLength": 1024
/// },
/// "sessionId": {
/// "description": "The session to revoke. Mutually exclusive with `all` and `subject`.",
/// "type": "string",
/// "minLength": 1
/// },
/// "subject": {
/// "description": "Revoke every active session the consumer holds for this subject. The producer's own identifier, or a subject whose access the producer could withdraw under the consumer's access-control policy — see Authorization. Mutually exclusive with `sessionId` and `all`.",
/// "type": "string",
/// "maxLength": 2048,
/// "pattern": "^did:"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///When true, revoke every active session the consumer holds for the producer's own subject — equivalent to `subject` naming the producer. `false` targets nothing and is refused as malformedRequest; it stays schema-valid only because 0.1 admitted it. Mutually exclusive with `sessionId` and `subject`.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub all: ::std::option::Option<bool>,
///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>,
///Optional human-readable rationale (e.g. "logout", "device-lost", "access-withdrawn"). Surfaced in audit logs; the framework imposes no vocabulary.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub reason: ::std::option::Option<PayloadReason>,
///The session to revoke. Mutually exclusive with `all` and `subject`.
#[serde(
rename = "sessionId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub session_id: ::std::option::Option<PayloadSessionId>,
///Revoke every active session the consumer holds for this subject. The producer's own identifier, or a subject whose access the producer could withdraw under the consumer's access-control policy — see Authorization. Mutually exclusive with `sessionId` and `all`.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub subject: ::std::option::Option<PayloadSubject>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
all: Default::default(),
ext: Default::default(),
reason: Default::default(),
session_id: Default::default(),
subject: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Optional human-readable rationale (e.g. "logout", "device-lost", "access-withdrawn"). Surfaced in audit logs; the framework imposes no vocabulary.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Optional human-readable rationale (e.g. \"logout\", \"device-lost\", \"access-withdrawn\"). Surfaced in audit logs; the framework imposes no vocabulary.",
/// "type": "string",
/// "maxLength": 1024
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadReason(::std::string::String);
impl ::std::ops::Deref for PayloadReason {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadReason> for ::std::string::String {
fn from(value: PayloadReason) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadReason {
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 PayloadReason {
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 PayloadReason {
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 PayloadReason {
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 PayloadReason {
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())
})
}
}
///The session to revoke. Mutually exclusive with `all` and `subject`.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The session to revoke. Mutually exclusive with `all` and `subject`.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSessionId(::std::string::String);
impl ::std::ops::Deref for PayloadSessionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSessionId> for ::std::string::String {
fn from(value: PayloadSessionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSessionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadSessionId {
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 PayloadSessionId {
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 PayloadSessionId {
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 PayloadSessionId {
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())
})
}
}
///Revoke every active session the consumer holds for this subject. The producer's own identifier, or a subject whose access the producer could withdraw under the consumer's access-control policy — see Authorization. Mutually exclusive with `sessionId` and `all`.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Revoke every active session the consumer holds for this subject. The producer's own identifier, or a subject whose access the producer could withdraw under the consumer's access-control policy — see Authorization. Mutually exclusive with `sessionId` and `all`.",
/// "type": "string",
/// "maxLength": 2048,
/// "pattern": "^did:"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSubject(::std::string::String);
impl ::std::ops::Deref for PayloadSubject {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSubject> for ::std::string::String {
fn from(value: PayloadSubject) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSubject {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 2048usize {
return Err("longer than 2048 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^did:").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadSubject {
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 PayloadSubject {
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 PayloadSubject {
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 PayloadSubject {
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())
})
}
}
///Acknowledgement carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/revoke-session/0.2#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "Acknowledgement carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/revoke-session/0.2#response.",
/// "type": "object",
/// "required": [
/// "revokedCount"
/// ],
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "revokedCount": {
/// "description": "Number of sessions this request invalidated. Zero is a valid outcome: the named session was already gone, or the subject held no active sessions.",
/// "type": "integer",
/// "minimum": 0.0
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///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>,
///Number of sessions this request invalidated. Zero is a valid outcome: the named session was already gone, or the subject held no active sessions.
#[serde(rename = "revokedCount")]
pub revoked_count: u64,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
all: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
reason: ::std::result::Result<
::std::option::Option<super::PayloadReason>,
::std::string::String,
>,
session_id: ::std::result::Result<
::std::option::Option<super::PayloadSessionId>,
::std::string::String,
>,
subject: ::std::result::Result<
::std::option::Option<super::PayloadSubject>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
all: Ok(Default::default()),
ext: Ok(Default::default()),
reason: Ok(Default::default()),
session_id: Ok(Default::default()),
subject: Ok(Default::default()),
}
}
}
impl Payload {
pub fn all<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.all = value
.try_into()
.map_err(|e| format!("error converting supplied value for all: {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 reason<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadReason>>,
T::Error: ::std::fmt::Display,
{
self.reason = value
.try_into()
.map_err(|e| format!("error converting supplied value for reason: {e}"));
self
}
pub fn session_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadSessionId>>,
T::Error: ::std::fmt::Display,
{
self.session_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_id: {e}"));
self
}
pub fn subject<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadSubject>>,
T::Error: ::std::fmt::Display,
{
self.subject = value
.try_into()
.map_err(|e| format!("error converting supplied value for subject: {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 {
all: value.all?,
ext: value.ext?,
reason: value.reason?,
session_id: value.session_id?,
subject: value.subject?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
all: Ok(value.all),
ext: Ok(value.ext),
reason: Ok(value.reason),
session_id: Ok(value.session_id),
subject: Ok(value.subject),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
revoked_count: ::std::result::Result<u64, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
revoked_count: Err("no value supplied for revoked_count".to_string()),
}
}
}
impl Response {
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 revoked_count<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.revoked_count = value
.try_into()
.map_err(|e| format!("error converting supplied value for revoked_count: {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 {
ext: value.ext?,
revoked_count: value.revoked_count?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
revoked_count: Ok(value.revoked_count),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/revoke-session/0.2";
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 \"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 \"description\": \"Acknowledgement carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/revoke-session/0.2#response.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"revokedCount\": {\n \"description\": \"Number of sessions this request invalidated. Zero is a valid outcome: the named session was already gone, or the subject held no active sessions.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"revokedCount\"\n ],\n \"title\": \"Auth Revoke Session — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/auth/revoke-session/0.2\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Invalidate one named session, every session of the producer, or every session of a named subject the producer may manage. The auth service drops the targeted session(s); any future use of their access or refresh tokens MUST fail. Exactly one of `sessionId`, `all` and `subject` is present.\",\n \"oneOf\": [\n {\n \"not\": {\n \"anyOf\": [\n {\n \"required\": [\n \"all\"\n ]\n },\n {\n \"required\": [\n \"subject\"\n ]\n }\n ]\n },\n \"required\": [\n \"sessionId\"\n ]\n },\n {\n \"not\": {\n \"anyOf\": [\n {\n \"required\": [\n \"sessionId\"\n ]\n },\n {\n \"required\": [\n \"subject\"\n ]\n }\n ]\n },\n \"required\": [\n \"all\"\n ]\n },\n {\n \"not\": {\n \"anyOf\": [\n {\n \"required\": [\n \"sessionId\"\n ]\n },\n {\n \"required\": [\n \"all\"\n ]\n }\n ]\n },\n \"required\": [\n \"subject\"\n ]\n }\n ],\n \"properties\": {\n \"all\": {\n \"description\": \"When true, revoke every active session the consumer holds for the producer's own subject — equivalent to `subject` naming the producer. `false` targets nothing and is refused as malformedRequest; it stays schema-valid only because 0.1 admitted it. Mutually exclusive with `sessionId` and `subject`.\",\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"reason\": {\n \"description\": \"Optional human-readable rationale (e.g. \\\"logout\\\", \\\"device-lost\\\", \\\"access-withdrawn\\\"). Surfaced in audit logs; the framework imposes no vocabulary.\",\n \"maxLength\": 1024,\n \"type\": \"string\"\n },\n \"sessionId\": {\n \"description\": \"The session to revoke. Mutually exclusive with `all` and `subject`.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"subject\": {\n \"description\": \"Revoke every active session the consumer holds for this subject. The producer's own identifier, or a subject whose access the producer could withdraw under the consumer's access-control policy — see Authorization. Mutually exclusive with `sessionId` and `all`.\",\n \"maxLength\": 2048,\n \"pattern\": \"^did:\",\n \"type\": \"string\"\n }\n },\n \"title\": \"Auth — Revoke Session\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/revoke-session/0.2#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 \"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 \"description\": \"Acknowledgement carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/revoke-session/0.2#response.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"revokedCount\": {\n \"description\": \"Number of sessions this request invalidated. Zero is a valid outcome: the named session was already gone, or the subject held no active sessions.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"revokedCount\"\n ],\n \"title\": \"Auth Revoke Session — 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;
}
/// 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::SESSION_NOT_FOUND];
/// 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 {
/// `auth/revoke-session:sessionNotFound`
///
/// The named `sessionId` is not a session the producer may revoke — it does not exist, was already revoked, or belongs to a subject outside the producer's authority. The consumer MUST answer all three identically, so the code discloses nothing about sessions the producer does not control. A consumer MAY instead answer all three with `revokedCount: 0`; see Conformance.
///
/// Declared `retryable: false`.
pub const SESSION_NOT_FOUND: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/revoke-session:sessionNotFound",
retryable: false,
};
}
#[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:4b5c6d7e-8f90-4a1b-8c2d-3e4f5a6b7c81\",\n \"type\": \"https://trusttasks.org/spec/auth/revoke-session/0.2\",\n \"issuer\": \"did:web:alice.example\",\n \"recipient\": \"did:web:auth.example\",\n \"issuedAt\": \"2026-09-27T11:00:00Z\",\n \"payload\": {\n \"sessionId\": \"ec5d3c89-3f49-49b2-9d7d-2a8c0a8a7b9b\",\n \"reason\": \"logout\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:alice.example#key-1\",\n \"created\": \"2026-09-27T11:00:00Z\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z3kg…\"\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 request_example_2() {
const JSON: &str = "{\n \"id\": \"urn:uuid:5c6d7e8f-9001-4b2c-9d3e-4f5a6b7c8d92\",\n \"type\": \"https://trusttasks.org/spec/auth/revoke-session/0.2\",\n \"issuer\": \"did:web:alice.example\",\n \"recipient\": \"did:web:auth.example\",\n \"issuedAt\": \"2026-09-27T11:00:00Z\",\n \"payload\": {\n \"all\": true,\n \"reason\": \"device-lost\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:alice.example#key-1\",\n \"created\": \"2026-09-27T11:00:00Z\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z3kg…\"\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 request_example_3() {
const JSON: &str = "{\n \"id\": \"urn:uuid:6d7e8f90-a112-4c3d-8e4f-5a6b7c8d9ea3\",\n \"type\": \"https://trusttasks.org/spec/auth/revoke-session/0.2\",\n \"issuer\": \"did:web:admin.example\",\n \"recipient\": \"did:web:auth.example\",\n \"issuedAt\": \"2026-09-27T11:05:00Z\",\n \"payload\": {\n \"subject\": \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n \"reason\": \"access-withdrawn\"\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:admin.example#key-1\",\n \"created\": \"2026-09-27T11:05:00Z\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z3kg…\"\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:7e8f90a1-b223-4d4e-9f5a-6b7c8d9eafb4\",\n \"type\": \"https://trusttasks.org/spec/auth/revoke-session/0.2#response\",\n \"threadId\": \"urn:uuid:6d7e8f90-a112-4c3d-8e4f-5a6b7c8d9ea3\",\n \"issuer\": \"did:web:auth.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-27T11:05:01Z\",\n \"payload\": {\n \"revokedCount\": 3\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)] = &[
(
"No target at all — the oneOf requires exactly one of `sessionId`, `all` and `subject`.",
"{\n \"reason\": \"logout\"\n}",
),
(
"`sessionId` and `all` together — mutually exclusive.",
"{\n \"all\": true,\n \"sessionId\": \"ec5d3c89-3f49-49b2-9d7d-2a8c0a8a7b9b\"\n}",
),
(
"`subject` and `sessionId` together — mutually exclusive. A producer cannot scope a single-session revoke to a subject; the session names its own subject.",
"{\n \"sessionId\": \"ec5d3c89-3f49-49b2-9d7d-2a8c0a8a7b9b\",\n \"subject\": \"did:web:alice.example\"\n}",
),
(
"`subject` and `all` together — mutually exclusive, and ambiguous about whose sessions are meant.",
"{\n \"all\": true,\n \"subject\": \"did:web:alice.example\"\n}",
),
(
"`subject` must be a DID — a bare handle would let the consumer guess which party is meant.",
"{\n \"subject\": \"alice\"\n}",
),
(
"Unknown top-level payload member.",
"{\n \"frobnicate\": true,\n \"subject\": \"did:web:alice.example\"\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
);
}
}
}