4 releases

✓ Uses Rust 2018 edition

0.1.3 Oct 20, 2019
0.1.2 Aug 26, 2019
0.1.1 Aug 25, 2019
0.1.0 Aug 25, 2019

#4 in #decryption

Download history 6/week @ 2019-10-04 2/week @ 2019-10-11 28/week @ 2019-10-18 6/week @ 2019-10-25 11/week @ 2019-11-01 3/week @ 2019-11-08 12/week @ 2019-11-15 12/week @ 2019-11-22 9/week @ 2019-11-29 42/week @ 2019-12-06 20/week @ 2019-12-13 4/week @ 2019-12-27 2/week @ 2020-01-03 37/week @ 2020-01-10

56 downloads per month

MIT license

12KB
304 lines

diesel_mate

Some default methods for diesel related structs

  • Encryption and Decryption in action
  • To make any struct encryptable, It must have an id field of type int(u64) necessary.
  • To make any struct encryptable or decryptable, It must define sub_key to encrypt and decrypt key individually.
  • Before using encryptable or decryptable, It must have initialize secret_key initially.
  • Secret key length depends upon how much good encryption that you want (64 byte recommended).
  • It is same as django encrypted_id.
  • We can reuse the secret key as we are using in django to en-decrypt the id.

use encrypted_id::{prelude::*};
#[derive(Debug, Default, Encrypted, Decrypted)]
#[encdec_opts(opts(sub_key = "enky_demo_sub_key"))]
pub struct EncyDemo {
    pub id: u64,
    pub name: String,
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn enc_test() {
        // We have to set secret key only single time based on that it will encrypt and decrypt key. 
        init_encrypt_conf("df(vh!3*8e21@qca#3)w#7ta*z#!bhsde43&#iez3sf5m1#h6l");
        let e = EncyDemo{id: 5, name: "foo".to_string()};
        let ekey = e.ekey().unwrap();
        let dkey = e.dkey(&ekey).unwrap();
        assert_eq!("E86VGQhfxb_9rxSfjnBqKg", ekey);
        assert_eq!(5, dkey);
    }
}

Using with struct

use encrypted_id::{prelude::*};
#[derive(Debug, Default, Encrypted, Decrypted)]
#[encdec_opts(opts(sub_key = "enky_demo_sub_key"))]
pub struct EncyDemo {
    pub id: u64,
    pub name: String,
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn enc_test() {
        // We have to set secret key only single time based on that it will encrypt and decrypt key.           
        init_encrypt_conf("df(vh!3*8e21@qca#3)w#7ta*z#!bhsde43&#iez3sf5m1#h6l");
        let e = EncyDemo{id: 5, name: "foo".to_string()};
        let ekey = e.ekey().unwrap();
        let dkey = e.dkey(&ekey).unwrap();
        assert_eq!("E86VGQhfxb_9rxSfjnBqKg", ekey);
        assert_eq!(5, dkey);
    }
}

Dependencies

~3.5MB
~49K SLoC