wire/command/no_secret.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The carrier a socket cannot fill.
7//!
8//! `Command` is generic over what carries a secret. Fixing that carrier
9//! to a type with no values is what makes `WireCommand::PutSecret`
10//! unrepresentable rather than merely refused, and the three impls here
11//! say the same thing to the three readers that ask: the compiler, a
12//! stream of bytes, and a schema a client is generated from.
13
14use serde::{Deserialize, Serialize};
15
16/// Uninhabited on purpose. A value of this type cannot be produced, so
17/// `Command<NoSecret>` has no reachable `PutSecret` variant. This is the
18/// compile-time half of "a remote connection cannot spell that frame";
19/// `Deserialize` supplies the runtime half for bytes that try anyway.
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum NoSecret {}
22
23impl Serialize for NoSecret {
24 fn serialize<S: serde::Serializer>(&self, _serializer: S) -> Result<S::Ok, S::Error> {
25 match *self {}
26 }
27}
28
29impl<'de> Deserialize<'de> for NoSecret {
30 fn deserialize<D: serde::Deserializer<'de>>(_deserializer: D) -> Result<Self, D::Error> {
31 Err(serde::de::Error::custom(
32 "a credential cannot be enrolled over a connection; enrol it on the host",
33 ))
34 }
35}
36
37/// The schema half of the same statement: `false` is the schema no value
38/// satisfies, so a client generated from it types the field as `never`.
39#[cfg(feature = "schema")]
40impl schemars::JsonSchema for NoSecret {
41 fn schema_name() -> std::borrow::Cow<'static, str> {
42 std::borrow::Cow::Borrowed("NoSecret")
43 }
44
45 fn json_schema(_generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
46 schemars::Schema::from(false)
47 }
48}