Skip to main content

Crate idm_frame

Crate idm_frame 

Source
Expand description

§IDM Frame Utilities

ITU-T Recommendation X.519 (2019) defines a protocol, Internet Directly-Mapped (IDM) Protocol, which is used to provide the OSI ROSE service and all lower layers of the OSI networking stack over TCP/IP, specifically for the purpose of making the X.500 directory easily available over the Internet.

There are two versions of the IDM protocol defined. This crate supports both. The second version supports negotiation of the transfer syntax, whereas the first uses the Basic Encoding Rules (BER).

This crate does not handle decoding of the contained IDM-PDU ASN.1 data structure: it only handles the frames.

§This crate

This crate is no_std and does not require alloc, except for running the tests. This crate was not written in any part by AI or LLMs. This crate was fuzz-tested. It has no dependencies. Extremely simple and light-weight.

§Usage

To read an IDM frame, simply create an IdmFrameIter, and iterate over it one or more times.

let buffer: Vec<u8> = Vec::from([
    1, 1, 0, 0, 0, 5, 1, 2, 3, 4, 5,
].as_slice());
let mut frames = IdmFrameIter::new(buffer.as_slice());
let frame = frames.next()
  .expect("uh oh, no frame")
  .expect("uh oh, unrecognized / unsupported version");
assert_eq!(frame.version, 1);
assert_eq!(frame.final_, 1);
assert_eq!(frame.encoding, 0);
assert_eq!(frame.data, [1,2,3,4,5].as_slice());

This crate also provides two fairly trivial functions for helping you write valid IDM frames: write_idm_v1_frame_header and write_idm_v2_frame_header. These can be used like so:

let mut buf: [u8; IDMV2_FRAME_SIZE] = [0, 0, 0, 0, 0, 0, 0, 0];
write_idm_v2_frame_header(&mut buf, true, IDM_ENCODING_XER, 1024);
assert_eq!(buf, [2, 1, 0x10, 0, 0, 0, 4, 0]);

Cheers!

Structs§

IdmFrame
An IDM Frame
IdmFrameIter
Iterator that reads IDM frames from a buffer, such as a buffer of bytes read in from a TCP socket.

Enums§

IdmError
An error pertaining to IDM frame decoding

Constants§

IDMV1_FRAME_SIZE
Size of a Version 1 IDM Frame
IDMV2_FRAME_SIZE
Size of a Version 2 IDM Frame
IDM_ENCODING_DER
Distinguished Encoding Rules (DER) as described in ITU-T Recommendation X.690.
IDM_ENCODING_PER_ALIGNED
Basic Aligned variant of Packed Encoding Rules (PER) as described in ITU-T Recommendation X.691.
IDM_ENCODING_PER_UNALIGNED
Basic Unaligned variant of Packed Encoding Rules (PER) as described in ITU-T Recommendation X.691.
IDM_ENCODING_XER
XML Encoding Rules (XER) as described in ITU-T Recommendation X.693.
IDM_FINAL
A final frame relaying the last bytes of a complete IDM-PDU
IDM_NOT_FINAL
Not a final frame relaying the last bytes of a complete IDM-PDU
IDM_VERSION_1
IDM Protocol Version 1
IDM_VERSION_2
IDM Protocol Version 2
MIN_FRAME_SIZE
Absolute smallest valid IDM frame

Functions§

write_idm_v1_frame_header
Write an IDM version 1 frame header to header
write_idm_v2_frame_header
Write an IDM version 2 frame header to header

Type Aliases§

EncodingMask
Mask for the encoding field of a version 2 IDM frame.
IDMFinality
Values of the IDM final field
IDMVersion
Values of the IDM version field