Repository navigation
asn1rt: fix PER encode/decode of permitted-alphabet constraint on non-known-multiplier char strings - #107
Merged
Conversation
…-known-multiplier char strings For character string types that are not known-multiplier types (UTF8String, GeneralString, TeletexString, ...), a permitted-alphabet constraint is not PER-visible (ITU-T X.691 30.6): the value is encoded as an unconstrained length in octets followed by the octets, as if the constraint were absent. _get_char_dyn() however returned the alphabet's bit width (rdyn) even though _clen is None for these types, so __to_per_val() and _from_per() evaluated 'cdyn < self._clen' against None and raised TypeError. Ignore the alphabet constraint when _clen is None. Fixes pycrate-org#104
Member
|
Thanks for the fix and the PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104.
Problem
For character string types that are not known-multiplier types (UTF8String, GeneralString, GraphicString, TeletexString/T61String, VideotexString), a permitted-alphabet (
FROM) constraint is not PER-visible (ITU-T X.691 30.6). Such a value must be encoded as an unconstrained length in octets followed by the octets, exactly as if the constraint were absent.pycrate applied the alphabet anyway:
_get_char_dyn()returned the alphabet's bit width (self._const_alpha.rdyn) even though_clenisNonefor these types, so__to_per_val()and_from_per()evaluatedcdyn < self._clenagainstNoneand raisedTypeError: '<' not supported between instances of 'int' and 'NoneType'. A valid value could neither be encoded nor decoded, in UPER or APER.Fix
Ignore the alphabet constraint in
_get_char_dyn()when_clenisNone(i.e. for non-known-multiplier types), so the value is encoded as raw octets with an unconstrained length, matching the spec and the behaviour of the same type without a constraint:/n/n```diffdef _get_char_dyn(self):
# returns the number of bits required to encode a character
Verification
Added regression types
U8s04 ::= UTF8String (FROM ("013")),Ges01 ::= GeneralString (FROM ("013"))andTes01 ::= TeletexString (FROM ("013"))totest/res/test_asn1rt_mod.asn, plus encode/decode assertions intest_asn1rt.py. All three now round-trip"13"as023133(one length octet02+ octets31 33), identical to an unconstrainedUTF8String.test/test_asn1rt.pyruns green end-to-end (test_rt_base, test_rrc3g, test_lteran, test_nrran, test_tcap_map, test_tcap_cap, test_x509).Related: #42 fixed the SIZE half of the same X.691 30.6 rule for UTF8String; this covers the remaining permitted-alphabet case.