Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PER-encoding issue: Semi-constrained integer encoding is incorrectly working #140

Open
andpopov opened this issue Jan 14, 2022 · 1 comment

Comments

@andpopov
Copy link

andpopov commented Jan 14, 2022

Hi,

I seem that semi-constrained integer PER-encoding is working incorrectly:

asn.1 description is:
HelloWorld DEFINITIONS ::= BEGIN
Message ::= SEQUENCE {
n1 INTEGER(5..MAX)
}
END

Input is: {'n1': 8}

Encoding result is: 0x0108

But expected value is: 0x0103

I understand that value should be encoded as: (8 - 5)
It means: (value - lower boundary)

Code snipped is here:

from future import print_function
from binascii import hexlify
import asn1tools

SPECIFICATION = '''
HelloWorld DEFINITIONS ::= BEGIN
Message ::= SEQUENCE {
n1 INTEGER(5..MAX)
}
END'''

hello_world = asn1tools.compile_string(SPECIFICATION, 'per')

message = {'n1': 8}
encoded = hello_world.encode('Message', message)
decoded = hello_world.decode('Message', encoded)

print('Encoded:', hexlify(encoded).decode('ascii'))

@andpopov andpopov changed the title emi-constrained integer encoding is incorrectly works Semi-constrained integer encoding is incorrectly working Jan 14, 2022
@andpopov andpopov changed the title Semi-constrained integer encoding is incorrectly working PER-encoding issue: Semi-constrained integer encoding is incorrectly working Jan 14, 2022
@eerimoq
Copy link
Owner

eerimoq commented Jan 14, 2022

Ok, thanks for the report. I'll not likely fix it myself. Feel free to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants