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: u8Consecutive failed reply_to_HLS_authentication attempts, for rate
limiting (see Self::reply_to_hls_authentication_checked).
Implementations§
Source§impl AssociationLn
impl AssociationLn
Sourcepub fn new(config: AssociationLnConfig) -> Self
pub fn new(config: AssociationLnConfig) -> Self
Builds a new AssociationLn from its configuration.
Sourcepub fn set_ctos(&mut self, ctos: Vec<u8>)
pub fn set_ctos(&mut self, ctos: Vec<u8>)
Stores the client challenge (CtoS) received in the AARQ (Pass 1).
Sourcepub fn set_stoc(&mut self, stoc: Vec<u8>)
pub fn set_stoc(&mut self, stoc: Vec<u8>)
Stores the server challenge (StoC) sent to the client in the AARE (Pass 2).
Sourcepub fn generate_stoc(&mut self, len: usize) -> Vec<u8> ⓘ
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.
Sourcepub fn set_hls_context(&mut self, ctx: HlsContext)
pub fn set_hls_context(&mut self, ctx: HlsContext)
Sets the cryptographic material for the HLS handshake (mechanisms 5/6/8/9).
Sourcepub fn set_client_system_title(&mut self, title: Vec<u8>)
pub fn set_client_system_title(&mut self, title: Vec<u8>)
Updates the client system title used by title-bound HLS mechanisms.
Sourcepub fn set_hls_handshake_mechanism(&mut self, mechanism: AuthMechanism)
pub fn set_hls_handshake_mechanism(&mut self, mechanism: AuthMechanism)
Records the mechanism proposed in the AARQ for the four-pass handshake.
fn hls_mechanism(&self) -> AuthMechanism
Sourcepub fn responding_ap_title_for_hls(&self) -> Option<Vec<u8>>
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.
Sourcepub fn authentication_mechanism(&self) -> AuthenticationMechanism
pub fn authentication_mechanism(&self) -> AuthenticationMechanism
Returns the authentication mechanism of this association (attribute 6).
Sourcepub fn set_association_status(&mut self, status: u8)
pub fn set_association_status(&mut self, status: u8)
Sets the association status (attribute 8): 0 = non-associated, 1 = association-pending, 2 = associated.
Sourcepub fn association_status(&self) -> u8
pub fn association_status(&self) -> u8
Current association status (attribute 8): 0 non-associated, 1 pending, 2 associated.
Sourcefn change_hls_secret(
&mut self,
data: CosemDataType,
) -> Result<CosemDataType, String>
fn change_hls_secret( &mut self, data: CosemDataType, ) -> Result<CosemDataType, String>
Method 2: change_HLS_secret — replaces the secret (password/key).
Sourcefn reply_to_hls_authentication(
&self,
data: CosemDataType,
) -> Result<CosemDataType, String>
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.
Sourcefn reply_to_hls_authentication_checked(
&mut self,
data: CosemDataType,
) -> Result<CosemDataType, String>
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.
Sourcefn secret_bytes(&self) -> &[u8] ⓘ
fn secret_bytes(&self) -> &[u8] ⓘ
Returns the secret as bytes.
Sourcefn add_object(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>
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.
Sourcefn remove_object(
&mut self,
data: &CosemDataType,
) -> Result<CosemDataType, String>
fn remove_object( &mut self, data: &CosemDataType, ) -> Result<CosemDataType, String>
Method 4: remove_object — removes an object_list_element from object_list.
Sourcefn add_user(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>
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).
Sourcefn remove_user(&mut self, data: &CosemDataType) -> Result<CosemDataType, String>
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).
Sourcepub fn find_object(
&self,
class_id: u16,
logical_name: &ObisCode,
) -> Option<&ObjectListEntry>
pub fn find_object( &self, class_id: u16, logical_name: &ObisCode, ) -> Option<&ObjectListEntry>
Finds an object_list entry by class_id and logical name.
Sourcepub fn can_read(
&self,
class_id: u16,
logical_name: &ObisCode,
attribute_id: i8,
) -> bool
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.
Sourcepub fn can_write(
&self,
class_id: u16,
logical_name: &ObisCode,
attribute_id: i8,
) -> bool
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.
Sourcepub fn can_invoke(
&self,
class_id: u16,
logical_name: &ObisCode,
method_id: i8,
) -> bool
pub fn can_invoke( &self, class_id: u16, logical_name: &ObisCode, method_id: i8, ) -> bool
Checks whether a method invocation is allowed.
Sourcepub fn object_list_entries(&self) -> &[ObjectListEntry]
pub fn object_list_entries(&self) -> &[ObjectListEntry]
Returns the parsed object_list.
Sourcepub fn add_object_with_access(&mut self, entry: ObjectListEntry)
pub fn add_object_with_access(&mut self, entry: ObjectListEntry)
Adds an object_list entry with the given access rights.
Source§impl AssociationLn
impl AssociationLn
Sourcefn authentication_mechanism_name(&self) -> CosemDataType
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
impl Clone for AssociationLn
Source§fn clone(&self) -> AssociationLn
fn clone(&self) -> AssociationLn
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AssociationLn
impl Debug for AssociationLn
Source§impl<'de> Deserialize<'de> for AssociationLn
impl<'de> Deserialize<'de> for AssociationLn
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl InterfaceClass for AssociationLn
impl InterfaceClass for AssociationLn
Source§fn logical_name(&self) -> &ObisCode
fn logical_name(&self) -> &ObisCode
Source§fn attributes(&self) -> Vec<(u8, CosemDataType)>
fn attributes(&self) -> Vec<(u8, CosemDataType)>
(attribute_id, value) pairs.