pub struct Codegen<'a> { /* private fields */ }
Expand description
ASN1 code generator.
Implementations§
source§impl Codegen<'_>
impl Codegen<'_>
sourcepub fn generate(
buf_name: &str,
buf_size_name: &str,
indent: &str,
indent_lvl: usize,
constants: &mut ConstantPool,
variable_info: &dyn Fn(&str) -> Result<VariableInfo>,
gen: impl FnOnce(&mut Codegen<'_>) -> Result<()>
) -> Result<(String, usize)>
pub fn generate( buf_name: &str, buf_size_name: &str, indent: &str, indent_lvl: usize, constants: &mut ConstantPool, variable_info: &dyn Fn(&str) -> Result<VariableInfo>, gen: impl FnOnce(&mut Codegen<'_>) -> Result<()> ) -> Result<(String, usize)>
Generate code that corresponds to an ASN1 document described by a closure acting on a Builder. Returns the generated code and the maximum possible size of the output.
Arguments
buf_name
- Name of the variable holding the pointer to the output buffer.buf_size_name
- Name of the variable holding the size of the output buffer. This variable is updated by the code to hold the actual size of the data after production.indent
- Identation string (one level).indent_lvl
- Initial identation level.constants
- Constant pool used to create necessary constants for the code.variables
- Description of the variable types used when producing the output.gen
- Closure generating the ASN1 document.
Trait Implementations§
source§impl Builder for Codegen<'_>
impl Builder for Codegen<'_>
source§fn push_byte(&mut self, val: u8) -> Result<()>
fn push_byte(&mut self, val: u8) -> Result<()>
Push a byte into the ASN1 output, the value can be any C expression.
source§fn push_boolean(&mut self, tag: &Tag, val: &Value<bool>) -> Result<()>
fn push_boolean(&mut self, tag: &Tag, val: &Value<bool>) -> Result<()>
Push a tagged boolean into the ASN1 output.
source§fn push_integer(
&mut self,
name_hint: Option<String>,
tag: &Tag,
val: &Value<BigUint>
) -> Result<()>
fn push_integer( &mut self, name_hint: Option<String>, tag: &Tag, val: &Value<BigUint> ) -> Result<()>
Push a tagged integer into the ASN1 output, the buffer (a big-endian integer) and its size are arbitrary C expressions.
source§fn push_integer_pad(
&mut self,
name_hint: Option<String>,
val: &Value<BigUint>,
size: usize
) -> Result<()>
fn push_integer_pad( &mut self, name_hint: Option<String>, val: &Value<BigUint>, size: usize ) -> Result<()>
Push a byte array into the ASN1 output, represeting an integer. If the provided buffer is too small, it will be padded with zeroes. Note that this function does not add a tag to the ASN1 output.
source§fn push_byte_array(
&mut self,
name_hint: Option<String>,
val: &Value<Vec<u8>>
) -> Result<()>
fn push_byte_array( &mut self, name_hint: Option<String>, val: &Value<Vec<u8>> ) -> Result<()>
Push a byte array of fixed length into the ASN1 output. Note that this function does not add a tag to the ASN1 output.
source§fn push_string(
&mut self,
_name_hint: Option<String>,
str_type: &Tag,
val: &Value<String>
) -> Result<()>
fn push_string( &mut self, _name_hint: Option<String>, str_type: &Tag, val: &Value<String> ) -> Result<()>
Push an optionally tagged string into the ASN1 output.
fn push_bitstring<'a>( &mut self, name_hint: Option<String>, tag: &Tag, bits: &[Value<bool>] ) -> Result<()>
source§fn push_oid(&mut self, oid: &Oid) -> Result<()>
fn push_oid(&mut self, oid: &Oid) -> Result<()>
source§fn push_tag(
&mut self,
name_hint: Option<String>,
tag: &Tag,
gen: impl FnOnce(&mut Self) -> Result<()>
) -> Result<()>
fn push_tag( &mut self, name_hint: Option<String>, tag: &Tag, gen: impl FnOnce(&mut Self) -> Result<()> ) -> Result<()>
source§fn push_octet_string(
&mut self,
name_hint: Option<String>,
gen: impl FnOnce(&mut Self) -> Result<()>
) -> Result<()>
fn push_octet_string( &mut self, name_hint: Option<String>, gen: impl FnOnce(&mut Self) -> Result<()> ) -> Result<()>
source§fn push_seq(
&mut self,
name_hint: Option<String>,
gen: impl FnOnce(&mut Self) -> Result<()>
) -> Result<()>
fn push_seq( &mut self, name_hint: Option<String>, gen: impl FnOnce(&mut Self) -> Result<()> ) -> Result<()>
source§fn push_set(
&mut self,
name_hint: Option<String>,
gen: impl FnOnce(&mut Self) -> Result<()>
) -> Result<()>
fn push_set( &mut self, name_hint: Option<String>, gen: impl FnOnce(&mut Self) -> Result<()> ) -> Result<()>
source§fn push_as_bit_string(
&mut self,
name_hint: Option<String>,
tag: &Tag,
unused_bits: usize,
gen: impl FnOnce(&mut Self) -> Result<()>
) -> Result<()>
fn push_as_bit_string( &mut self, name_hint: Option<String>, tag: &Tag, unused_bits: usize, gen: impl FnOnce(&mut Self) -> Result<()> ) -> Result<()>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Codegen<'a>
impl<'a> !Send for Codegen<'a>
impl<'a> !Sync for Codegen<'a>
impl<'a> Unpin for Codegen<'a>
impl<'a> !UnwindSafe for Codegen<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>where
F: FnOnce(&Self) -> bool,
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>where F: FnOnce(&Self) -> bool,
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more