[erlang-patches] Add specific return for incomplete asn.1 packets
Jeremy Heater
jeremy.heater@REDACTED
Tue Jul 24 17:15:55 CEST 2012
Hello all,
We had already broached the subject a few years back (cf.
http://erlang.org/pipermail/erlang-patches/2009-December/000627.html) and
we modified our approach to take the comments made at the time into
account. Here follows a description of the changes:
This patch's goal is to allow the user to determine if an incoming
asn.1 packet is incomplete.
To that end, the decode/2 functions of generated asn.1 files were
modified so as to return {error, incomplete} when the packet to be
decoded is incomplete instead of the generic
{error, {asn1, {badmatch, _}}} (or badarg) which is not distinguishable
from other errors.
This would seem to us to be a necessary feature so as to be able to
determine if a packet received from a socket is complete (since overly
large messages are split).
It is also complementary to the undec_rest option where when decode/2
is called on a packet containing more than one message, the function
returns the first message decoded and the rest of the packet
undecoded.
The solution was implemented for all encoding rules, even though BER
encoding allows for simpler checking by manually parsing the first
bytes of the packet, for the sake of having a consistent API whatever
the encoding.
The proposed patch can be found at:
git fetch git://github.com/Kwisatx/otp.git incomplete_packet_asn1
https://github.com/Kwisatx/otp/compare/master...incomplete_packet_asn1
https://github.com/Kwisatx/otp/compare/master...incomplete_packet_asn1.patch
Since the added tests inevitably add some overhead, we also tried to
link the changes to the undec_rest option
(incomplete_packet_asn1_duplicate_files branch), but since most of the
changes are in the runtime, it made duplicating the code necessary (as
the name of the branch suggests), which complicates the code.
What are your thoughts on this change? Any ideas for how to improve it?
Best regards,
Jeremy Heater.
More information about the erlang-patches
mailing list