Giter VIP home page Giter VIP logo

Comments (3)

tony-iqlusion avatar tony-iqlusion commented on June 1, 2024

How about subtle::ConstantTimeEq as a safe alternative?

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.

from crates.

marccarre avatar marccarre commented on June 1, 2024

@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? 🙇🏻‍♂️

from crates.

Bauxitedev avatar Bauxitedev commented on June 1, 2024

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)
pub struct SecretWrapper<T>(pub Secret<T>)
where
    T: Zeroize;

impl<T> SecretWrapper<T>
where
    T: Zeroize,
{
    pub fn new(value: T) -> Self {
        Self(Secret::new(value))
    }
}

impl<T> Eq for SecretWrapper<T> where T: Zeroize + Eq {}
impl<T> PartialEq for SecretWrapper<T>
where
    T: Zeroize + PartialEq,
{
    fn eq(&self, other: &Self) -> bool {
        self.expose_secret() == other.expose_secret()
    }
}

You'll need to impl any other traits you may need (Clone/Debug/etc)

from crates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.