Skip to main content

Luks2Header

Struct Luks2Header 

Source
pub struct Luks2Header {
    pub version: u16,
    pub hdr_size: u64,
    pub seqid: u64,
    pub label: String,
    pub checksum_alg: String,
    pub salt: [u8; 64],
    pub uuid: LuksUuid,
    pub subsystem: String,
    pub hdr_offset: u64,
    pub checksum: [u8; 64],
    pub metadata: Luks2Metadata,
}

Fields§

§version: u16§hdr_size: u64§seqid: u64§label: String§checksum_alg: String§salt: [u8; 64]§uuid: LuksUuid§subsystem: String§hdr_offset: u64§checksum: [u8; 64]§metadata: Luks2Metadata

Implementations§

Source§

impl Luks2Header

Source

pub fn num_keyslots(&self) -> usize

Returns the number of configured keyslots.

Examples found in repository?
examples/read_header.rs (line 28)
6fn main() {
7    let args: Vec<String> = env::args().collect();
8    if args.len() < 2 {
9        eprintln!("Usage: {} <device>", args[0]);
10        process::exit(1);
11    }
12
13    let device_path = &args[1];
14    let file = File::open(device_path).unwrap_or_else(|e| {
15        eprintln!("Error opening {}: {}", device_path, e);
16        process::exit(1);
17    });
18
19    match LuksHeader::from_reader(file) {
20        Ok(LuksHeader::V1) => println!("LUKS1 detected on {}", device_path),
21        Ok(LuksHeader::V2(h)) => {
22            println!("LUKS2 detected on {}", device_path);
23            println!("  Label:         {}", h.label);
24            println!("  UUID:          {}", h.uuid);
25            println!("  Subsystem:     {}", h.subsystem);
26            println!("  Checksum Alg:  {}", h.checksum_alg);
27            println!("  Header Size:   {}", h.hdr_size);
28            println!("  Keyslots:      {}", h.num_keyslots());
29            for (id, slot) in &h.metadata.keyslots {
30                match slot {
31                    luks::Luks2Keyslot::Luks2 {
32                        priority, area, kdf, ..
33                    } => {
34                        println!("    Keyslot {}:", id);
35                        println!("      Type:         luks2");
36                        if let Some(p) = priority {
37                            println!("      Priority:     {:?}", p);
38                        }
39                        print_area(area);
40                        print_kdf(kdf);
41                    }
42                    luks::Luks2Keyslot::Reencrypt {
43                        mode,
44                        priority,
45                        area,
46                        kdf,
47                        ..
48                    } => {
49                        println!("    Keyslot {}:", id);
50                        println!("      Type:         reencrypt");
51                        println!("      Mode:         {:?}", mode);
52                        if let Some(p) = priority {
53                            println!("      Priority:     {:?}", p);
54                        }
55                        print_area(area);
56                        print_kdf(kdf);
57                    }
58                }
59            }
60        }
61        Err(e) => {
62            eprintln!("Error reading LUKS header: {}", e);
63            process::exit(1);
64        }
65    }
66}

Trait Implementations§

Source§

impl Clone for Luks2Header

Source§

fn clone(&self) -> Luks2Header

Returns a duplicate 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 Luks2Header

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.