fn encrypt_cookie(&self, cookie: &mut Cookie) {
        let mut data;
        let output_len = {
            // Create the `SealingKey` structure.
            let key = SealingKey::new(ALGO, &self.key).expect("sealing key creation");

            // Create a vec to hold the [nonce | cookie value | overhead].
            let overhead = ALGO.tag_len();
            let cookie_val = cookie.value().as_bytes();
            data = vec![0; NONCE_LEN + cookie_val.len() + overhead];

            // Randomly generate the nonce, then copy the cookie value as input.
            let (nonce, in_out) = data.split_at_mut(NONCE_LEN);
            SystemRandom::new().fill(nonce).expect("couldn't random fill nonce");
            in_out[..cookie_val.len()].copy_from_slice(cookie_val);
            let nonce = Nonce::try_assume_unique_for_key(nonce)
                .expect("invalid length of `nonce`");

            // Use cookie's name as associated data to prevent value swapping.
            let ad = Aad::from(cookie.name().as_bytes());

            // Perform the actual sealing operation and get the output length.
            seal_in_place(&key, nonce, ad, in_out, overhead).expect("in-place seal")
        };

        // Base64 encode the nonce and encrypted value.
        let sealed_value = base64::encode(&data[..(NONCE_LEN + output_len)]);
        cookie.set_value(sealed_value);
    }
/// Encrypts the cookie's value with
/// authenticated encryption assuring confidentiality, integrity, and authenticity.
Encrypts the cookie's value with
authenticated encryption assuring confidentiality, integrity, and authenticity.
Encrypts the cookie ' s value with authenticated encryption assuring confidentiality integrity and authenticity .
fn encrypt_cookie(&self, cookie: &mut Cookie) {
        let mut data;
        let output_len = {
            // Create the `SealingKey` structure.
            let key = SealingKey::new(ALGO, &self.key).expect("sealing key creation");
            // Create a vec to hold the [nonce | cookie value | overhead].
            let overhead = ALGO.tag_len();
            let cookie_val = cookie.value().as_bytes();
            data = vec![0; NONCE_LEN + cookie_val.len() + overhead];
            // Randomly generate the nonce, then copy the cookie value as input.
            let (nonce, in_out) = data.split_at_mut(NONCE_LEN);
            SystemRandom::new().fill(nonce).expect("couldn't random fill nonce");
            in_out[..cookie_val.len()].copy_from_slice(cookie_val);
            let nonce = Nonce::try_assume_unique_for_key(nonce)
                .expect("invalid length of `nonce`");
            // Use cookie's name as associated data to prevent value swapping.
            let ad = Aad::from(cookie.name().as_bytes());
            // Perform the actual sealing operation and get the output length.
            seal_in_place(&key, nonce, ad, in_out, overhead).expect("in-place seal")
        };
        // Base64 encode the nonce and encrypted value.
        let sealed_value = base64::encode(&data[..(NONCE_LEN + output_len)]);
        cookie.set_value(sealed_value);
    }
fn encrypt_cookie ( & self , cookie : & mut Cookie ) { let mut data ; let output_len = { // Create the `SealingKey` structure. let key = SealingKey :: new ( ALGO , & self . key ) . expect ( " " ) ; // Create a vec to hold the [nonce | cookie value | overhead]. let overhead = ALGO . tag_len ( ) ; let cookie_val = cookie . value ( ) . as_bytes ( ) ; data = vec ! [ 0 NONCE_LEN cookie_val len ( ) overhead ] ; // Randomly generate the nonce, then copy the cookie value as input. let ( nonce , in_out ) = data . split_at_mut ( NONCE_LEN ) ; SystemRandom :: new ( ) . fill ( nonce ) . expect ( " " ) ; in_out [ .. cookie_val . len ( ) ] . copy_from_slice ( cookie_val ) ; let nonce = Nonce :: try_assume_unique_for_key ( nonce ) . expect ( " " ) ; // Use cookie's name as associated data to prevent value swapping. let ad = Aad :: from ( cookie . name ( ) . as_bytes ( ) ) ; // Perform the actual sealing operation and get the output length. seal_in_place ( & key , nonce , ad , in_out , overhead ) . expect ( " " ) } ; // Base64 encode the nonce and encrypted value. let sealed_value = base64 :: encode ( & data [ .. ( NONCE_LEN + output_len ) ] ) ; cookie . set_value ( sealed_value ) ; }
Encrypts the cookie's value with
authenticated encryption assuring confidentiality, integrity, and authenticity.
Encrypts the cookie ' s value with authenticated encryption assuring confidentiality integrity and authenticity .
&self
cookie
&mut Cookie
&self
cookie
&mut Cookie