Patch for ASN1 Library

Aude Quintana <>
Tue Aug 18 11:03:05 CEST 2009

Hello !

Here is a proposition for a patch for Erlang asn1 library.

I hope I didn't reimplement existing functionality, but I didn't manage to
do it another way.

If the functionality is already implemented, thanks to reply me with some
indication on how to proceed using it.

So this patch should be used to catch decoding error when the message to
decode is incomplete and to return the error {error,incomplete} in this
case. The existing behaviour is to throw various hard-to-match errors.

This change is necessary when using APER norm. The APER norm makes
impossible to foresee the message length and so to foresee if the packet to
decode is long enough to contain a full packet. So, when decoding a packet
with error, it is impossible to say if it is because the contained message
is incomplete or other.

With BER encoding it is cheap to read the size of the message, but with PER
you have to decode the whole message first, so an in-library solution is

.diff file attached with the details of my modifications to add the return
of the error {error,incomplete} in case of an incomplete message.

In the following files :
the size of the buffer put in argument should be check each time a function
wants to match a precise number of bytes (related to an expected size of

This means
* to add a check_bit_size(Buffer,BitSize) or a
check_bin_size(Buffer,BinSize) each time we had something like
"<<Bin:5/binary,Rest/binary>> = Buffer",
* and to add pattern functions, for example: for getbit(Bin) we must add
getbit(<<>>) -> throw({error,incomplete}) and not let the system crashed.

Note that check_bit_size/2 et check_bin_size/2 are functions added in each

Eventually, in the generator file asn1ct_gen.erl, just 2 lines in
decode_disp/2 must be added to forward the error {error,incomplete} to the
parent module.

This seems to be enough to implement the error matching, I tried to test
with my data and it works and with bad data, it replies with an error

What do you think about it ?

Best regards,

Aude Quintana
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_lib_asn1.diff
Type: text/x-patch
Size: 35692 bytes
Desc: not available
URL: <>

More information about the erlang-patches mailing list