X213NetworkAddress

Enum X213NetworkAddress 

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

  1. Unrecognized encodings could mean that two values cannot be compared for equality because their semantics are unknown.
  2. Even among recognized encodings, it is not clear whether or not the decimal encoding should always be considered equal to the binary encoding.
  3. 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>

Source

pub fn get_octets(&'a self) -> &'a [u8]

Get the bytes of the encoded NSAP address

Source

pub fn afi(&self) -> u8

Get the Authority and Format Identifier (AFI): part of an NSAP address

Source

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

Source

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

Source

pub fn from_slice_unchecked(octets: &'a [u8]) -> X213NetworkAddress<'a>

Create an NSAP address from its binary encoding as a &[u8] without checking validity

Source

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

Source

pub fn get_network_type_info(&self) -> Option<X213NetworkAddressInfo>

Get network type info for this NSAP address

Source

pub fn get_network_type(&self) -> Option<X213NetworkAddressType>

Get the network type for this NSAP address

Source

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.

Source

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.

Source

pub fn get_url(&'a self) -> Option<&'a str>

Get the encoded URL

This returns None if this NSAP does not encode a URL

Source

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

Source

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

Source

pub fn from_ip(ip: &IpAddr) -> Self

Create a new IANA ICP NSAP address from an IP address

Source

pub fn from_ipv4(ip: &Ipv4Addr) -> Self

Create a new IANA ICP NSAP address from an IPv4 address

Source

pub fn from_ipv6(ip: &Ipv6Addr) -> Self

Create a new IANA ICP NSAP address from an IPv6 address

Source

pub fn from_itot_url(url: &str) -> Self

Create a new X.519 ITOT URL NSAP address from a URL

Source

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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for X213NetworkAddress<'a>

Source§

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

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

impl<'a> Display for X213NetworkAddress<'a>

Source§

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

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

impl<'a> From<&IpAddr> for X213NetworkAddress<'a>

Source§

fn from(value: &IpAddr) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&Ipv4Addr> for X213NetworkAddress<'a>

Source§

fn from(value: &Ipv4Addr) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&Ipv6Addr> for X213NetworkAddress<'a>

Source§

fn from(value: &Ipv6Addr) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromStr for X213NetworkAddress<'a>

Source§

type Err = RFC1278ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, RFC1278ParseError>

Parses a string s to return a value of this type. Read more
Source§

impl<'a> TryFrom<&'a [u8]> for X213NetworkAddress<'a>

Source§

type Error = NAddressParseError

The type returned in the event of a conversion error.
Source§

fn try_from(octets: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<Vec<u8>> for X213NetworkAddress<'a>

Source§

type Error = NAddressParseError

The type returned in the event of a conversion error.
Source§

fn try_from(octets: Vec<u8>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for X213NetworkAddress<'a>

§

impl<'a> RefUnwindSafe for X213NetworkAddress<'a>

§

impl<'a> Send for X213NetworkAddress<'a>

§

impl<'a> Sync for X213NetworkAddress<'a>

§

impl<'a> Unpin for X213NetworkAddress<'a>

§

impl<'a> UnwindSafe for X213NetworkAddress<'a>

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.