Skip to main content

ParamBuilder

Struct ParamBuilder 

Source
pub struct ParamBuilder<'a> { /* private fields */ }
Expand description

Builder for OSSL_PARAM arrays.

use native_ossl::params::ParamBuilder;

let params = ParamBuilder::new()
    .push_int(c"key_bits", 2048)?
    .push_utf8_ptr(c"pad-mode", c"oaep")?
    .build()?;

Implementations§

Source§

impl<'a> ParamBuilder<'a>

Source

pub fn new() -> Result<Self, ErrorStack>

Create a new empty builder.

§Errors

Returns Err if OpenSSL cannot allocate the builder.

Source

pub fn push_int(self, key: &CStr, val: i32) -> Result<Self, ErrorStack>

Push a signed integer parameter.

§Errors

Returns Err if the push fails (allocation error or key too long).

Source

pub fn push_uint(self, key: &CStr, val: u32) -> Result<Self, ErrorStack>

Push an unsigned integer parameter.

§Errors
Source

pub fn push_uint64(self, key: &CStr, val: u64) -> Result<Self, ErrorStack>

Push a 64-bit unsigned integer parameter.

Used for parameters such as the scrypt N cost factor.

§Errors
Source

pub fn push_size(self, key: &CStr, val: usize) -> Result<Self, ErrorStack>

Push a size_t parameter.

§Errors
Source

pub fn push_octet_slice( self, key: &CStr, val: &[u8], ) -> Result<Self, ErrorStack>

Push an octet-string parameter — copies val into the param array.

Use this when val may be dropped before the resulting Params is consumed. If val is guaranteed to outlive Params, prefer push_octet_ptr.

§Errors
Source

pub fn push_octet_ptr<'b>( self, key: &CStr, val: &'b [u8], ) -> Result<ParamBuilder<'b>, ErrorStack>
where 'a: 'b,

Push an octet-string parameter — stores a pointer into val.

Zero-copy: no allocation occurs. The lifetime 'b of val must be at least 'a to prevent the reference from being invalidated before the Params array is consumed.

§Errors
Source

pub fn push_utf8_string( self, key: &CStr, val: &CStr, ) -> Result<Self, ErrorStack>

Push a UTF-8 string parameter — copies val into the param array.

§Errors
Source

pub fn push_utf8_ptr( self, key: &CStr, val: &'static CStr, ) -> Result<Self, ErrorStack>

Push a UTF-8 string parameter — stores a pointer into val.

Zero-copy: no allocation occurs. Use only for 'static literals such as algorithm names (c"oaep", c"SHA-256").

§Errors
Source

pub fn push_bn( self, key: &CStr, bigendian_bytes: &[u8], ) -> Result<Self, ErrorStack>

Push a BIGNUM parameter from big-endian bytes.

Converts bigendian_bytes to an OpenSSL BIGNUM and pushes it into the builder. The BIGNUM is copied into the builder’s internal storage so the caller’s slice is not referenced after this call returns.

§Errors

Returns Err if the allocation fails or the push fails.

Source

pub fn build(self) -> Result<Params<'a>, ErrorStack>

Finalise the builder and return the Params array.

Consumes the builder. The returned Params must outlive any borrowed slices stored via push_octet_ptr.

§Errors

Returns Err if OSSL_PARAM_BLD_to_param fails.

Trait Implementations§

Source§

impl Drop for ParamBuilder<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ParamBuilder<'a>

§

impl<'a> RefUnwindSafe for ParamBuilder<'a>

§

impl<'a> !Send for ParamBuilder<'a>

§

impl<'a> !Sync for ParamBuilder<'a>

§

impl<'a> Unpin for ParamBuilder<'a>

§

impl<'a> UnsafeUnpin for ParamBuilder<'a>

§

impl<'a> UnwindSafe for ParamBuilder<'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, 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.