secrecy: Add CloneableSecret marker trait
Adds a marker trait for secrets which are allowed to be cloned.
Ideally secrets aren't cloned all over the place, so in lieu of a
blanket impl, this marker trait allows certain secrets to be cloned.
@@ -54,6 +54,17 @@ where
}
}
+impl<S> Clone for Secret<S>
+where
+ S: CloneableSecret,
+{
+ fn clone(&self) -> Self {
+ Secret {
+ inner_secret: self.inner_secret.clone(),
+ }
+ }
+}
+
impl<S> Debug for Secret<S>
where
S: Zeroize + DebugSecret,
@@ -86,6 +97,9 @@ where
}
}
+/// Marker trait for secrets which are allowed to be cloned
+pub trait CloneableSecret: Clone + Zeroize {}
+
/// Expose a reference to an inner secret
pub trait ExposeSecret<S> {
/// Expose secret
