pub fn try_construct_der_seq<F, E>(callback: F) -> Result<Vec<u8>, E>where
    F: FnOnce(&mut DERWriterSeq<'_>) -> Result<(), E>,
Expand description

Tries to construct a DER-encoded sequence of data as Vec<u8>.

Same as construct_der_seq, only that it allows returning an error from the passed closure.

This function uses the loan pattern: callback is called back with a DERWriterSeq, to which the ASN.1 values are written.

Examples

use yasna;
let res_ok = yasna::try_construct_der_seq::<_, ()>(|writer| {
    writer.next().write_i64(10);
    writer.next().write_bool(true);
    Ok(())
});
let res_err = yasna::try_construct_der_seq::<_, &str>(|writer| {
    return Err("some error here");
});
assert_eq!(res_ok, Ok(vec![2, 1, 10, 1, 1, 255]));
assert_eq!(res_err, Err("some error here"));