Skip to main content

CompressedDate

Struct CompressedDate 

Source
pub struct CompressedDate(/* private fields */);
Expand description

3-byte date encoding per Microchip format

Layout (24 bits total, little-endian):

  • Bits 0-4: Year (years since BASE_YEAR, valid 0-31 = 2025-2056)
  • Bits 5-8: Month (1-12)
  • Bits 9-13: Day (1-31)
  • Bits 14-18: Hour (0-23)
  • Bits 19-23: Expire years (0-31 years validity)

Implementations§

Source§

impl CompressedDate

Source

pub const fn new() -> Self

Create a new CompressedDate with all fields set to 0

Source

pub const fn year(&self) -> u8

Get the year offset from Self::BASE_YEAR (0-31)

Source

pub const fn with_year(self, year: u8) -> Self

Set the year offset and return self (builder pattern)

Source

pub const fn month(&self) -> u8

Get the month (1-12)

Source

pub const fn with_month(self, month: u8) -> Self

Set the month and return self (builder pattern)

Source

pub const fn day(&self) -> u8

Get the day of month (1-31)

Source

pub const fn with_day(self, day: u8) -> Self

Set the day and return self (builder pattern)

Source

pub const fn hour(&self) -> u8

Get the hour (0-23)

Source

pub const fn with_hour(self, hour: u8) -> Self

Set the hour and return self (builder pattern)

Source

pub const fn expire_years(&self) -> u8

Get the certificate validity in years (0-31)

Source

pub const fn with_expire_years(self, years: u8) -> Self

Set the expire years and return self (builder pattern)

Source

pub fn with_month_checked(self, month: u8) -> Result<Self, Error>

Set month with validation (1-12)

Source

pub fn with_day_checked(self, day: u8) -> Result<Self, Error>

Set day with validation (1-31)

Source

pub fn with_hour_checked(self, hour: u8) -> Result<Self, Error>

Set hour with validation (0-23)

Source§

impl CompressedDate

Source

pub const BASE_YEAR: u16 = 2025

Base year for compressed date encoding.

The 5-bit year field encodes an offset 0-31, giving issue years BASE_YEAR..=BASE_YEAR + 31. The base is not stored in the 72-byte compressed cert — it is implicit in this constant on both the issuer and the device, so a cert compressed under one base would reconstruct to a different date (and thus a different, unverifiable TBS) under another. It can only be changed before any device holds a compressed cert.

Source

pub const MAX_YEAR_OFFSET: u8 = 31

Maximum year offset (5 bits)

Source

pub const MAX_EXPIRE_YEARS: u8 = 31

Maximum expire years (5 bits)

Source

pub fn from_validity(validity: &Validity) -> Result<Self, Error>

Convert from X.509 Validity to compressed date format

Source

pub fn to_validity(&self) -> Result<Validity, Error>

Convert compressed date to X.509 Validity

Source

pub fn to_bytes(&self) -> [u8; 3]

Convert to 3-byte array for storage

Source

pub fn from_bytes(bytes: [u8; 3]) -> Self

Create from 3-byte array

Trait Implementations§

Source§

impl Clone for CompressedDate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for CompressedDate

Source§

impl Debug for CompressedDate

Source§

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

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

impl Default for CompressedDate

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CompressedDate

Source§

impl PartialEq for CompressedDate

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CompressedDate

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.