Skip to main content

opcua/types/
mod.rs

1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3// Copyright (C) 2017-2022 Adam Lock
4
5//! The OPC UA Types module contains data types and enumerations for OPC UA.
6//!
7//! This includes:
8//!
9//! 1. All of the built-in data types described in OPC Part 6 Chapter 5 that are encodable.
10//! 2. All of the standard data types described in OPC Part 3 Chapter 8 (if not covered by 1.).
11//! 3. Autogenerated data types and request / responses as described in OPC Part 4.
12//!
13//! For the built-in data types, the module provides functions
14
15///Contains constants recognized by OPC UA clients and servers to describe various protocols and
16/// profiles used during communication and encryption.
17pub mod profiles {
18    pub const TRANSPORT_PROFILE_URI_BINARY: &str =
19        "http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary";
20    pub const SECURITY_USER_TOKEN_POLICY_ANONYMOUS: &str =
21        "http://opcfoundation.org/UA-Profile/Security/UserToken/Anonymous";
22    pub const SECURITY_USER_TOKEN_POLICY_USERPASS: &str =
23        "http://opcfoundation.org/UA-Profile/ Security/UserToken-Server/UserNamePassword";
24}
25
26pub mod constants {
27    /// Default maximum number of elements in an array
28    pub const MAX_ARRAY_LENGTH: usize = 1000;
29    /// Default maximum size of a string in chars
30    pub const MAX_STRING_LENGTH: usize = 65535;
31    /// Default maximum size of a byte string in bytes
32    pub const MAX_BYTE_STRING_LENGTH: usize = 65535;
33    /// Default maximum size of a certificate to send
34    pub const MAX_CERTIFICATE_LENGTH: usize = 32767;
35    /// Default maximum size of a message in bytes. 0 is any length, i.e. the other end can send a message of any size which is
36    /// not recommended in a server configuration. Override in the client / server config.
37    /// In clients, max message size is only preferred size since it can be adjusted by the server during the handshake.
38    pub const MAX_MESSAGE_SIZE: usize = 65535 * MAX_CHUNK_COUNT;
39    /// Default maximum number of chunks in a single message. 0 is any number but this is not recommended
40    /// as the default since server memory could be exhausted. Default number can be overridden
41    /// by client / server config which is where it should happen if you want a different figure. In clients
42    /// chunk size is a preferred value since the server can modify it during the handshake.
43    pub const MAX_CHUNK_COUNT: usize = 5;
44    /// Default maximum decoding depth for recursive data structures, i.e. if data is nested deeper than this it is
45    /// an error during decoding. This is a security measure to stop deeply nested junk being sent to
46    /// a server / client.
47    pub const MAX_DECODING_DEPTH: usize = 10;
48    /// URI supplied for the None security policy
49    pub const SECURITY_POLICY_NONE_URI: &str = "http://opcfoundation.org/UA/SecurityPolicy#None";
50    /// String used as shorthand in config files, debug etc.for `None` security policy
51    pub const SECURITY_POLICY_NONE: &str = "None";
52}
53
54// Attributes mask bits
55bitflags! {
56    pub struct AttributesMask: u32 {
57        /// Indicates if the AccessLevel Attribute is set.
58        const ACCESS_LEVEL = 1;
59        /// Indicates if the ArrayDimensions Attribute is set.
60        const ARRAY_DIMENSIONS = 1 << 1;
61        /// Indicates if the ContainsNoLoops Attribute is set.
62        const CONTAINS_NO_LOOPS = 1 << 3;
63        /// Indicates if the DataType Attribute is set.
64        const DATA_TYPE = 1 << 4;
65        /// Indicates if the Description Attribute is set.
66        const DESCRIPTION = 1 << 5;
67        /// Indicates if the DisplayName Attribute is set.
68        const DISPLAY_NAME = 1 << 6;
69        /// Indicates if the EventNotifier Attribute is set.
70        const EVENT_NOTIFIER = 1 << 7;
71        /// Indicates if the Executable Attribute is set.
72        const EXECUTABLE = 1 << 8;
73        /// Indicates if the Historizing Attribute is set.
74        const HISTORIZING = 1 << 9;
75        /// Indicates if the InverseName Attribute is set.
76        const INVERSE_NAME = 1 << 10;
77        /// Indicates if the IsAbstract Attribute is set.
78        const IS_ABSTRACT = 1 << 11;
79        /// Indicates if the MinimumSamplingInterval Attribute is set.
80        const MINIMUM_SAMPLING_INTERVAL = 1 << 12;
81        /// Indicates if the Symmetric Attribute is set.
82        const SYMMETRIC = 1 << 15;
83        /// Indicates if the UserAccessLevel Attribute is set.
84        const USER_ACCESS_LEVEL = 1 << 16;
85        /// Indicates if the UserExecutable Attribute is set.
86        const USER_EXECUTABLE = 1 << 17;
87        /// Indicates if the UserWriteMask Attribute is set.
88        const USER_WRITE_MASK = 1 << 18;
89        /// Indicates if the ValueRank Attribute is set.
90        const VALUE_RANK = 1 << 19;
91        /// Indicates if the WriteMask Attribute is set.
92        const WRITE_MASK = 1 << 20;
93        /// Indicates if the Value Attribute is set
94        const VALUE = 1 << 21;
95    }
96}
97
98// Write mask bits (similar but different to AttributesMask)
99//
100// See Part 3, Table 43
101bitflags! {
102    pub struct WriteMask: u32 {
103        /// Indicates if the AccessLevel Attribute is writable.
104        const ACCESS_LEVEL = 1;
105        /// Indicates if the ArrayDimensions Attribute is writable.
106        const ARRAY_DIMENSIONS = 1 << 1;
107        ///Indicates if the BrowseName Attribute is writable.
108        const BROWSE_NAME = 1 << 2;
109        /// Indicates if the ContainsNoLoops Attribute is writable.
110        const CONTAINS_NO_LOOPS = 1 << 3;
111        /// Indicates if the DataType Attribute is writable.
112        const DATA_TYPE = 1 << 4;
113        /// Indicates if the Description Attribute is writable.
114        const DESCRIPTION = 1 << 5;
115        /// Indicates if the DisplayName Attribute is writable.
116        const DISPLAY_NAME = 1 << 6;
117        /// Indicates if the EventNotifier Attribute is writable.
118        const EVENT_NOTIFIER = 1 << 7;
119        /// Indicates if the Executable Attribute is writable.
120        const EXECUTABLE = 1 << 8;
121        /// Indicates if the Historizing Attribute is writable.
122        const HISTORIZING = 1 << 9;
123        /// Indicates if the InverseName Attribute is writable.
124        const INVERSE_NAME = 1 << 10;
125        /// Indicates if the IsAbstract Attribute is writable.
126        const IS_ABSTRACT = 1 << 11;
127        /// Indicates if the MinimumSamplingInterval Attribute is writable.
128        const MINIMUM_SAMPLING_INTERVAL = 1 << 12;
129        /// Indicates if the NodeClass Attribute is writable.
130        const NODE_CLASS = 1 << 13;
131        /// Indicates if the NodeId Attribute is writable.
132        const NODE_ID = 1 << 14;
133        /// Indicates if the Symmetric Attribute is writable.
134        const SYMMETRIC = 1 << 15;
135        /// Indicates if the UserAccessLevel Attribute is writable.
136        const USER_ACCESS_LEVEL = 1 << 16;
137        /// Indicates if the UserExecutable Attribute is writable.
138        const USER_EXECUTABLE = 1 << 17;
139        /// Indicates if the UserWriteMask Attribute is writable.
140        const USER_WRITE_MASK = 1 << 18;
141        /// Indicates if the ValueRank Attribute is writable.
142        const VALUE_RANK = 1 << 19;
143        /// Indicates if the WriteMask Attribute is writable.
144        const WRITE_MASK = 1 << 20;
145        /// Indicates if the Value Attribute is writable for a VariableType. It does not apply for Variables
146        /// since this is handled by the AccessLevel and UserAccessLevel Attributes for the Variable.
147        /// For Variables this bit shall be set to 0.
148        const VALUE_FOR_VARIABLE_TYPE = 1 << 21;
149        /// Indicates if the DataTypeDefinition Attribute is writable.
150        const DATA_TYPE_DEFINITION = 1 << 22;
151        /// Indicates if the RolePermissions Attribute is writable.
152        const ROLE_PERMISSIONS = 1 << 23;
153        /// Indicates if the AccessRestrictions Attribute is writable
154        const ACCESS_RESTRICTIONS = 1 << 24;
155        /// Indicates if the AccessLevelEx Attribute is writable
156        const ACCESS_LEVEL_EX = 1 << 25;
157
158        // Bits 26-31. Reserved for future use. Shall always be zero.
159    }
160}
161
162// Bits that control the reference description coming back from browse()
163bitflags! {
164    pub struct BrowseDescriptionResultMask: u32 {
165        const RESULT_MASK_REFERENCE_TYPE = 1;
166        const RESULT_MASK_IS_FORWARD = 1 << 1;
167        const RESULT_MASK_NODE_CLASS = 1 << 2;
168        const RESULT_MASK_BROWSE_NAME = 1 << 3;
169        const RESULT_MASK_DISPLAY_NAME = 1 << 4;
170        const RESULT_MASK_TYPE_DEFINITION = 1 << 5;
171    }
172}
173
174// Bits for a node class mask
175bitflags! {
176    pub struct NodeClassMask: u32 {
177        const OBJECT = 1;
178        const VARIABLE = 1 << 1;
179        const METHOD = 1 << 2;
180        const OBJECT_TYPE = 1 << 3;
181        const VARIABLE_TYPE = 1 << 4;
182        const REFERENCE_TYPE = 1 << 5;
183        const DATA_TYPE = 1 << 6;
184        const VIEW = 1 << 7;
185    }
186}
187
188// These 3 modules are autogenerated
189#[rustfmt::skip]
190mod status_codes;
191#[rustfmt::skip]
192pub mod node_ids;
193#[rustfmt::skip]
194pub mod service_types;
195
196pub mod argument;
197pub mod array;
198pub mod attribute;
199pub mod basic_types;
200pub mod byte_string;
201pub mod data_types;
202pub mod data_value;
203pub mod date_time;
204pub mod diagnostic_info;
205pub mod encoding;
206pub mod expanded_node_id;
207pub mod extension_object;
208pub mod guid;
209pub mod localized_text;
210pub mod node_id;
211pub mod notification_message;
212pub mod numeric_range;
213pub mod operand;
214pub mod qualified_name;
215pub mod relative_path;
216pub mod request_header;
217pub mod response_header;
218pub mod status_code;
219pub mod string;
220pub mod variant;
221pub mod variant_json;
222pub mod variant_type_id;
223
224pub use crate::types::{
225    argument::*, array::*, attribute::*, basic_types::*, byte_string::*, data_types::*,
226    data_value::*, date_time::*, diagnostic_info::*, encoding::*, expanded_node_id::*,
227    extension_object::*, guid::*, localized_text::*, node_id::*, node_ids::*, numeric_range::*,
228    operand::*, qualified_name::*, request_header::*, response_header::*, service_types::*,
229    status_code::*, string::*, variant::*, variant_type_id::*,
230};
231
232#[cfg(test)]
233mod tests;