Skip to main content

AssociationLn

Struct AssociationLn 

Source
pub struct AssociationLn {
Show 18 fields logical_name: ObisCode, version: AssociationLnVersion, object_list: Vec<ObjectListElement>, associated_partners_id: AssociatedPartnersId, application_context_name: ContextName, xdlms_context_info: XDLMSContextInfo, authentication_mechanism: AuthenticationMechanism, secret: Vec<u8>, association_status: u8, security_setup_reference: ObisCode, user_list: Vec<User>, current_user: Option<User>, parsed_object_list: Vec<ObjectListEntry>, ctos: Option<Vec<u8>>, stoc: Option<Vec<u8>>, hls_context: Option<HlsContext>, hls_handshake_mechanism: Option<AuthMechanism>, hls_failures: u8,
}
Expand description

Association LN interface class (class_id = 15) per IEC 62056-6-2 §4.4.3. Models the associations between a client and the server (logical device) and carries the authentication mechanism and HLS handshake used to open them.

Fields§

§logical_name: ObisCode§version: AssociationLnVersion§object_list: Vec<ObjectListElement>§associated_partners_id: AssociatedPartnersId§application_context_name: ContextName§xdlms_context_info: XDLMSContextInfo§authentication_mechanism: AuthenticationMechanism§secret: Vec<u8>§association_status: u8§security_setup_reference: ObisCode§user_list: Vec<User>§current_user: Option<User>§parsed_object_list: Vec<ObjectListEntry>

Parsed object_list with structured access rights.

§ctos: Option<Vec<u8>>

Transient HLS handshake state — not part of the COSEM attributes. Client-to-server challenge (CtoS) received in the AARQ (Pass 1).

§stoc: Option<Vec<u8>>

Server-to-client challenge (StoC) sent in the AARE (Pass 2).

§hls_context: Option<HlsContext>

Cryptographic material for the HLS handshake (mechanisms 5/6/8/9). Not needed for the plain-hash mechanisms 3/4.

§hls_handshake_mechanism: Option<AuthMechanism>

Mechanism used for the in-flight four-pass HLS handshake (may differ from Self::authentication_mechanism when the client proposes the generic mechanism 2 against a GMAC-configured association).

§hls_failures: u8

Consecutive failed reply_to_HLS_authentication attempts, for rate limiting (see Self::reply_to_hls_authentication_checked).

Implementations§

Source§

impl AssociationLn

Source

pub fn new(config: AssociationLnConfig) -> Self

Builds a new AssociationLn from its configuration.

Source

pub fn set_ctos(&mut self, ctos: Vec<u8>)

Stores the client challenge (CtoS) received in the AARQ (Pass 1).

Source

pub fn set_stoc(&mut self, stoc: Vec<u8>)

Stores the server challenge (StoC) sent to the client in the AARE (Pass 2).

Source

pub fn generate_stoc(&mut self, len: usize) -> Vec<u8> ⓘ

Generates a random server challenge StoC of len octets (8..64 per IEC 62056-5-3, Table 32), stores it, and returns it for the AARE.

Source

pub fn set_hls_context(&mut self, ctx: HlsContext)

Sets the cryptographic material for the HLS handshake (mechanisms 5/6/8/9).

Source

pub fn set_client_system_title(&mut self, title: Vec<u8>)

Updates the client system title used by title-bound HLS mechanisms.

Source

pub fn set_hls_handshake_mechanism(&mut self, mechanism: AuthMechanism)

Records the mechanism proposed in the AARQ for the four-pass handshake.

Source

fn hls_mechanism(&self) -> AuthMechanism

Source

pub fn responding_ap_title_for_hls(&self) -> Option<Vec<u8>>

Server system title for the AARE responding-AP-title on HLS pass 1/2.

Source

pub fn authentication_mechanism(&self) -> AuthenticationMechanism

Returns the authentication mechanism of this association (attribute 6).

Source

pub fn secret(&self) -> &[u8] ⓘ

Returns the LLS/HLS secret (attribute 7).

Source

pub fn set_association_status(&mut self, status: u8)

Sets the association status (attribute 8): 0 = non-associated, 1 = association-pending, 2 = associated.

Source

pub fn association_status(&self) -> u8

Current association status (attribute 8): 0 non-associated, 1 pending, 2 associated.

Source

fn change_hls_secret( &mut self, data: CosemDataType, ) -> Result<CosemDataType, String>

Method 2: change_HLS_secret — replaces the secret (password/key).

Source

fn reply_to_hls_authentication( &self, data: CosemDataType, ) -> Result<CosemDataType, String>

Method 1: reply_to_HLS_authentication (Pass 3 → Pass 4).

The client sends its processed value of the server challenge f(StoC). The server VERIFIES it against the stored StoC and the secret and, only on a match, returns its processed value of the client challenge f(CtoS) (IEC 62056-6-2 §5.3.5.3.1, IEC 62056-5-3 Table 32). On a mismatch the authentication is rejected and no data is returned.

Requires StoC (Pass 2) and CtoS (Pass 1) to be set beforehand via AssociationLn::set_stoc/AssociationLn::generate_stoc and AssociationLn::set_ctos. For mechanism 5 (GMAC), also AssociationLn::set_hls_context.

Source

fn reply_to_hls_authentication_checked( &mut self, data: CosemDataType, ) -> Result<CosemDataType, String>

Rate-limited wrapper around Self::reply_to_hls_authentication (method 1): after MAX_HLS_FAILURES consecutive failed attempts, further attempts are rejected without even checking the response, mitigating brute-force guessing of the challenge response. The counter resets on a successful authentication.

Source

fn secret_bytes(&self) -> &[u8] ⓘ

Returns the secret as bytes.

Source

fn add_object(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>

Method 3: add_object — adds an object_list_element to object_list. If an object with the same (class_id, logical_name) already exists, it is updated.

Source

fn remove_object( &mut self, data: &CosemDataType, ) -> Result<CosemDataType, String>

Method 4: remove_object — removes an object_list_element from object_list.

Source

fn add_user(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>

Method 5 (version 2): add_user — adds a user { id, name } entry to user_list. If an entry with the same user id already exists, it is updated (IEC 62056-6-2 §5.3.7.3.5).

Source

fn remove_user(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>

Method 6 (version 2): remove_user — removes the user entry with the given id from user_list (IEC 62056-6-2 §5.3.7.3.6).

Source

pub fn find_object( &self, class_id: u16, logical_name: &ObisCode, ) -> Option<&ObjectListEntry>

Finds an object_list entry by class_id and logical name.

Source

pub fn can_read( &self, class_id: u16, logical_name: &ObisCode, attribute_id: i8, ) -> bool

Checks whether a read is allowed for the given object and attribute.

Source

pub fn can_write( &self, class_id: u16, logical_name: &ObisCode, attribute_id: i8, ) -> bool

Checks whether a write is allowed for the given object and attribute.

Source

pub fn can_invoke( &self, class_id: u16, logical_name: &ObisCode, method_id: i8, ) -> bool

Checks whether a method invocation is allowed.

Source

pub fn object_list_entries(&self) -> &[ObjectListEntry]

Returns the parsed object_list.

Source

pub fn add_object_with_access(&mut self, entry: ObjectListEntry)

Adds an object_list entry with the given access rights.

Source§

impl AssociationLn

Source

fn authentication_mechanism_name(&self) -> CosemDataType

Encodes attribute 6 authentication_mechanism_name as an octet-string containing the OBJECT IDENTIFIER 2.16.756.5.8.2.<mechanism_id> (BER: tag 0x09, length 0x07, 7 value bytes). See DLMS UA 1000-1, 11.4 and IEC 62056-5-3, Table 65 (mechanism_id: LLS=1, MD5=3, SHA-1=4, GMAC=5).

Trait Implementations§

Source§

impl Clone for AssociationLn

Source§

fn clone(&self) -> AssociationLn

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 AssociationLn

Source§

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

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

impl<'de> Deserialize<'de> for AssociationLn

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl InterfaceClass for AssociationLn

Source§

fn class_id(&self) -> u16

Returns the class id (class_id) as defined in IEC 62056-6-2.
Source§

fn version(&self) -> u8

Returns the class version.
Source§

fn logical_name(&self) -> &ObisCode

Returns the object’s logical name (OBIS code).
Source§

fn attributes(&self) -> Vec<(u8, CosemDataType)>

Returns the class attributes as (attribute_id, value) pairs.
Source§

fn methods(&self) -> Vec<(u8, String)>

Returns the class methods as (method_id, name) pairs.
Source§

fn serialize_ber(&self, buf: &mut Vec<u8>) -> Result<(), BerError>

Serializes the object into BER. Read more
Source§

fn deserialize_ber(&mut self, data: &[u8]) -> Result<(), BerError>

Deserializes the object from BER data. Read more
Source§

fn set_attribute( &mut self, attribute_id: u8, value: CosemDataType, ) -> Result<(), String>

Writes the value of a writable attribute. The default implementation rejects the write; classes with writable attributes override it. Read more
Source§

fn invoke_method( &mut self, method_id: u8, params: Option<CosemDataType>, ) -> Result<CosemDataType, String>

Invokes the object method with the given id. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns the object as dyn Any for dynamic downcasting.
Source§

impl Serialize for AssociationLn

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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