A symmetric AES-128 encryption/decryption key.
Can be obtained from a variety of formats and is used by Gbl::encrypt
and Gbl::decrypt
.
Creates an AES key from 16 raw bytes.
let key = AesKey::from_raw([
0xE7, 0xE5, 0x56, 0xB6, 0x35, 0xA3, 0x52, 0x06,
0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2,
]);
Creates an AES key from a byte slice containing 16 bytes.
If the slice does not contain exactly 16 bytes, returns None
.
assert!(AesKey::from_slice(&[
0xE7, 0xE5, 0x56, 0xB6, 0x35, 0xA3, 0x52, 0x06,
0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2,
]).is_some());
Note that it is preferrable to use AesKey::from_raw
when you already
have a fixed-size array of 16 Bytes.
When the slice does not contain 16 Bytes, this returns None
:
assert!(AesKey::from_slice(&[
0xE7, 0xE5, 0x56, 0xB6, 0x35, 0xA3, 0x52, 0x06,
0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2,
0xFF,
]).is_none());
Parses an AES key from a hexadecimal string.
let key = AesKey::from_hex_str("E7E556B635A3520659A2E161CBDF4BC2")?;
Parses an AES key from a bootloader token file.
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
.
Load a key from an example token file:
let contents = r"
# Key randomly generated
TOKEN_MFG_SECURE_BOOTLOADER_KEY: E7E556B635A3520659A2E161CBDF4BC2
";
let key = AesKey::from_token_file(contents)?;
Returns a reference to the raw 16-Byte AES-128 key.
Consumes self
and returns the raw bytes making up the key.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Writes the hex string representing self
into w
. Lower case letters are used (e.g. f9b4ca
). Read more
Writes the hex string representing self
into w
. Upper case letters are used (e.g. F9B4CA
). Read more