use rustorb_cdr::{ByteOrder, CdrDecode, CdrEncode, Decoder, Encoder, Encoding};
use crate::Result;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TaggedComponent {
pub tag: u32,
pub component_data: Vec<u8>,
}
impl CdrEncode for TaggedComponent {
fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
enc.write_u32(self.tag);
enc.write_octet_seq(&self.component_data)
}
}
impl CdrDecode for TaggedComponent {
fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
Ok(TaggedComponent {
tag: dec.read_u32()?,
component_data: dec.read_octet_seq()?.to_vec(),
})
}
}
impl TaggedComponent {
pub fn encapsulated<F>(tag: u32, order: ByteOrder, f: F) -> Result<TaggedComponent>
where
F: FnOnce(&mut Encoder) -> rustorb_cdr::Result<()>,
{
let mut enc = Encoder::encapsulation(order, Encoding::Giop1_2);
f(&mut enc)?;
Ok(TaggedComponent {
tag,
component_data: enc.into_bytes(),
})
}
pub fn decoder(&self) -> Result<Decoder<'_>> {
Ok(Decoder::encapsulation(
&self.component_data,
Encoding::Giop1_2,
)?)
}
}
pub mod component_tag {
pub const ORB_TYPE: u32 = 0;
pub const CODE_SETS: u32 = 1;
pub const POLICIES: u32 = 2;
pub const ALTERNATE_IIOP_ADDRESS: u32 = 3;
pub const COMPLETE_OBJECT_KEY: u32 = 5;
pub const ENDPOINT_ID_POSITION: u32 = 6;
pub const LOCATION_POLICY: u32 = 12;
pub const ASSOCIATION_OPTIONS: u32 = 13;
pub const SEC_NAME: u32 = 14;
pub const SSL_SEC_TRANS: u32 = 20;
pub const JAVA_CODEBASE: u32 = 25;
pub const CSI_SEC_MECH_LIST: u32 = 33;
pub const NULL_TAG: u32 = 34;
pub const TLS_SEC_TRANS: u32 = 36;
pub const OMNIORB_BIDIR: u32 = 0x4154_5401;
pub const OMNIORB_UNIX_TRANS: u32 = 0x4154_5402;
pub const OMNIORB_PERSISTENT_ID: u32 = 0x4154_5403;
pub const OMNIORB_RESTRICTED_CONNECTION: u32 = 0x4154_5404;
pub const OMNIORB_HTTP_TRANS: u32 = 0x4154_5405;
}
pub mod orb_type {
pub const OMNIORB: u32 = 0x4154_5400;
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CodeSetComponent {
pub native_code_set: u32,
pub conversion_code_sets: Vec<u32>,
}
impl CdrEncode for CodeSetComponent {
fn encode(&self, enc: &mut Encoder) -> rustorb_cdr::Result<()> {
enc.write_u32(self.native_code_set);
self.conversion_code_sets.encode(enc)
}
}
impl CdrDecode for CodeSetComponent {
fn decode(dec: &mut Decoder<'_>) -> rustorb_cdr::Result<Self> {
Ok(CodeSetComponent {
native_code_set: dec.read_u32()?,
conversion_code_sets: Vec::decode(dec)?,
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CodeSetComponentInfo {
pub for_char_data: CodeSetComponent,
pub for_wchar_data: CodeSetComponent,
}
impl CodeSetComponentInfo {
pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
TaggedComponent::encapsulated(component_tag::CODE_SETS, order, |enc| {
self.for_char_data.encode(enc)?;
self.for_wchar_data.encode(enc)
})
}
pub fn from_component(component: &TaggedComponent) -> Result<CodeSetComponentInfo> {
let mut dec = component.decoder()?;
Ok(CodeSetComponentInfo {
for_char_data: CodeSetComponent::decode(&mut dec)?,
for_wchar_data: CodeSetComponent::decode(&mut dec)?,
})
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AlternateIiopAddress {
pub host: String,
pub port: u16,
}
impl AlternateIiopAddress {
pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
TaggedComponent::encapsulated(component_tag::ALTERNATE_IIOP_ADDRESS, order, |enc| {
enc.write_string(&self.host)?;
enc.write_u16(self.port);
Ok(())
})
}
pub fn from_component(component: &TaggedComponent) -> Result<AlternateIiopAddress> {
let mut dec = component.decoder()?;
Ok(AlternateIiopAddress {
host: dec.read_string()?,
port: dec.read_u16()?,
})
}
}
pub mod association_options {
pub const NO_PROTECTION: u16 = 1;
pub const INTEGRITY: u16 = 2;
pub const CONFIDENTIALITY: u16 = 4;
pub const DETECT_REPLAY: u16 = 8;
pub const DETECT_MISORDERING: u16 = 16;
pub const ESTABLISH_TRUST_IN_TARGET: u16 = 32;
pub const ESTABLISH_TRUST_IN_CLIENT: u16 = 64;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SslSecTrans {
pub target_supports: u16,
pub target_requires: u16,
pub port: u16,
}
impl SslSecTrans {
pub fn to_component(&self, order: ByteOrder) -> Result<TaggedComponent> {
TaggedComponent::encapsulated(component_tag::SSL_SEC_TRANS, order, |enc| {
enc.write_u16(self.target_supports);
enc.write_u16(self.target_requires);
enc.write_u16(self.port);
Ok(())
})
}
pub fn from_component(component: &TaggedComponent) -> Result<SslSecTrans> {
let mut dec = component.decoder()?;
Ok(SslSecTrans {
target_supports: dec.read_u16()?,
target_requires: dec.read_u16()?,
port: dec.read_u16()?,
})
}
}
pub fn orb_type_component(orb_type: u32, order: ByteOrder) -> Result<TaggedComponent> {
TaggedComponent::encapsulated(component_tag::ORB_TYPE, order, |enc| {
enc.write_u32(orb_type);
Ok(())
})
}