//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `keys/export-secret`. Version: `0.1`.
#[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())
})
}
}
///Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256), and `mldsa44` and `mldsa65` sign with the post-quantum ML-DSA scheme of US NIST FIPS 204. The set is expected to grow as algorithms are standardised, and growing it is a MINOR change under SPEC.md §5.2: `keyType` selects no schema branch, so adding a value relaxes a constraint rather than narrowing one, and the generated libraries mark this enumeration non-exhaustive so that a consumer absorbs a new value rather than failing to compile. Two ML-DSA parameter sets are carried because two specifications require different ones — W3C Quantum-Resistant Cryptosuites defines Data Integrity suites only for ML-DSA-44, while Trust Spanning Protocol Rev 3 §8.1 mandates ML-DSA-65 — so the parameter set is chosen by whatever consumes the key and the two are not redundant. A consumer that does not implement a value it receives MUST refuse the document rather than substitute one it does support.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "KeyType",
/// "description": "Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256), and `mldsa44` and `mldsa65` sign with the post-quantum ML-DSA scheme of US NIST FIPS 204. The set is expected to grow as algorithms are standardised, and growing it is a MINOR change under SPEC.md §5.2: `keyType` selects no schema branch, so adding a value relaxes a constraint rather than narrowing one, and the generated libraries mark this enumeration non-exhaustive so that a consumer absorbs a new value rather than failing to compile. Two ML-DSA parameter sets are carried because two specifications require different ones — W3C Quantum-Resistant Cryptosuites defines Data Integrity suites only for ML-DSA-44, while Trust Spanning Protocol Rev 3 §8.1 mandates ML-DSA-65 — so the parameter set is chosen by whatever consumes the key and the two are not redundant. A consumer that does not implement a value it receives MUST refuse the document rather than substitute one it does support.",
/// "type": "string",
/// "enum": [
/// "ed25519",
/// "x25519",
/// "p256",
/// "mldsa44",
/// "mldsa65"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum KeyType {
#[serde(rename = "ed25519")]
Ed25519,
#[serde(rename = "x25519")]
X25519,
#[serde(rename = "p256")]
P256,
#[serde(rename = "mldsa44")]
Mldsa44,
#[serde(rename = "mldsa65")]
Mldsa65,
}
impl ::std::fmt::Display for KeyType {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Ed25519 => f.write_str("ed25519"),
Self::X25519 => f.write_str("x25519"),
Self::P256 => f.write_str("p256"),
Self::Mldsa44 => f.write_str("mldsa44"),
Self::Mldsa65 => f.write_str("mldsa65"),
}
}
}
impl ::std::str::FromStr for KeyType {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"ed25519" => Ok(Self::Ed25519),
"x25519" => Ok(Self::X25519),
"p256" => Ok(Self::P256),
"mldsa44" => Ok(Self::Mldsa44),
"mldsa65" => Ok(Self::Mldsa65),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for KeyType {
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 KeyType {
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 KeyType {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Names one key whose private half is being asked for. 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/keys/export-secret/0.1",
/// "title": "Payload",
/// "description": "Names one key whose private half is being asked for. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "required": [
/// "keyId"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "keyId": {
/// "description": "The key to release. Custodian-scoped, as everywhere in `keys/*`. One key per request: there is deliberately no list form, so that each release is one decision the custodian can refuse, record and rate-limit on its own terms.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "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>,
///The key to release. Custodian-scoped, as everywhere in `keys/*`. One key per request: there is deliberately no list form, so that each release is one decision the custodian can refuse, record and rate-limit on its own terms.
#[serde(rename = "keyId")]
pub key_id: PayloadKeyId,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The key to release. Custodian-scoped, as everywhere in `keys/*`. One key per request: there is deliberately no list form, so that each release is one decision the custodian can refuse, record and rate-limit on its own terms.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The key to release. Custodian-scoped, as everywhere in `keys/*`. One key per request: there is deliberately no list form, so that each release is one decision the custodian can refuse, record and rate-limit on its own terms.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadKeyId(::std::string::String);
impl ::std::ops::Deref for PayloadKeyId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadKeyId> for ::std::string::String {
fn from(value: PayloadKeyId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadKeyId {
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 PayloadKeyId {
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 PayloadKeyId {
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 PayloadKeyId {
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 PayloadKeyId {
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 key material. Failures use trust-task-error, not this shape. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/export-secret/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The key material. Failures use trust-task-error, not this shape. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/export-secret/0.1#response.",
/// "type": "object",
/// "required": [
/// "keyId",
/// "keyType",
/// "privateKeyMultibase",
/// "publicKeyMultibase"
/// ],
/// "properties": {
/// "keyId": {
/// "description": "The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.",
/// "type": "string",
/// "minLength": 1
/// },
/// "keyType": {
/// "$ref": "#/definitions/KeyType"
/// },
/// "privateKeyMultibase": {
/// "description": "The private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.",
/// "type": "string",
/// "minLength": 1
/// },
/// "publicKeyMultibase": {
/// "description": "The public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.
#[serde(rename = "keyId")]
pub key_id: ResponseKeyId,
#[serde(rename = "keyType")]
pub key_type: KeyType,
///The private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.
#[serde(rename = "privateKeyMultibase")]
pub private_key_multibase: ResponsePrivateKeyMultibase,
///The public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.
#[serde(rename = "publicKeyMultibase")]
pub public_key_multibase: ResponsePublicKeyMultibase,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseKeyId(::std::string::String);
impl ::std::ops::Deref for ResponseKeyId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseKeyId> for ::std::string::String {
fn from(value: ResponseKeyId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseKeyId {
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 ResponseKeyId {
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 ResponseKeyId {
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 ResponseKeyId {
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 ResponseKeyId {
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 private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponsePrivateKeyMultibase(::std::string::String);
impl ::std::ops::Deref for ResponsePrivateKeyMultibase {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponsePrivateKeyMultibase> for ::std::string::String {
fn from(value: ResponsePrivateKeyMultibase) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponsePrivateKeyMultibase {
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 ResponsePrivateKeyMultibase {
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 ResponsePrivateKeyMultibase {
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 ResponsePrivateKeyMultibase {
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 ResponsePrivateKeyMultibase {
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 public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponsePublicKeyMultibase(::std::string::String);
impl ::std::ops::Deref for ResponsePublicKeyMultibase {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponsePublicKeyMultibase> for ::std::string::String {
fn from(value: ResponsePublicKeyMultibase) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponsePublicKeyMultibase {
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 ResponsePublicKeyMultibase {
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 ResponsePublicKeyMultibase {
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 ResponsePublicKeyMultibase {
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 ResponsePublicKeyMultibase {
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>,
key_id: ::std::result::Result<super::PayloadKeyId, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
key_id: Err("no value supplied for key_id".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 key_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadKeyId>,
T::Error: ::std::fmt::Display,
{
self.key_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for key_id: {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?,
key_id: value.key_id?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
key_id: Ok(value.key_id),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
key_id: ::std::result::Result<super::ResponseKeyId, ::std::string::String>,
key_type: ::std::result::Result<super::KeyType, ::std::string::String>,
private_key_multibase:
::std::result::Result<super::ResponsePrivateKeyMultibase, ::std::string::String>,
public_key_multibase:
::std::result::Result<super::ResponsePublicKeyMultibase, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
key_id: Err("no value supplied for key_id".to_string()),
key_type: Err("no value supplied for key_type".to_string()),
private_key_multibase: Err(
"no value supplied for private_key_multibase".to_string()
),
public_key_multibase: Err("no value supplied for public_key_multibase".to_string()),
}
}
}
impl Response {
pub fn key_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseKeyId>,
T::Error: ::std::fmt::Display,
{
self.key_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for key_id: {e}"));
self
}
pub fn key_type<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::KeyType>,
T::Error: ::std::fmt::Display,
{
self.key_type = value
.try_into()
.map_err(|e| format!("error converting supplied value for key_type: {e}"));
self
}
pub fn private_key_multibase<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponsePrivateKeyMultibase>,
T::Error: ::std::fmt::Display,
{
self.private_key_multibase = value.try_into().map_err(|e| {
format!("error converting supplied value for private_key_multibase: {e}")
});
self
}
pub fn public_key_multibase<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponsePublicKeyMultibase>,
T::Error: ::std::fmt::Display,
{
self.public_key_multibase = value.try_into().map_err(|e| {
format!("error converting supplied value for public_key_multibase: {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 {
key_id: value.key_id?,
key_type: value.key_type?,
private_key_multibase: value.private_key_multibase?,
public_key_multibase: value.public_key_multibase?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
key_id: Ok(value.key_id),
key_type: Ok(value.key_type),
private_key_multibase: Ok(value.private_key_multibase),
public_key_multibase: Ok(value.public_key_multibase),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/keys/export-secret/0.1";
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 \"KeyType\": {\n \"description\": \"Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256), and `mldsa44` and `mldsa65` sign with the post-quantum ML-DSA scheme of US NIST FIPS 204. The set is expected to grow as algorithms are standardised, and growing it is a MINOR change under SPEC.md §5.2: `keyType` selects no schema branch, so adding a value relaxes a constraint rather than narrowing one, and the generated libraries mark this enumeration non-exhaustive so that a consumer absorbs a new value rather than failing to compile. Two ML-DSA parameter sets are carried because two specifications require different ones — W3C Quantum-Resistant Cryptosuites defines Data Integrity suites only for ML-DSA-44, while Trust Spanning Protocol Rev 3 §8.1 mandates ML-DSA-65 — so the parameter set is chosen by whatever consumes the key and the two are not redundant. A consumer that does not implement a value it receives MUST refuse the document rather than substitute one it does support.\",\n \"enum\": [\n \"ed25519\",\n \"x25519\",\n \"p256\",\n \"mldsa44\",\n \"mldsa65\"\n ],\n \"title\": \"KeyType\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The key material. Failures use trust-task-error, not this shape. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/export-secret/0.1#response.\",\n \"properties\": {\n \"keyId\": {\n \"description\": \"The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"keyType\": {\n \"$ref\": \"#/$defs/KeyType\"\n },\n \"privateKeyMultibase\": {\n \"description\": \"The private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"publicKeyMultibase\": {\n \"description\": \"The public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyId\",\n \"keyType\",\n \"publicKeyMultibase\",\n \"privateKeyMultibase\"\n ],\n \"title\": \"Keys Export Secret — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/keys/export-secret/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Names one key whose private half is being asked for. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"keyId\": {\n \"description\": \"The key to release. Custodian-scoped, as everywhere in `keys/*`. One key per request: there is deliberately no list form, so that each release is one decision the custodian can refuse, record and rate-limit on its own terms.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyId\"\n ],\n \"title\": \"Keys Export Secret — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/keys/export-secret/0.1#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 \"KeyType\": {\n \"description\": \"Cryptographic algorithm the key material belongs to. `ed25519` signs (EdDSA), `x25519` performs key agreement and never signs, `p256` signs (ES256), and `mldsa44` and `mldsa65` sign with the post-quantum ML-DSA scheme of US NIST FIPS 204. The set is expected to grow as algorithms are standardised, and growing it is a MINOR change under SPEC.md §5.2: `keyType` selects no schema branch, so adding a value relaxes a constraint rather than narrowing one, and the generated libraries mark this enumeration non-exhaustive so that a consumer absorbs a new value rather than failing to compile. Two ML-DSA parameter sets are carried because two specifications require different ones — W3C Quantum-Resistant Cryptosuites defines Data Integrity suites only for ML-DSA-44, while Trust Spanning Protocol Rev 3 §8.1 mandates ML-DSA-65 — so the parameter set is chosen by whatever consumes the key and the two are not redundant. A consumer that does not implement a value it receives MUST refuse the document rather than substitute one it does support.\",\n \"enum\": [\n \"ed25519\",\n \"x25519\",\n \"p256\",\n \"mldsa44\",\n \"mldsa65\"\n ],\n \"title\": \"KeyType\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The key material. Failures use trust-task-error, not this shape. Carried in a Trust Task document whose type is https://trusttasks.org/spec/keys/export-secret/0.1#response.\",\n \"properties\": {\n \"keyId\": {\n \"description\": \"The key released, echoed so a consumer can confirm it received the one it named rather than matching on request order.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"keyType\": {\n \"$ref\": \"#/$defs/KeyType\"\n },\n \"privateKeyMultibase\": {\n \"description\": \"The private half, multibase-encoded (Base58BTC) over its multicodec-prefixed bytes. The prefix identifies the key material; a consumer decodes by prefix rather than trusting `keyType` alone.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"publicKeyMultibase\": {\n \"description\": \"The public half, multibase-encoded. Returned alongside the private half so a consumer can check the pair agrees before installing it, rather than deriving the public half and hoping.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"keyId\",\n \"keyType\",\n \"publicKeyMultibase\",\n \"privateKeyMultibase\"\n ],\n \"title\": \"Keys Export Secret — 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/keys/export-secret/0.1#request\",\n \"issuer\": \"did:example:operator\",\n \"recipient\": \"did:example:custodian\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"keyId\": \"did:example:issuer#key-0\"\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/keys/export-secret/0.1#response\",\n \"issuer\": \"did:example:custodian\",\n \"recipient\": \"did:example:operator\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"keyId\": \"did:example:issuer#key-0\",\n \"keyType\": \"ed25519\",\n \"publicKeyMultibase\": \"z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH\",\n \"privateKeyMultibase\": \"z3u2en7t5LR2WtQH5PfFqMqtVcSdd7ELrcFtnP63HKq4KLg\"\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)] = &[
(
"`keyId` is required — a request naming no key has nothing to release.",
"{}",
),
(
"`keyId` must not be empty. An empty string is what a caller lands on when its own key configuration is unset, and a custodian must refuse rather than resolve it to something.",
"{\n \"keyId\": \"\"\n}",
),
(
"No list form. One key per request is the point: a batch would make many releases one decision, where each ought to be its own.",
"{\n \"keyId\": [\n \"did:example:issuer#key-0\",\n \"did:example:issuer#key-1\"\n ]\n}",
),
(
"Nor a `keyIds` member arriving alongside, which is the shape a batch would most likely take if someone added one.",
"{\n \"keyId\": \"did:example:issuer#key-0\",\n \"keyIds\": [\n \"did:example:issuer#key-1\"\n ]\n}",
),
(
"No context selector. Exporting 'every key in a context' is a different request with a different risk, and it must not be reachable by widening this one.",
"{\n \"contextId\": \"rooms\",\n \"keyId\": \"did:example:issuer#key-0\"\n}",
),
(
"A request must not ask the custodian to override the key's own exportability. That decision belongs to `keys/set-exportability` and to an authority beyond the one that imposed it, not to a member on the request that reads it.",
"{\n \"exportable\": true,\n \"keyId\": \"did:example:issuer#key-0\"\n}",
),
(
"Nor to name where the key should be sent. The response goes to the producer that asked, established by the envelope; a destination member would be an open redirect for key material.",
"{\n \"deliverTo\": \"did:example:elsewhere\",\n \"keyId\": \"did:example:issuer#key-0\"\n}",
),
("`keyId` must be a string, not a number.", "{\n \"keyId\": 42\n}"),
(
"`ext` keys must be reverse-DNS namespaces (SPEC §4.5.1); a bare word is not one.",
"{\n \"ext\": {\n \"mine\": {\n \"a\": 1\n }\n },\n \"keyId\": \"did:example:issuer#key-0\"\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
);
}
}
}