Sorting SET OF encodings in aligned & canonical PER
According to the ASN.1 PER standard, the elements of SET OFs are supposed to be sorted based on their PER encodings:
"22.1 For CANONICAL-PER the encoding of the component values of the set-of type shall appear in ascending order, the component encodings being compared as bit strings padded at their trailing ends with as many as seven 0 bits to an octet boundary, and with 0-octets added to the shorter one if necessary to make the length equal to that of the longer one. NOTE – Any pad bits or pad octets added for the sort do not appear in the actual encoding.
22.2 For BASIC-PER the set-of shall be encoded as if it had been declared a sequence-of type."
The current sorting mechanism in TITAN's PER codec works fine in unaligned PER, and in aligned PER, if the first SET OF element starts at an octet boundary. However, there are issues, if the elements don't start at an octet boundary, and the elements contain octet-alignments.
Currently the sorting mechanism is used for all SET OFs in runtime1, and all SET OFs and all SEQUENCE OFs in runtime2 (in both cases the elements' encodings are only sorted if it's a SET OF in canonical PER, but their elements are encoded in separate buffers that start at an octet boundary, to prepare them for sorting).
/cc @aknappqwt @mmagyari