pub enum X213NetworkAddress<'a> {
Heap(Vec<u8>),
Inline((u8, [u8; 22])),
Borrowed(&'a [u8]),
}Expand description
ITU-T Recommendation X.213 NSAP Address
This is composed of three parts, encoded in this order:
- Authority and Format Identifier (AFI): always a single byte, which identifies the network type and the syntax of the encoding that follows
- Initial Domain Identifier (IDI): the authority for allocating further address identifiers, which is always encoded as binary-coded decimal, and padded with either 0x0 or 0x1 depending on whether leading zeroes are significant or not until the maximum length is reached in digits.
- Domain-Specific Part (DSP): the remainder of the information that completes the address and is allocated by the authority identified by the IDI. It can have four abstract syntaxes: BCD, binary, ISO/IEC 646 string, and a national character encoding.
Together, the AFI and IDI are referred to as the Initial Domain Part (IDP).
This type does not implement PartialEq, Eq, or Hash, because:
- Unrecognized encodings could mean that two values cannot be compared for equality because their semantics are unknown.
- Even among recognized encodings, it is not clear whether or not the decimal encoding should always be considered equal to the binary encoding.
- The semantics of the DSP encodings seems to be undefined for most AFIs.
A simple Eq or Hash implementation could just use the raw octets, but
this could contradict cases where two different encoding should be treated
as equal. Letting the caller explicitly hash or compare the octets is more
clear as to what the underlying behavior is.
Variants§
Heap(Vec<u8>)
Allocation on the heap
Inline((u8, [u8; 22]))
Allocation on the stack Even though NSAPs are capped at 20 bytes, this inline buffer accepts up to 22 just so that programming errors are less likely to result in reading out-of-bounds.
Borrowed(&'a [u8])
Reference to an existing allocation
Implementations§
Source§impl<'a> X213NetworkAddress<'a>
impl<'a> X213NetworkAddress<'a>
Sourcepub fn get_octets(&'a self) -> &'a [u8]
pub fn get_octets(&'a self) -> &'a [u8]
Get the bytes of the encoded NSAP address
Sourcepub fn from_vec_unchecked(octets: Vec<u8>) -> X213NetworkAddress<'static>
pub fn from_vec_unchecked(octets: Vec<u8>) -> X213NetworkAddress<'static>
Create an NSAP address from its binary encoding as a Vec<u8> without checking validity
Sourcepub fn from_vec(
octets: Vec<u8>,
) -> Result<X213NetworkAddress<'static>, NAddressParseError>
pub fn from_vec( octets: Vec<u8>, ) -> Result<X213NetworkAddress<'static>, NAddressParseError>
Create an NSAP address from its binary encoding as a Vec<u8> after checking validity
Sourcepub fn from_slice_unchecked(octets: &'a [u8]) -> X213NetworkAddress<'a>
pub fn from_slice_unchecked(octets: &'a [u8]) -> X213NetworkAddress<'a>
Create an NSAP address from its binary encoding as a &[u8] without checking validity
Sourcepub fn from_slice(
octets: &'a [u8],
) -> Result<X213NetworkAddress<'a>, NAddressParseError>
pub fn from_slice( octets: &'a [u8], ) -> Result<X213NetworkAddress<'a>, NAddressParseError>
Create an NSAP address from its binary encoding as a &[u8] after checking validity
Sourcepub fn get_network_type_info(&self) -> Option<X213NetworkAddressInfo>
pub fn get_network_type_info(&self) -> Option<X213NetworkAddressInfo>
Get network type info for this NSAP address
Sourcepub fn get_network_type(&self) -> Option<X213NetworkAddressType>
pub fn get_network_type(&self) -> Option<X213NetworkAddressType>
Get the network type for this NSAP address
Sourcepub fn idi_digits(&'a self) -> Option<BCDDigitsIter<'a>>
pub fn idi_digits(&'a self) -> Option<BCDDigitsIter<'a>>
Iterate over the IDI digits for this NSAP address
Returns None if the AFI is unrecognized, and therefore, that the
NSAP address cannot be parsed, since the end of the IDI cannot be
determined.
Sourcepub fn dsp_digits(&'a self) -> Option<BCDDigitsIter<'a>>
pub fn dsp_digits(&'a self) -> Option<BCDDigitsIter<'a>>
Iterate over the IDI digits for this NSAP address, if the DSP is in decimal
Returns None if the AFI is unrecognized, and therefore, that the
NSAP address cannot be parsed, since the end of the IDI cannot be
determined. Also returns None if the DSP syntax is not decimal.
Sourcepub fn get_url(&'a self) -> Option<&'a str>
pub fn get_url(&'a self) -> Option<&'a str>
Get the encoded URL
This returns None if this NSAP does not encode a URL
Sourcepub fn get_ip(&self) -> Option<IpAddr>
pub fn get_ip(&self) -> Option<IpAddr>
Get the encoded IP address
This only returns an IP address for IANA ICP-based NSAP addresses
This returns None if this NSAP does not encode an IP address
See: https://www.rfc-editor.org/rfc/rfc4548.html
Sourcepub fn get_rfc1277_socket(&self) -> Option<Rfc1277SocketInfo>
pub fn get_rfc1277_socket(&self) -> Option<Rfc1277SocketInfo>
Get the RFC 1277 socket address info
Specifically, if this returns Some(_), it contains a tuple of the
IP network, the socket address, and optionally, the transport-set, as
defined in IETF RFC 1277, in that order.
This returns None if this NSAP does not encode an ITOT socket address
Sourcepub fn from_ipv4(ip: &Ipv4Addr) -> Self
pub fn from_ipv4(ip: &Ipv4Addr) -> Self
Create a new IANA ICP NSAP address from an IPv4 address
Sourcepub fn from_ipv6(ip: &Ipv6Addr) -> Self
pub fn from_ipv6(ip: &Ipv6Addr) -> Self
Create a new IANA ICP NSAP address from an IPv6 address
Sourcepub fn from_itot_url(url: &str) -> Self
pub fn from_itot_url(url: &str) -> Self
Create a new X.519 ITOT URL NSAP address from a URL
Sourcepub fn from_non_osi_url(url: &str) -> Self
pub fn from_non_osi_url(url: &str) -> Self
Create a new X.519 Non-OSI (LDAP, IDM, etc.) URL NSAP address from a URL
Sourcepub fn from_socket_addr_v4(
network: u8,
addr: &SocketAddrV4,
tset: Option<u16>,
) -> Self
pub fn from_socket_addr_v4( network: u8, addr: &SocketAddrV4, tset: Option<u16>, ) -> Self
Create an ITOT NSAP address from a socket address and optional transport set
Note that this only supports IPv4 due to the encoding.
Sourcepub fn to_ns_string(&self) -> String
pub fn to_ns_string(&self) -> String
Convert to a String using the NS+<hex> syntax
This is desirable for portability / interoperability: the NS+<hex>
syntax is the easiest display syntax to parse and leaves no ambiguity of
encoding. This is a great choice if you are exporting an NSAP address in
string format for use in other systems.
The output looks like NS+A433BB93C1.
Sourcepub fn fmt_as_ns_string(&self, f: &mut Formatter<'_>) -> Result
pub fn fmt_as_ns_string(&self, f: &mut Formatter<'_>) -> Result
Display using the NS+<hex> syntax
This is desirable for portability / interoperability: the NS+<hex>
syntax is the easiest display syntax to parse and leaves no ambiguity of
encoding. This is a great choice if you are exporting an NSAP address in
string format for use in other systems.
The output looks like NS+A433BB93C1.