Skip to main content

SecurityContext

Struct SecurityContext 

Source
pub struct SecurityContext {
    pub security_control: u8,
    pub encryption_key: Vec<u8>,
    pub authentication_key: Vec<u8>,
    pub system_title: Vec<u8>,
    pub invocation_counter: u32,
    last_peer_ic: u32,
    ic_valid: bool,
}
Expand description

The security material and parameters for one ciphering operation.

Fields§

§security_control: u8

Security control byte (SC).

§encryption_key: Vec<u8>

Block cipher (encryption) key, 16 or 32 octets.

§authentication_key: Vec<u8>

Authentication key (AK), used in the additional authenticated data.

§system_title: Vec<u8>

System title, 8 octets (forms the IV together with the IC).

§invocation_counter: u32

Invocation counter (IC).

§last_peer_ic: u32

The last invocation counter accepted from the peer, for replay rejection. Set by for_suite; updated by the *_unprotect functions.

§ic_valid: bool

Whether last_peer_ic holds a value yet (false until the first successful unprotect).

Implementations§

Source§

impl SecurityContext

Source

pub fn for_suite( policy: SecurityPolicy, suite: SecuritySuite, encryption_key: Vec<u8>, authentication_key: Vec<u8>, system_title: Vec<u8>, invocation_counter: u32, ) -> Result<SecurityContext, CipherError>

Builds a context for a given protection level and security suite, validating that the encryption key length matches the suite (16 octets for suites 0/1, 32 for suite 2) and deriving the security control byte from the policy and the suite id.

Source

fn check_replay(&self, ic: u32) -> Result<(), CipherError>

Checks the received invocation counter against the last one accepted from this peer, rejecting a replayed or reordered-backward APDU before any decryption is attempted (IEC 62056-5-3: the IC must increase monotonically per peer).

Source

fn accept_peer_ic(&mut self, ic: u32)

Records ic as the last invocation counter accepted from the peer, after a successful unprotect.

Source

fn check_send_ic(&self) -> Result<(), CipherError>

Rejects protecting an APDU once the invocation counter has reached its maximum value: it must never wrap back to a smaller value, per IEC 62056-5-3. Re-keying (a fresh IC) is required past this point.

Source

pub fn key_rotation_needed(&self) -> bool

Advisory check for the host: true once the invocation counter is within 1000 of overflow, signalling that the keys should be rotated (a fresh system-title/key pair resets the counter) before CipherError::InvocationCounterExhausted starts rejecting sends.

Source

fn authentication(&self) -> bool

Source

fn encryption(&self) -> bool

Source

fn iv(&self) -> Result<[u8; 12], CipherError>

Trait Implementations§

Source§

impl Clone for SecurityContext

Source§

fn clone(&self) -> SecurityContext

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 Debug for SecurityContext

Source§

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

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

impl Drop for SecurityContext

Source§

fn drop(&mut self)

Zeroizes the key material when the context is dropped, so secrets do not linger in freed memory.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more