You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's slightly more cumbersome in that you have to import a trait and use Into to coerce subtle::Choice into a boolean, but it would avoid exposing unsafe APIs just for testing.
@steven-joruk, which workaround did you end up using? Mind sharing an example? 🙇🏻♂️ @tony-iqlusion, could you share an example of what you'd have in mind for the case of implementing PartialEq/Eq using subtle::Choice? 🙇🏻♂️
Unfortunately, due to the orphan trait rule, I couldn't find a nice workaround for this, so I just made my own wrapper type and used that instead.
use secrecy::{ExposeSecret,Secret,Zeroize,};/// Secret<T> wrapper that impls PartialEq and Eq (so you can use it in BTreeSets and such)pubstructSecretWrapper<T>(pubSecret<T>)whereT:Zeroize;impl<T>SecretWrapper<T>whereT:Zeroize,{pubfnnew(value:T) -> Self{Self(Secret::new(value))}}impl<T>EqforSecretWrapper<T>whereT:Zeroize + Eq{}impl<T>PartialEqforSecretWrapper<T>whereT:Zeroize + PartialEq,{fneq(&self,other:&Self) -> bool{self.expose_secret() == other.expose_secret()}}
You'll need to impl any other traits you may need (Clone/Debug/etc)
I would find it useful when unit testing equivalence of values which contain secrets.
I can work around it by manually implementing the traits for my structs which contain secrets, but maybe others would find this useful as well.
Perhaps it should be an opt-in feature flag so that it could support more test project configurations?
The text was updated successfully, but these errors were encountered: