Enum Key

Source
pub enum Key {
    Secret(String),
    RC4Key([u8; 16]),
    AES128Key([u8; 16]),
    AES256Key([u8; 32]),
}
Expand description

Encapsules the possible keys used by this Kerberos implementation. Each key can be used by a different cryptographic algorithm.

Variants§

§

Secret(String)

The secret of the user. This is the most versatile key, since can it can be use to derive the rest of the keys, and therefore, being used by any cryptographic algorithm.

§

RC4Key([u8; 16])

RC4 key used by RC4-HMAC algorithm. In Windows, this is the NTLM hash of the user password.

§

AES128Key([u8; 16])

AES key used by AES128-CTS-HMAC-SHA1-96 algorithm.

§

AES256Key([u8; 32])

AES key used by AES256-CTS-HMAC-SHA1-96 algorithm.

Implementations§

Source§

impl Key

Source

pub fn random(etype: i32) -> Result<Key, Error>

Generates a random key of the given etype

§Error

Returns error if the etype is not supported

Source

pub fn etypes(&self) -> Vec<i32>

Return the etypes associated with the type of key.

§Examples
use himmelblau_kerberos_crypto::*;
use himmelblau_kerberos_constants::etypes::*;

assert_eq!(
    vec![AES256_CTS_HMAC_SHA1_96, AES128_CTS_HMAC_SHA1_96, RC4_HMAC],
    Key::Secret("".to_string()).etypes()
);
assert_eq!(vec![RC4_HMAC], Key::RC4Key([0; RC4_KEY_SIZE]).etypes());
assert_eq!(
    vec![AES128_CTS_HMAC_SHA1_96],
    Key::AES128Key([0; AES128_KEY_SIZE]).etypes()
);
assert_eq!(
    vec![AES256_CTS_HMAC_SHA1_96],
    Key::AES256Key([0; AES256_KEY_SIZE]).etypes()
);
Source

pub fn as_bytes(&self) -> &[u8]

Retrieve the key as an array of bytes.

§Examples
use himmelblau_kerberos_crypto::*;

assert_eq!(&[0x73, 0x65, 0x63, 0x72, 0x65, 0x74], Key::Secret("secret".to_string()).as_bytes());
assert_eq!(&[0; RC4_KEY_SIZE], Key::RC4Key([0; RC4_KEY_SIZE]).as_bytes());
assert_eq!(&[0; AES128_KEY_SIZE], Key::AES128Key([0; AES128_KEY_SIZE]).as_bytes());
assert_eq!(&[0; AES256_KEY_SIZE], Key::AES256Key([0; AES256_KEY_SIZE]).as_bytes());
Source

pub fn from_rc4_key_string(hex_str: &str) -> Result<Key, Error>

Get a RC4 key from a hexdump.

§Example
use himmelblau_kerberos_crypto::Key;
assert_eq!(
    Key::RC4Key([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]),
    Key::from_rc4_key_string("0123456789ABCDEF0123456789abcdef").unwrap()
);
§Errors

An error if raised if the argument string has any non hexadecimal character or size is different from 32.

Source

pub fn from_aes_128_key_string(hex_str: &str) -> Result<Key, Error>

Get a AES-128 key from a hexdump.

§Example
use himmelblau_kerberos_crypto::Key;
assert_eq!(
    Key::AES128Key([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]),
    Key::from_aes_128_key_string("0123456789ABCDEF0123456789abcdef").unwrap()
);
§Errors

An error if raised if the argument string has any non hexadecimal character or size is different from 32.

Source

pub fn from_aes_256_key_string(hex_str: &str) -> Result<Key, Error>

Get a AES-256 key from a hexdump.

§Example
use himmelblau_kerberos_crypto::Key;
assert_eq!(
    Key::AES256Key([
        0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
        0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
    ]),
    Key::from_aes_256_key_string("0123456789ABCDEF0123456789abcdef0123456789ABCDEF0123456789abcdef").unwrap()
);
§Errors

An error if raised if the argument string has any non hexadecimal character or size is different from 64.

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Key

Source§

fn eq(&self, other: &Key) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Key

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,