fn encrypt_cookie(&self, cookie: &mut Cookie) {
        // Create the `LessSafeKey` structure.
        let unbound = UnboundKey::new(&ALGO, &self.key).expect("matching key length");
        let key = LessSafeKey::new(unbound);

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

        // Split data into three: nonce, input/output, tag. Copy input.
        let (nonce, in_out) = data.split_at_mut(NONCE_LEN);
        let (in_out, tag) = in_out.split_at_mut(cookie_val.len());
        in_out.copy_from_slice(cookie_val);

        // Randomly generate the nonce into the nonce piece.
        SystemRandom::new().fill(nonce).expect("couldn't random fill nonce");
        let nonce = Nonce::try_assume_unique_for_key(nonce)
            .expect("invalid `nonce` length");

        // Perform the actual sealing operation, using the cookie's name as
        // associated data to prevent value swapping.
        let ad = Aad::from(cookie.name().as_bytes());
        let ad_tag = key.seal_in_place_separate_tag(nonce, ad, in_out)
            .expect("in-place seal");

        // Copy the tag into the tag piece.
        tag.copy_from_slice(ad_tag.as_ref());

        // Base64 encode [none | encrypted value | tag].
        cookie.set_value(base64::encode(&data));
    }
/// 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) {
        // Create the `LessSafeKey` structure.
        let unbound = UnboundKey::new(&ALGO, &self.key).expect("matching key length");
        let key = LessSafeKey::new(unbound);
        // Create a vec to hold the [nonce | cookie value | tag].
        let cookie_val = cookie.value().as_bytes();
        let mut data = vec![0; NONCE_LEN + cookie_val.len() + ALGO.tag_len()];
        // Split data into three: nonce, input/output, tag. Copy input.
        let (nonce, in_out) = data.split_at_mut(NONCE_LEN);
        let (in_out, tag) = in_out.split_at_mut(cookie_val.len());
        in_out.copy_from_slice(cookie_val);
        // Randomly generate the nonce into the nonce piece.
        SystemRandom::new().fill(nonce).expect("couldn't random fill nonce");
        let nonce = Nonce::try_assume_unique_for_key(nonce)
            .expect("invalid `nonce` length");
        // Perform the actual sealing operation, using the cookie's name as
        // associated data to prevent value swapping.
        let ad = Aad::from(cookie.name().as_bytes());
        let ad_tag = key.seal_in_place_separate_tag(nonce, ad, in_out)
            .expect("in-place seal");
        // Copy the tag into the tag piece.
        tag.copy_from_slice(ad_tag.as_ref());
        // Base64 encode [none | encrypted value | tag].
        cookie.set_value(base64::encode(&data));
    }
fn encrypt_cookie ( & self , cookie : & mut Cookie ) { // Create the `LessSafeKey` structure. let unbound = UnboundKey :: new ( & ALGO , & self . key ) . expect ( " " ) ; let key = LessSafeKey :: new ( unbound ) ; // Create a vec to hold the [nonce | cookie value | tag]. let cookie_val = cookie . value ( ) . as_bytes ( ) ; let mut data = vec ! [ 0 NONCE_LEN cookie_val len ( ) ALGO tag_len ( ) ] ; // Split data into three: nonce, input/output, tag. Copy input. let ( nonce , in_out ) = data . split_at_mut ( NONCE_LEN ) ; let ( in_out , tag ) = in_out . split_at_mut ( cookie_val . len ( ) ) ; in_out . copy_from_slice ( cookie_val ) ; // Randomly generate the nonce into the nonce piece. SystemRandom :: new ( ) . fill ( nonce ) . expect ( " " ) ; let nonce = Nonce :: try_assume_unique_for_key ( nonce ) . expect ( " " ) ; // Perform the actual sealing operation, using the cookie's name as // associated data to prevent value swapping. let ad = Aad :: from ( cookie . name ( ) . as_bytes ( ) ) ; let ad_tag = key . seal_in_place_separate_tag ( nonce , ad , in_out ) . expect ( " " ) ; // Copy the tag into the tag piece. tag . copy_from_slice ( ad_tag . as_ref ( ) ) ; // Base64 encode [none | encrypted value | tag]. cookie . set_value ( base64 :: encode ( & data ) ) ; }
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