use crate::error::{check, Result};
use crate::ffi;
use crate::ffi_safe::call_for_string;
use crate::ops::{Input, Output};
#[derive(Clone, Copy, Debug, Default)]
pub struct DumpFlags(pub u32);
impl DumpFlags {
pub const MPI: Self = Self(ffi::RNP_DUMP_MPI as u32);
pub const RAW: Self = Self(ffi::RNP_DUMP_RAW as u32);
pub const GRIP: Self = Self(ffi::RNP_DUMP_GRIP as u32);
pub fn bits(self) -> u32 {
self.0
}
}
impl std::ops::BitOr for DumpFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct JsonDumpFlags(pub u32);
impl JsonDumpFlags {
pub const MPI: Self = Self(ffi::RNP_JSON_DUMP_MPI as u32);
pub const RAW: Self = Self(ffi::RNP_JSON_DUMP_RAW as u32);
pub const GRIP: Self = Self(ffi::RNP_JSON_DUMP_GRIP as u32);
pub fn bits(self) -> u32 {
self.0
}
}
impl std::ops::BitOr for JsonDumpFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
#[derive(Clone, Copy, Debug, Default)]
pub struct JsonFlags(pub u32);
impl JsonFlags {
pub const PUBLIC_MPIS: Self = Self(ffi::RNP_JSON_PUBLIC_MPIS as u32);
pub const SECRET_MPIS: Self = Self(ffi::RNP_JSON_SECRET_MPIS as u32);
pub const SIGNATURES: Self = Self(ffi::RNP_JSON_SIGNATURES as u32);
pub const SIGNATURE_MPIS: Self = Self(ffi::RNP_JSON_SIGNATURE_MPIS as u32);
pub fn bits(self) -> u32 {
self.0
}
}
impl std::ops::BitOr for JsonFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
pub fn dump_packets_to_output(
input: &Input,
output: &mut Output,
flags: DumpFlags,
) -> Result<()> {
unsafe { check(ffi::rnp_dump_packets_to_output(input.as_ptr(), output.as_ptr(), flags.bits())) }
}
pub fn dump_packets_to_json(input: &Input, flags: JsonDumpFlags) -> Result<String> {
call_for_string(|out| unsafe {
ffi::rnp_dump_packets_to_json(input.as_ptr(), flags.bits(), out)
})
}
pub fn dump_packets_bytes_to_json(bytes: &[u8], flags: JsonDumpFlags) -> Result<String> {
let input = Input::from_memory(bytes)?;
dump_packets_to_json(&input, flags)
}
#[allow(unused_imports)]
use crate::error as _error_reexport;