Skip to main content

SecurityPolicy

Enum SecurityPolicy 

Source
pub enum SecurityPolicy {
    Basic256Sha256,
    Aes128Sha256RsaOaep,
    Aes256Sha256RsaPss,
}
Expand description

Security policy for a SignAndEncrypt secure channel.

Variants§

§

Basic256Sha256

Widely supported RSA policy.

§

Aes128Sha256RsaOaep

RSA-OAEP key exchange with AES-128 symmetric encryption.

§

Aes256Sha256RsaPss

RSA-PSS signatures with AES-256 symmetric encryption.

Implementations§

Source§

impl SecurityPolicy

Source

pub const fn uri(self) -> &'static str

OPC UA policy URI for endpoint selection.

Examples found in repository?
examples/local_server.rs (line 41)
15fn main() -> Result<(), Box<dyn Error>> {
16    let port = std::env::args()
17        .nth(1)
18        .unwrap_or_else(|| "4840".into())
19        .parse::<NonZeroU16>()?;
20    let args: Vec<String> = std::env::args().skip(2).collect();
21    let (host, runner) = match args.as_slice() {
22        [] => Server::loopback(port, "urn:example:line")?,
23        [uri, cert, key, client_uri, client_cert, policy @ ..] => Server::secure_with_policy(
24            SecureServerConfig {
25                bind: ([127, 0, 0, 1], port.get()).into(),
26                application_uri: uri,
27                certificate_der: &std::fs::read(cert)?,
28                private_key_der: &std::fs::read(key)?,
29                trusted_client_uri: client_uri,
30                trusted_client_certificate_der: &std::fs::read(client_cert)?,
31            },
32            "urn:example:line",
33            match policy {
34                [] => SecurityPolicy::Basic256Sha256,
35                [p] => [
36                    SecurityPolicy::Basic256Sha256,
37                    SecurityPolicy::Aes128Sha256RsaOaep,
38                    SecurityPolicy::Aes256Sha256RsaPss,
39                ]
40                .into_iter()
41                .find(|policy| policy.uri().rsplit('#').next() == Some(p.as_str()))
42                .ok_or("unknown security policy")?,
43                _ => return Err("expected at most one security policy".into()),
44            },
45        )?,
46        _ => {
47            return Err(
48                "expected PORT [SERVER_URI SERVER.der SERVER_KEY.der CLIENT_URI CLIENT.der [POLICY]]".into(),
49            );
50        }
51    };
52    let counter = host.add_variable("PartsProduced", 0_u64)?;
53    let stop = Arc::new(AtomicBool::new(false));
54    let input_closed = Arc::clone(&stop);
55    thread::spawn(move || {
56        for line in io::stdin().lock().lines() {
57            let Ok(line) = line else { break };
58            match line.trim().parse() {
59                Ok(n) => {
60                    if let Err(error) = counter.set(n) {
61                        eprintln!("update failed: {error}");
62                    }
63                }
64                Err(error) => eprintln!("expected a UInt64: {error}"),
65            }
66        }
67        input_closed.store(true, Ordering::Release);
68    });
69    eprintln!("Serving PartsProduced on opc.tcp://127.0.0.1:{port} while stdin is open");
70    runner.run_until(|| stop.load(Ordering::Acquire))?;
71    Ok(())
72}

Trait Implementations§

Source§

impl Clone for SecurityPolicy

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 SecurityPolicy

Source§

impl Debug for SecurityPolicy

Source§

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

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

impl Default for SecurityPolicy

Source§

fn default() -> Self

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

impl Eq for SecurityPolicy

Source§

impl PartialEq for SecurityPolicy

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 SecurityPolicy

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> 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 = !

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.