Skip to main content

ExposeSecret

Struct ExposeSecret 

Source
pub struct ExposeSecret;
Expand description

English:
Explicitly serializes a Secret<T> as its unredacted inner value with serde_with.

Available with the serde_with feature (which enables serde). Implements only serde_with::SerializeAs; use Secret’s ordinary Deserialize for input. Compose this adapter with containers supported by serde_with, such as Option< Vec<ExposeSecret> >. Custom containers may need a user-defined adapter or a storage DTO. Output is plaintext, not encrypted, and is not zeroized when the source secret is dropped. Inner serialization errors are propagated unchanged and may also contain secrets.

日本語:
serde_with を使い、Secret<T> の内部値を秘匿せず明示的にシリアライズします。

serde_with feature(serde も有効化)が必要です。serde_with::SerializeAs のみを実装し、 入力には Secret 自体の通常の Deserialize を使います。Option< Vec<ExposeSecret> > など、 serde_with が対応するコンテナと合成できます。独自コンテナには利用者定義のアダプターや 保存用 DTO が必要な場合があります。出力は暗号化されない平文であり、元の秘密値を破棄しても ゼロ化されません。内部型のシリアライズエラーはそのまま伝播し、秘密値を含む可能性もあります。

§Example / 使用例

use ddd_toolkit_core::{ExposeSecret, Secret};
use serde_with::SerializeAs;

let token = Secret::new(String::from("storage-token"));
let mut bytes = Vec::new();
let mut serializer = serde_json::Serializer::new(&mut bytes);
ExposeSecret::serialize_as(&token, &mut serializer).unwrap();
assert_eq!(bytes, br#""storage-token""#);

Trait Implementations§

Source§

impl<T: Zeroize + Serialize> SerializeAs<Secret<T>> for ExposeSecret

Source§

fn serialize_as<S: Serializer>( source: &Secret<T>, serializer: S, ) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.