sensitive_trait

Crates.iosensitive_trait
lib.rssensitive_trait
version0.1.2
sourcesrc
created_at2023-07-17 09:52:17.613936
updated_at2023-07-17 12:37:41.000003
descriptionA marker trait for sensitive information.
homepage
repository
max_upload_size
id918360
size4,112
mizu (WhyNotDogie)

documentation

README

NonSensitive

A marker trait for sensitive information.

Examples

This will compile error:

struct Password(SensitiveData<String>);
impl AsRef<str> for Password {
    fn as_ref(&self) -> &str {
        self.0.as_str()
    }
}

fn post_tweet<T: NonSensitive + AsRef<str>, P: AsRef<str>>(msg: T, pwd: P) {
    twitter::post(msg.as_ref(), pwd);
}

fn main() {
    let pwd = Password(SensitiveData::new("wutdedogdoin1!".to_string()));
    let msg = "Hello, world! *Beep boops aggressively*";

    post_tweet(pwd, msg); // Uh oh, we flipped the message and the password!
}

But NonSensitive comes to the rescue!
Instead of posting our twitter password, we get an error.
Error message:

the trait bound `sensitive_trait::SensitiveData<String>: sensitive_trait::NonSensitive` is not satisfied in `Password`
Commit count: 0

cargo fmt