pub struct Secret(/* private fields */);Expand description
An access or refresh token.
Its Debug and Display print
<redacted>, it has no Serialize, and its own buffer is zeroed when it
is dropped. Secret::expose is the only way to read it.
Zeroing is best effort, not a guarantee that no copy is left in memory.
Each clone is a separate buffer, zeroed when that clone drops. The
client zeroes the response bodies it reads, but not the copies made
outside it: the request body handed to reqwest (and its TLS and HTTP/2
buffers), reqwest’s received chunks, the String a caller passes to
Secret::new, and whatever a caller does with Secret::expose.
Equality (==) is a plain string comparison, not constant-time: fine
for the compare-and-swap a refresh needs, not for checking a token an
untrusted party sent.
use ccwire_oauth::Secret;
let token = Secret::new("not-a-real-token");
assert_eq!(format!("{token} {token:?}"), "<redacted> Secret(<redacted>)");
assert_eq!(token.expose(), "not-a-real-token");Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Secret
impl<'de> Deserialize<'de> for Secret
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Secret
impl StructuralPartialEq for Secret
Auto Trait Implementations§
impl Forget for Secret
impl Freeze for Secret
impl RefUnwindSafe for Secret
impl Send for Secret
impl Sync for Secret
impl Unpin for Secret
impl UnsafeUnpin for Secret
impl UnwindSafe for Secret
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.