async_graphql/types/external/
secrecy.rs

1use std::borrow::Cow;
2
3use secrecy::{zeroize::Zeroize, ExposeSecret, SecretBox, SecretString};
4
5use crate::{registry, InputType, InputValueError, InputValueResult, Value};
6
7impl<T: InputType + Zeroize> InputType for SecretBox<T> {
8    type RawValueType = T::RawValueType;
9
10    fn type_name() -> Cow<'static, str> {
11        T::type_name()
12    }
13
14    fn qualified_type_name() -> String {
15        T::qualified_type_name()
16    }
17
18    fn create_type_info(registry: &mut registry::Registry) -> String {
19        T::create_type_info(registry)
20    }
21
22    fn parse(value: Option<Value>) -> InputValueResult<Self> {
23        T::parse(value)
24            .map(|value| SecretBox::new(Box::new(value)))
25            .map_err(InputValueError::propagate)
26    }
27
28    fn to_value(&self) -> Value {
29        Value::Null
30    }
31
32    fn as_raw_value(&self) -> Option<&Self::RawValueType> {
33        self.expose_secret().as_raw_value()
34    }
35}
36
37impl InputType for SecretString {
38    type RawValueType = str;
39
40    fn type_name() -> Cow<'static, str> {
41        String::type_name()
42    }
43
44    fn qualified_type_name() -> String {
45        String::qualified_type_name()
46    }
47
48    fn create_type_info(registry: &mut registry::Registry) -> String {
49        String::create_type_info(registry)
50    }
51
52    fn parse(value: Option<Value>) -> InputValueResult<Self> {
53        String::parse(value)
54            .map(SecretString::from)
55            .map_err(InputValueError::propagate)
56    }
57
58    fn to_value(&self) -> Value {
59        Value::Null
60    }
61
62    fn as_raw_value(&self) -> Option<&Self::RawValueType> {
63        Some(self.expose_secret())
64    }
65}