dtls_handler_t

Struct dtls_handler_t 

Source
#[repr(C)]
pub struct dtls_handler_t { pub write: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, buf: *mut uint8, len: usize) -> c_int>, pub read: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, buf: *mut uint8, len: usize) -> c_int>, pub event: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, level: dtls_alert_level_t, code: c_ushort) -> c_int>, pub get_user_parameters: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, parameters: *mut dtls_user_parameters_t)>, pub get_psk_info: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, type_: dtls_credentials_type_t, desc: *const c_uchar, desc_len: usize, result: *mut c_uchar, result_length: usize) -> c_int>, pub get_ecdsa_key: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, result: *mut *const dtls_ecdsa_key_t) -> c_int>, pub verify_ecdsa_key: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, other_pub_x: *const c_uchar, other_pub_y: *const c_uchar, key_size: usize) -> c_int>, }
Expand description

This structure contains callback functions used by tinydtls to communicate with the application. At least the write function must be provided. It is called by the DTLS state machine to send packets over the network. The read function is invoked to deliver decrypted and verfified application data. The third callback is an event handler function that is called when alert messages are encountered or events generated by the library have occured.

Fields§

§write: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, buf: *mut uint8, len: usize) -> c_int>

Called from dtls_handle_message() to send DTLS packets over the network. The callback function must use the network interface denoted by session->ifindex to send the data.

@param ctx The current DTLS context. @param session The session object, including the address of the remote peer where the data shall be sent. @param buf The data to send. @param len The actual length of @p buf. @return The callback function must return the number of bytes that were sent, or a value less than zero to indicate an error.

§read: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, buf: *mut uint8, len: usize) -> c_int>

Called from dtls_handle_message() deliver application data that was received on the given session. The data is delivered only after decryption and verification have succeeded.

@param ctx The current DTLS context. @param session The session object, including the address of the data’s origin. @param buf The received data packet. @param len The actual length of @p buf. @return ignored

§event: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, level: dtls_alert_level_t, code: c_ushort) -> c_int>

The event handler is called when a message from the alert protocol is received or the state of the DTLS session changes.

@param ctx The current dtls context. @param session The session object that was affected. @param level The alert level or @c 0 when an event ocurred that is not an alert. @param code Values less than @c 256 indicate alerts, while @c 256 or greater indicate internal DTLS session changes. @return ignored

§get_user_parameters: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *mut session_t, parameters: *mut dtls_user_parameters_t)>

Called during handshake to get the user parameter.

@param ctx The current dtls context. @param session The session where the cipher suites will be used. @param parameters The pointer to user parameters. The user parameters are initialized with the default values.

§get_psk_info: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, type_: dtls_credentials_type_t, desc: *const c_uchar, desc_len: usize, result: *mut c_uchar, result_length: usize) -> c_int>

Called during handshake to get information related to the psk key exchange. The type of information requested is indicated by @p type which will be one of DTLS_PSK_HINT, DTLS_PSK_IDENTITY, or DTLS_PSK_KEY. The called function must store the requested item in the buffer @p result of size @p result_length. On success, the function must return the actual number of bytes written to @p result, of a value less than zero on error. The parameter @p desc may contain additional request information (e.g. the psk_identity for which a key is requested when @p type == @c DTLS_PSK_KEY.

@param ctx The current dtls context. @param session The session where the key will be used. @param type The type of the requested information. @param desc Additional request information @param desc_len The actual length of desc. @param result Must be filled with the requested information. @param result_length Maximum size of @p result. @return The number of bytes written to @p result or a value less than zero on error.

§get_ecdsa_key: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, result: *mut *const dtls_ecdsa_key_t) -> c_int>

Called during handshake to get the server’s or client’s ecdsa key used to authenticate this server or client in this session. If found, the key must be stored in @p result and the return value must be @c 0. If not found, @p result is undefined and the return value must be less than zero.

If ECDSA should not be supported, set this pointer to NULL.

Implement this if you want to provide your own certificate to the other peer. This is mandatory for a server providing ECDSA support and optional for a client. A client doing DTLS client authentication has to implementing this callback.

@param ctx The current dtls context. @param session The session where the key will be used. @param result Must be set to the key object to used for the given session. @return @c 0 if result is set, or less than zero on error.

§verify_ecdsa_key: Option<unsafe extern "C" fn(ctx: *mut dtls_context_t, session: *const session_t, other_pub_x: *const c_uchar, other_pub_y: *const c_uchar, key_size: usize) -> c_int>

Called during handshake to check the peer’s pubic key in this session. If the public key matches the session and should be considerated valid the return value must be @c 0. If not valid, the return value must be less than zero.

If ECDSA should not be supported, set this pointer to NULL.

Implement this if you want to verify the other peers public key. This is mandatory for a DTLS client doing based ECDSA authentication. A server implementing this will request the client to do DTLS client authentication.

@param ctx The current dtls context. @param session The session where the key will be used. @param other_pub_x x component of the public key. @param other_pub_y y component of the public key. @return @c 0 if public key matches, or less than zero on error. error codes: return dtls_alert_fatal_create(DTLS_ALERT_BAD_CERTIFICATE); return dtls_alert_fatal_create(DTLS_ALERT_UNSUPPORTED_CERTIFICATE); return dtls_alert_fatal_create(DTLS_ALERT_CERTIFICATE_REVOKED); return dtls_alert_fatal_create(DTLS_ALERT_CERTIFICATE_EXPIRED); return dtls_alert_fatal_create(DTLS_ALERT_CERTIFICATE_UNKNOWN); return dtls_alert_fatal_create(DTLS_ALERT_UNKNOWN_CA);

Trait Implementations§

Source§

impl Clone for dtls_handler_t

Source§

fn clone(&self) -> dtls_handler_t

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 Debug for dtls_handler_t

Source§

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

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

impl Copy for dtls_handler_t

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
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> 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.