phpseclib/phpseclib — pull request #25 by monnerat (2012-10-18 11:11:17+00:00)
Title: ASN1: Fix default value optimization upon encoding.

Also encode SETs as SEQUENCEs since order is not important.

Hi Jim,
Please try this one: it should fix the extra CONT(0) problem. I already performed some tests successfully, but it's probably good if you perform some additional test from yours before pulling to master.

Regarding the ANY fields type problem: a solution would be to keep a special array field (for example named '') as sibling of the ANY field(s) to hold the effective type of the any fields. As an example, an AttributeTypeAndValue can be represented by
array('type' => some_object_id, 'value' => 'ABC', '' => array('value' => FILE_ASN1_TYPE_PRINTABLE_STRING))
And we'll do it for ANY fields only. Upon encoding, the original type can be recovered from here: the $filters mechanism will be used only if the effective type is not stored in array.

I also appreciate the simplicity of the current type handling, but I think the above solution is preferable to the character conversion solution: this conversion is not easy at all (some weird encoding can be found in some string type) and this is not general enough (an ANY field could be a SEQUENCE for example).