Samuel-Tyler / fast_ber

A C++11 ASN.1 BER Encoding and Decoding Library
Boost Software License 1.0
84 stars 11 forks source link

Add support for dynamic encoding #14

Open melg8 opened 4 years ago

melg8 commented 4 years ago

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:

Possible solutions:

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.

Samuel-Tyler commented 4 years ago

Thank you very much!

Really appreciate your feedback.

Problem one sounds relatively easy fix, with the solution being adding functionality to calculate the encoded length ahead of time.

Problem two sounds more complex, and will require some thought.

The thing that would be most helpful to me is more test data. Both ASN.1 schemas and encoded BER data will allow me to improve the parsing and encoding/decoding. If you have any available it would be of great use to me.

Thank you very much, I hope to hear more of your use case to understand good directions for the project.

Sam

Samuel-Tyler commented 4 years ago

Hi I've added functionality to determine encoded length, this is shown in sample code: e9da42413b46afa0d2b500dc98b4a403dfb82cfb

I plan on expanding the DecodeResult and EncodeResult functions to include more information on fail soon.

I don't plan on supporting Problem 2 at the moment. Perhaps once the library is more mature.

melg8 commented 4 years ago

That's really great news! I'll take a look at your example and try to play with it. Solving at least size problem is very helpful. Thanks for your work. If you want you can close that issue than.