-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Introduction
In current version (master/devel) of library we have fast_ber::encode function, which ber encodes provided asn.1 structure inside provided absl::Span continuous storage. Usage example and tests use std::array or std::vector as storage provider for creation absl::Span. Size of storage varies from test to test in values from 100 to 5000 or even 10000 in some cases.
Problem 1: minimal memory allocation
User can't allocate minimum amount of memory needed to successfully encode provided asn.1 structure. If Pokemon team takes exactly 125 bytes to encode - there is no way to know that before fast_ber::encode call or after bad call, because, as i can see encode_result.length returns 125 only at succsess case (with storage size > 125) and 0 on faliure.
Possible solutions:
- return minimal needed value at "too small buffer provided" type of failure (this approach takes GNU libtasn1 take a look at asn1_der_coding)
- provide separate function which calculates needed size without attempting to encode structure
Problem 2: limited available memory (less than full encoded binary)
If user have limited memory or want to send encoded structure asap to some external device or to some stream, without accumulating full binary representation in memory on encoding side - there is no way to do that using current fast_ber::encode function.
Possible solutions:
- provide callback function which is called on each PDU. (this approach takes asn1c look for der_encode wich have argument
asn_app_consume_bytes_f *consume_bytes_cb
with description) - more general approach to use pair of iterators or, better, single range to be used for encoding instead of hard wired absl::Span.
P.s. I'm really interested in your library to become viable alternative to asn1c in cpp world of ber/der encoding, but i have too little time/discipline/knowledge to code it myself, on the other hand, if you interested, i can sometimes provide issues which i think are important. Anyway great job and thanks for inspiration.