rusmpp_core/pdus/owned/
outbind.rs

1use rusmpp_macros::Rusmpp;
2
3use crate::{pdus::owned::Pdu, types::owned::COctetString};
4
5/// Authentication PDU used by a Message Centre to Outbind to
6/// an ESME to inform it that messages are present in the MC.
7/// The PDU contains identification, and access password for the
8/// ESME. If the ESME authenticates the request, it will respond
9/// with a bind_receiver or bind_transceiver to begin the process
10/// of binding into the MC.
11#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Rusmpp)]
12#[rusmpp(decode = owned, test = skip)]
13#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
14#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
15#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
16pub struct Outbind {
17    /// MC identifier.
18    ///
19    /// Identifies the MC to the ESME.
20    pub system_id: COctetString<1, 16>,
21    /// The password may be used by the
22    /// ESME for security reasons to
23    /// authenticate the MC originating the
24    /// outbind.
25    pub password: COctetString<1, 9>,
26}
27
28impl Outbind {
29    pub fn new(system_id: COctetString<1, 16>, password: COctetString<1, 9>) -> Self {
30        Self {
31            system_id,
32            password,
33        }
34    }
35
36    pub fn builder() -> OutbindBuilder {
37        OutbindBuilder::new()
38    }
39}
40
41impl From<Outbind> for Pdu {
42    fn from(value: Outbind) -> Self {
43        Self::Outbind(value)
44    }
45}
46
47#[derive(Debug, Default)]
48pub struct OutbindBuilder {
49    inner: Outbind,
50}
51
52impl OutbindBuilder {
53    pub fn new() -> Self {
54        Self::default()
55    }
56
57    pub fn system_id(mut self, system_id: COctetString<1, 16>) -> Self {
58        self.inner.system_id = system_id;
59        self
60    }
61
62    pub fn password(mut self, password: COctetString<1, 9>) -> Self {
63        self.inner.password = password;
64        self
65    }
66
67    pub fn build(self) -> Outbind {
68        self.inner
69    }
70}
71
72#[cfg(test)]
73mod tests {
74    use std::str::FromStr;
75
76    use crate::tests::TestInstance;
77
78    use super::*;
79
80    impl TestInstance for Outbind {
81        fn instances() -> alloc::vec::Vec<Self> {
82            alloc::vec![
83                Self::default(),
84                Self::builder()
85                    .system_id(COctetString::from_str("system_id").unwrap())
86                    .password(COctetString::from_str("password").unwrap())
87                    .build(),
88            ]
89        }
90    }
91
92    #[test]
93    fn encode_decode() {
94        crate::tests::owned::encode_decode_test_instances::<Outbind>();
95    }
96}