[−][src]Struct gbl::AesKey
A symmetric AES-128 encryption/decryption key.
Can be obtained from a variety of formats and is used by Gbl::encrypt
and Gbl::decrypt
.
Methods
impl AesKey
[src]
pub fn from_raw(raw: [u8; 16]) -> Self
[src]
Creates an AES key from 16 raw bytes.
Examples
let key = AesKey::from_raw([ 0xE7, 0xE5, 0x56, 0xB6, 0x35, 0xA3, 0x52, 0x06, // 8 0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2, // 16 ]);
pub fn from_slice(slice: &[u8]) -> Option<Self>
[src]
Creates an AES key from a byte slice containing 16 bytes.
If the slice does not contain exactly 16 bytes, returns None
.
Examples
assert!(AesKey::from_slice(&[ 0xE7, 0xE5, 0x56, 0xB6, 0x35, 0xA3, 0x52, 0x06, // 8 0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2, // 16 ]).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, // 8 0x59, 0xA2, 0xE1, 0x61, 0xCB, 0xDF, 0x4B, 0xC2, // 16 0xFF, // 17 ]).is_none());
pub fn from_hex_str<S: AsRef<str>>(s: S) -> Result<Self, Error>
[src]
Parses an AES key from a hexadecimal string.
Examples
let key = AesKey::from_hex_str("E7E556B635A3520659A2E161CBDF4BC2")?;
pub fn from_token_file<S: AsRef<str>>(contents: S) -> Result<Self, Error>
[src]
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 keyTOKEN_MFG_SECURE_BOOTLOADER_KEY
.
Examples
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)?;
pub fn as_raw(&self) -> &[u8; 16]
[src]
Returns a reference to the raw 16-Byte AES-128 key.
pub fn into_raw(self) -> [u8; 16]
[src]
Consumes self
and returns the raw bytes making up the key.
Trait Implementations
impl Into<[u8; 16]> for AesKey
[src]
impl AsRef<[u8]> for AesKey
[src]
impl AsRef<[u8; 16]> for AesKey
[src]
impl From<[u8; 16]> for AesKey
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToHex for T where
T: AsRef<[u8]>,
[src]
T: AsRef<[u8]>,