pub fn from_token_file<S: AsRef<str>>(contents: S) -> Result<Self, Error> {
        const BL_KEY: &str = "TOKEN_MFG_SECURE_BOOTLOADER_KEY";

        let mut parsed_aes_key = None;
        for line in contents.as_ref().lines() {
            let line = line.trim();
            if line.starts_with('#') || line.is_empty() {
                continue;
            }

            let mut split = line.splitn(2, ':');
            let key = split.next().unwrap();
            let value = split
                .next()
                .ok_or_else(|| Error::parse_err(format!("malformed line: {}", line)))?;
            let key = key.trim();
            let value = value.trim();

            if key != BL_KEY {
                return Err(Error::parse_err(format!(
                    "invalid key in token file: got '{}', expected '{}'",
                    key, BL_KEY
                )));
            }

            // parse the associated 128-bit AES key (in hexadecimal notation)
            let aes_key = AesKey::from_hex_str(value)?;

            if parsed_aes_key.is_some() {
                return Err(Error::parse_err("duplicate AES key entry"));
            }

            parsed_aes_key = Some(aes_key);
        }

        parsed_aes_key.ok_or_else(|| Error::parse_err("no AES key found in token file"))
    }
/// Parses an AES key from a bootloader token file.
///
/// # Parameters
///
/// * `contents`: Contents of the bootloader token file generated by (eg.)
///   `commander gbl keygen --type aes-ccm`. Must contain the key
///   `TOKEN_MFG_SECURE_BOOTLOADER_KEY`.
///
/// # Examples
///
/// Load a key from an example token file:
///
/// ```
/// # use gbl::*;
/// # fn run() -> Result<(), Error> {
/// let contents = r"
/// 	## Key randomly generated
/// 	TOKEN_MFG_SECURE_BOOTLOADER_KEY: E7E556B635A3520659A2E161CBDF4BC2
/// ";
///
/// let key = AesKey::from_token_file(contents)?;
/// # Ok(()) }    fn main() { run().unwrap() }
/// ```
Parses an AES key from a bootloader token file.
Parses an AES key from a bootloader token file .
pub fn from_token_file<S: AsRef<str>>(contents: S) -> Result<Self, Error> {
        const BL_KEY: &str = "TOKEN_MFG_SECURE_BOOTLOADER_KEY";
        let mut parsed_aes_key = None;
        for line in contents.as_ref().lines() {
            let line = line.trim();
            if line.starts_with('#') || line.is_empty() {
                continue;
            }
            let mut split = line.splitn(2, ':');
            let key = split.next().unwrap();
            let value = split
                .next()
                .ok_or_else(|| Error::parse_err(format!("malformed line: {}", line)))?;
            let key = key.trim();
            let value = value.trim();
            if key != BL_KEY {
                return Err(Error::parse_err(format!(
                    "invalid key in token file: got '{}', expected '{}'",
                    key, BL_KEY
                )));
            }
            // parse the associated 128-bit AES key (in hexadecimal notation)
            let aes_key = AesKey::from_hex_str(value)?;
            if parsed_aes_key.is_some() {
                return Err(Error::parse_err("duplicate AES key entry"));
            }
            parsed_aes_key = Some(aes_key);
        }
        parsed_aes_key.ok_or_else(|| Error::parse_err("no AES key found in token file"))
    }
pub fn from_token_file < S : AsRef < str > > ( contents : S ) -> Result < Self , Error > { const BL_KEY : & str = " " ; let mut parsed_aes_key = None ; for line in contents . as_ref ( ) . lines ( ) { let line = line . trim ( ) ; if line . starts_with ( '#' ) || line . is_empty ( ) { continue ; } let mut split = line . splitn ( 2 , ':' ) ; let key = split . next ( ) . unwrap ( ) ; let value = split . next ( ) . ok_or_else ( | | Error :: parse_err ( format ! ( " " line ) ) ) ? ; let key = key . trim ( ) ; let value = value . trim ( ) ; if key != BL_KEY { return Err ( Error :: parse_err ( format ! ( " " key BL_KEY ) ) ) ; } // parse the associated 128-bit AES key (in hexadecimal notation) let aes_key = AesKey :: from_hex_str ( value ) ? ; if parsed_aes_key . is_some ( ) { return Err ( Error :: parse_err ( " " ) ) ; } parsed_aes_key = Some ( aes_key ) ; } parsed_aes_key . ok_or_else ( | | Error :: parse_err ( " " ) ) }
Parses an AES key from a bootloader token file.
Parses an AES key from a bootloader token file .
contents
S
examples
Load a key from an example token file.


Load a key from an example token file .
use gbl::*;
None
fn run() -> result<(), error> {


let key = AesKey::from_token_file(contents)?.
let key = AesKey :: from_token_file ( contents ) ? .
ok(()) }    fn main() { run().unwrap() }
None