pub fn encrypt(self, key: AesKey) -> Gbl<Encrypted<'a>, NotSigned<'a>> {
        debug_assert!(!self.is_encrypted());

        let nonce = crypto::random_nonce();
        // FIXME(perf): Optimize storage (`Vec<&[u8]>` with a shared backing store)
        let sec_count = self.enc.sections.len() + 1; // + 1 for AppData
        let mut sections: Vec<Vec<u8>> = Vec::with_capacity(sec_count);
        {
            let mut buf: Vec<u8> = Vec::new();
            Tag::AppInfo(self.enc.app_info)
                .write(&mut buf)
                .expect("failed to write to `Vec`");
            sections.push(buf);
        }
        for sec in &self.enc.sections {
            let mut buf: Vec<u8> = Vec::new();
            Tag::ProgramData(sec.clone())
                .write(&mut buf)
                .expect("failed to write to `Vec`");
            sections.push(buf);
        }

        let encrypted = crypto::crypt(key, nonce, &sections);
        info!("parsing {} sections", encrypted.len());

        let mut total_bytes: u32 = 0;
        let mut enc_sections = Vec::new();
        for sec in encrypted {
            total_bytes += sec.len() as u32;
            enc_sections.push(Blob(Cow::from(sec)));
        }

        Gbl {
            enc: Encrypted {
                enc_header: EncryptionHeader {
                    total_bytes,
                    nonce: Blob(nonce),
                },
                enc_sections,
            },
            sig: self.sig,
        }
    }
/// Encrypts the content of this GBL file using an AES-128 key.
///
/// This will generate a random 12-Byte nonce using the operating
/// system's random number generator. The nonce will be used for encryption
/// and decryption and is stored inside the encryption header inside the
/// encrypted GBL.
///
/// Note that the validity of the key cannot be checked: Passing an invalid
/// key will result in encryption succeeding, but resulting in garbage data,
/// which will then fail to parse properly.
///
/// # Method availability
///
/// This method is only available when `self` is `NotEncrypted` and
/// `NotSigned`. It turns a `NotEncrypted` and `NotSigned` GBL into an
/// `Encrypted` and `NotSigned` GBL.
Encrypts the content of this GBL file using an AES-128 key.
This will generate a random 12-Byte nonce using the operating
system's random number generator. The nonce will be used for encryption
and decryption and is stored inside the encryption header inside the
encrypted GBL.

Note that the validity of the key cannot be checked: Passing an invalid
key will result in encryption succeeding, but resulting in garbage data,
which will then fail to parse properly.
Encrypts the content of this GBL file using an AES - 128 key . This will generate a random 12 - Byte nonce using the operating system ' s random number generator . The nonce will be used for encryption and decryption and is stored inside the encryption header inside the encrypted GBL . Note that the validity of the key cannot be checked : Passing an invalid key will result in encryption succeeding but resulting in garbage data which will then fail to parse properly .
pub fn encrypt(self, key: AesKey) -> Gbl<Encrypted<'a>, NotSigned<'a>> {
        debug_assert!(!self.is_encrypted());
        let nonce = crypto::random_nonce();
        // FIXME(perf): Optimize storage (`Vec<&[u8]>` with a shared backing store)
        let sec_count = self.enc.sections.len() + 1; // + 1 for AppData
        let mut sections: Vec<Vec<u8>> = Vec::with_capacity(sec_count);
        {
            let mut buf: Vec<u8> = Vec::new();
            Tag::AppInfo(self.enc.app_info)
                .write(&mut buf)
                .expect("failed to write to `Vec`");
            sections.push(buf);
        }
        for sec in &self.enc.sections {
            let mut buf: Vec<u8> = Vec::new();
            Tag::ProgramData(sec.clone())
                .write(&mut buf)
                .expect("failed to write to `Vec`");
            sections.push(buf);
        }
        let encrypted = crypto::crypt(key, nonce, &sections);
        info!("parsing {} sections", encrypted.len());
        let mut total_bytes: u32 = 0;
        let mut enc_sections = Vec::new();
        for sec in encrypted {
            total_bytes += sec.len() as u32;
            enc_sections.push(Blob(Cow::from(sec)));
        }
        Gbl {
            enc: Encrypted {
                enc_header: EncryptionHeader {
                    total_bytes,
                    nonce: Blob(nonce),
                },
                enc_sections,
            },
            sig: self.sig,
        }
    }
pub fn encrypt ( self , key : AesKey ) -> Gbl < Encrypted < ' a > , NotSigned < ' a > > { debug_assert ! ( self is_encrypted ( ) ) ; let nonce = crypto :: random_nonce ( ) ; // FIXME(perf): Optimize storage (`Vec<&[u8]>` with a shared backing store) let sec_count = self . enc . sections . len ( ) + 1 ; // + 1 for AppData let mut sections : Vec < Vec < u8 > > = Vec :: with_capacity ( sec_count ) ; { let mut buf : Vec < u8 > = Vec :: new ( ) ; Tag :: AppInfo ( self . enc . app_info ) . write ( & mut buf ) . expect ( " " ) ; sections . push ( buf ) ; } for sec in & self . enc . sections { let mut buf : Vec < u8 > = Vec :: new ( ) ; Tag :: ProgramData ( sec . clone ( ) ) . write ( & mut buf ) . expect ( " " ) ; sections . push ( buf ) ; } let encrypted = crypto :: crypt ( key , nonce , & sections ) ; info ! ( " " encrypted len ( ) ) ; let mut total_bytes : u32 = 0 ; let mut enc_sections = Vec :: new ( ) ; for sec in encrypted { total_bytes += sec . len ( ) as u32 ; enc_sections . push ( Blob ( Cow :: from ( sec ) ) ) ; } Gbl { enc : Encrypted { enc_header : EncryptionHeader { total_bytes , nonce : Blob ( nonce ) , } , enc_sections , } , sig : self . sig , } }
Encrypts the content of this GBL file using an AES-128 key.
Encrypts the content of this GBL file using an AES - 128 key .
self
key
AesKey
method availability
This method is only available when `self` is `NotEncrypted` and
`NotSigned`. It turns a `NotEncrypted` and `NotSigned` GBL into an
`Encrypted` and `NotSigned` GBL.
This method is only available when ` self ` is ` NotEncrypted ` and ` NotSigned ` . It turns a ` NotEncrypted ` and ` NotSigned ` GBL into an ` Encrypted ` and ` NotSigned ` GBL .