Skip to main content

ServerAssociationOptions

Struct ServerAssociationOptions 

Source
pub struct ServerAssociationOptions<'a, A> { /* private fields */ }
Expand description

A DICOM association builder for an acceptor DICOM node, often taking the role of a service class provider (SCP).

This is the standard way of negotiating and establishing an association with a requesting node. The outcome is a ServerAssociation. Unlike the ClientAssociationOptions, a value of this type can be reused for multiple connections.

The SCP will by default accept all transfer syntaxes supported by the main transfer syntax registry, unless one or more transfer syntaxes are explicitly indicated through calls to with_transfer_syntax.

Access control logic is also available, enabling application entities to decide on whether to accept or reject the association request based on the called and calling AE titles.

§Basic Usage

§Synchronous API

Spawn a single sync thread to listen for incoming requests.

let scp_options = ServerAssociationOptions::new()
   .with_abstract_syntax("1.2.840.10008.1.1")
   .with_transfer_syntax("1.2.840.10008.1.2.1");

let (stream, _address) = tcp_listener.accept()?;
scp_options.establish(stream)?;

§Asynchronous API

Spawn an async task for each incoming association request.

let listen_addr = SocketAddrV4::new(Ipv4Addr::from(0), 11111);
let listener = tokio::net::TcpListener::bind(listen_addr).await?;
loop {
    let (socket, _addr) = listener.accept().await?;
    tokio::task::spawn(async move {
        let mut scp = ServerAssociationOptions::new()
            .accept_any()
            .with_abstract_syntax("1.2.840.10008.1.1")
            .with_transfer_syntax("1.2.840.10008.1.2.1")
            .establish_async(socket)
            .await
            .expect("Could not establish association on socket");
        loop {
            match scp.receive().await {
                Ok(dicom_ul::Pdu::PData { data }) => {
                    // read P-Data here
                },
                Ok(dicom_ul::Pdu::ReleaseRP) => {
                    break;
                },
                Ok(dicom_ul::Pdu::AbortRQ { source }) => {
                    eprintln!("Association aborted: {source:?}");
                    break;
                },
                Ok(pdu) => {
                    eprintln!("Unexpected PDU");
                },
                Err(e) => {
                    eprintln!("Oops! {e}");
                },
            }
        }
    });
}
fn main() {}

§TLS Support

Enabling one of the Cargo features sync-tls or async-tls unlocks the methods for configuring TLS. Call tls_config for the server to expect associations established over a secure transport connection.

§TLS in synchronous API

Include the sync-tls feature in your Cargo.toml.

§TLS in asynchronous API

Include the async-tls feature in your Cargo.toml.

§Example

use dicom_ul::{ServerAssociation, ServerAssociationOptions};
use std::net::TcpListener;
use rustls::{
    ServerConfig, RootCertStore,
    pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
    server::WebPkiClientVerifier,
};
// Loading certificates and keys for demonstration purposes
let ca_cert = CertificateDer::from_pem_slice(std::fs::read("ssl/ca.crt")?.as_ref())
    .expect("Failed to load client cert");

// Server certificate and private key -- signed by CA
let server_cert = CertificateDer::from_pem_slice(std::fs::read("ssl/server.crt")?.as_ref())
    .expect("Failed to load server cert");

let server_private_key = PrivateKeyDer::from_pem_slice(std::fs::read("ssl/server.key")?.as_ref())
    .expect("Failed to load client private key");

// Create a root cert store for the client which includes the server certificate
let mut certs = RootCertStore::empty();
certs.add_parsable_certificates(vec![ca_cert.clone()]);

// Server configuration.
// Creates a server config that requires client authentication (mutual TLS) using
// webpki for certificate verification.
let server_config = ServerConfig::builder()
    .with_client_cert_verifier(
        WebPkiClientVerifier::builder(certs.clone().into())
            .build()
            .expect("Failed to create client certificate verifier")
    )
    .with_single_cert(vec![server_cert.clone(), ca_cert.clone()], server_private_key)
    .expect("Failed to create server TLS config");

let (stream, _address) = tcp_listener.accept()?;

let association: ServerAssociation<_> = ServerAssociationOptions::new()
    .accept_called_ae_title()
    .ae_title("TLS-SCP")
    .with_abstract_syntax(dicom_dictionary_std::uids::VERIFICATION)
    .tls_config(server_config)
    .establish_tls(stream)?;

For an association with the async API, call establish_tls_async instead of establish_tls.

Implementations§

Source§

impl ServerAssociationOptions<'_, AcceptAny>

Source

pub fn new() -> Self

Create a new set of options for establishing an association.

Source§

impl<'a, A> ServerAssociationOptions<'a, A>
where A: AccessControl,

Source

pub fn accept_any(self) -> ServerAssociationOptions<'a, AcceptAny>

Change the access control policy to accept any association regardless of the specified AE titles.

This is the default behavior when the options are first created.

Source

pub fn accept_called_ae_title( self, ) -> ServerAssociationOptions<'a, AcceptCalledAeTitle>

Change the access control policy to accept an association if the called AE title matches this node’s AE title.

The default is to accept any requesting node regardless of the specified AE titles.

Source

pub fn ae_access_control<P>( self, access_control: P, ) -> ServerAssociationOptions<'a, P>
where P: AccessControl,

Change the access control policy.

The default is to accept any requesting node regardless of the specified AE titles.

Source

pub fn ae_title<T>(self, ae_title: T) -> Self
where T: Into<Cow<'a, str>>,

Define the application entity title referring to this DICOM node.

The default is THIS-SCP.

Source

pub fn with_abstract_syntax<T>(self, abstract_syntax_uid: T) -> Self
where T: Into<Cow<'a, str>>,

Include this abstract syntax in the list of proposed presentation contexts.

Source

pub fn with_transfer_syntax<T>(self, transfer_syntax_uid: T) -> Self
where T: Into<Cow<'a, str>>,

Include this transfer syntax in each proposed presentation context.

Source

pub fn max_pdu_length(self, value: u32) -> Self

Override the maximum expected PDU length.

Source

pub fn strict(self, strict: bool) -> Self

Override strict mode: whether receiving PDUs must not surpass the negotiated maximum PDU length.

Source

pub fn promiscuous(self, promiscuous: bool) -> Self

Override promiscuous mode: whether to accept unknown abstract syntaxes.

Source

pub fn read_timeout(self, timeout: Duration) -> Self

Set the read timeout for the underlying TCP socket

This is used to set both the read and write timeout.

Source

pub fn write_timeout(self, timeout: Duration) -> Self

Set the write timeout for the underlying TCP socket

Source

pub fn establish( &self, socket: TcpStream, ) -> Result<ServerAssociation<TcpStream>, Error>

Negotiate an association with the given TCP stream.

Trait Implementations§

Source§

impl<'a, A: Clone> Clone for ServerAssociationOptions<'a, A>

Source§

fn clone(&self) -> ServerAssociationOptions<'a, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, A: Debug> Debug for ServerAssociationOptions<'a, A>

Source§

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

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

impl Default for ServerAssociationOptions<'_, AcceptAny>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a, A> Freeze for ServerAssociationOptions<'a, A>
where A: Freeze,

§

impl<'a, A> RefUnwindSafe for ServerAssociationOptions<'a, A>
where A: RefUnwindSafe,

§

impl<'a, A> Send for ServerAssociationOptions<'a, A>
where A: Send,

§

impl<'a, A> Sync for ServerAssociationOptions<'a, A>
where A: Sync,

§

impl<'a, A> Unpin for ServerAssociationOptions<'a, A>
where A: Unpin,

§

impl<'a, A> UnsafeUnpin for ServerAssociationOptions<'a, A>
where A: UnsafeUnpin,

§

impl<'a, A> UnwindSafe for ServerAssociationOptions<'a, A>
where A: UnwindSafe,

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
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> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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