Closed mbrehler closed 2 years ago
This is related to canonicity of the encoding. In PER, canonical encoding requires default values not to be encoded, which is the default behaviour of the PER codec in pycrate, see: https://github.com/P1sec/pycrate/blob/6b8691bfec1ce16851176260a34920e9952e23d5/pycrate_asn1rt/codecs.py#L51
With JER and JSON more generally being human-readable, there is no such thing as canonical encoding.
In your case, setting ASN1CodecPER.CANONICAL = False
before reencoding with UPER should answer your question.
Thanks. I was more interested in controlling how to_jer() behaves (so that the output is either always with default values or w/o, independent of other calls). Is that possible? Certainly easy enough to work around this by always ensuring a certain call order of from_uper/to_uper/to_jer.
I try to better understand your need. To me, what you are looking for is not exactly related to the transfer syntax (JER, or PER), but more related to the user-side API of the asn.1 runtime. One could add 2 switches in the SEQUENCE / SET parent class:
set_val()
: to set default values into the object (before encoding a message) even if those values are not part of the argument passed to the methodget_val()
: to get default values from the object (after decoding a message) even if those values are not present in the message that has been decodedWould this work for you ?
Thanks & I agree that I look at this more as an API issue: The output of to_jer() changes even though in my mind nothing should have changed in the message. Apparently the call to to_uper() has some side effect that make to_jer() behave differently which is unexpected (and caused us some grief since some regression tests expected consistent output). I do not follow you set_val/get_val proposal: My example doesn't call these.
The call to to_uper()
changes the content of the message because your PER encoder is configured to do canonical encoding. If you just want to change this behavior, so that your PER encoder also encodes DEFAULT values when they are present, try to set ASN1CodecPER.CANONICAL = False
in your code first, and let me know if this solves your issue.
ASN.1 default values are generated as part of JER if the to_jer() is called before to_uper() while they are not generated afterwards, see example code below. I haven't double checked what the spec says about this (I suspect don't include defaults in JER). Either way, consistent behavior for to_jer() is probably what most people would expect. We actually like seeing the default values, so some control over it would be ideal.
One could also argue that the warnings / logs about "removing value equal to the default one" that the code generates are a bit surprising since in the example these values were not set/written.
Thanks, Matthias
Example: Need to compile NR RRC ASN.1 for the xample to work with pycrate_asn1compile.py -i pycrate\pycrate_asn1dir\3GPP_NR_RRC_38331\NR-RRC-Definitions.asn -o pycrate\pycrate_asn1dir\NR_RRC_Definitions