-
Notifications
You must be signed in to change notification settings - Fork 45
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
types: Fixes #146, VisibleString character set #147
Conversation
Seems like Edit: Also the whole set in |
I modified the VisibleString output values but there might be other data race condition similar to this issue: ferrilab/bitvec#229 When running failures:
---- uper::tests::extension_additions stdout ----
thread 'uper::tests::extension_additions' panicked at 'assertion failed: `(left == right)`
Diff < left / right > :
[
199,
< 93,
< 57,
< 17,
< 105,
< 82,
< 178,
> 91,
> 53,
> 9,
> 89,
> 50,
> 114,
7,
1,
128,
5,
150,
< 154,
< 19,
< 233,
< 84,
> 150,
> 11,
> 217,
> 52,
]
', src/uper.rs:785:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
uper::tests::extension_additions
test result: FAILED. 76 passed; 1 failed; 2 ignored; 0 measured; 0 filtered out; finished in 2.62s But alone it succeeds Finished test [unoptimized + debuginfo] target(s) in 0.05s
Running unittests src/lib.rs (target/debug/deps/rasn-8b41135ae5a97fd6)
running 1 test
test uper::tests::extension_additions ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 78 filtered out; finished in 0.13s |
Both the width and the order are used in UPER.
Hmm, are you sure these are correct? These are adapted from tests in other ASN.1 projects, so I would expect that those values are the correct ones, and not the new values. |
I do not know about UPER codec so it might be very time consuming to verify the code. But I can check if they use similar character sets for VisibleString encoding. |
@Nicceboy Yeah I would look at packages like |
Seems like asn1rs uses similar set: pub const VISIBLE_STRING_CHARACTERS: &'static str =
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; Also asn1tools: VISIBLE_STRING = ''.join([chr(v) for v in range(32, 127)]) # 0x20, 0x7f, end value not inclusive |
@Nicceboy There must be something different though because their test is the same as the |
Yeah, I tried it manually and new values are different indeed when compared to asn1tools output. But since the character set changed, these values are also expected to change, since codec depends on it, so how can they be same with different character sets? I am trying to see if asn1tools respects those character sets and maybe also test some other tool. |
I would assume that the new character list is correct, but codecs use them differently, and the asn1tools output is correct. Also asn1.io seems to produce same output. If we look at the same asn1tools test file, there is also test for It uses the same character list as the "old" one here, #L1123-L1126. ('D',
'HejHoppHappHippAbcde',
b'\x03\x23\x2e\xa9\x1b\xf8\x70\x91\x87\x87\x09\x1a\x78\x70\x83\x8b'
b'\x1e\x4c\xa0'), The output is same for smaller VisibleString character list, #L1175-L1177 : ('A',
'HejHoppHappHippAbcde',
b'\x03\x23\x2e\xa9\x1b\xf8\x70\x91\x87\x87\x09\x1a\x78\x70\x83\x8b'
b'\x1e\x4c\xa0'), So this change should not actually change the output, if we trust these outputs. But finding the difference in UPER implementation might be a bit too time consuming for me right now. |
2bfe5fa
to
ceba49d
Compare
I compared asn1tools and The main issue might be on using indexes when they should not be. This has gone unnoticed, because Tests are also missing for If you add similar test from asn1tools for PrintableString, it fails: #[test]
fn printable_string() {
round_trip_with_constraints!(
uper,
PrintableString,
Constraints::new(&[Constraint::Size(Size::new(Bounded::Single(16)).into())]),
PrintableString::from_bytes("0123456789abcdef".as_bytes()).unwrap(),
&[0x60, 0xc5, 0x93, 0x36, 0x8d, 0x5b, 0x37, 0x70, 0xe7, 0x0e, 0x2c, 0x79, 0x32, 0xe6]
);
} NumericString type is encoded correctly, because the allowed character list is so short, that is is expected to be encoded by using indexes. You can see the difference also in asn1tools encode/decode mapping generation: class NumericString(KnownMultiplierStringType):
ALPHABET = bytearray(NUMERIC_STRING.encode('ascii'))
ENCODE_MAP = {v: i for i, v in enumerate(ALPHABET)}
DECODE_MAP = {i: v for i, v in enumerate(ALPHABET)}
PERMITTED_ALPHABET = PermittedAlphabet(ENCODE_MAP,
DECODE_MAP)
class PrintableString(KnownMultiplierStringType):
ALPHABET = bytearray(PRINTABLE_STRING.encode('ascii'))
ENCODE_MAP = {v: v for v in ALPHABET}
DECODE_MAP = {v: v for v in ALPHABET}
PERMITTED_ALPHABET = PermittedAlphabet(ENCODE_MAP,
DECODE_MAP)
class IA5String(KnownMultiplierStringType):
ALPHABET = bytearray(IA5_STRING.encode('ascii'))
ENCODE_DECODE_MAP = {v: v for v in ALPHABET}
PERMITTED_ALPHABET = PermittedAlphabet(ENCODE_DECODE_MAP,
ENCODE_DECODE_MAP) |
@Nicceboy Can we make an issue for fixing that? Just so I don't forget about it. |
I can try to debug it again since I know a bit more PER now. If I can't figure it out, I will create issue. |
@Nicceboy Nice, thank you again for all your contributions to rasn! ❤️ |
ceba49d
to
5c23752
Compare
@XAMPPRocky I think this can be reviewed now. The issue was on not checking whether alphabet list should be indexed or not. By default, both types and constraints were always indexed, but based on the standard, it depends on the highest value in that alphabet group. There are also tests for |
Thank you for your PR! |
Resolves #146
There is standard compliant character set.
However, there is weird side-effect on UPER tests, and some will fail.
Is the codec somehow using the allowed character list as part of codec?
I could not figure out the reason yet.
For reference, array was generated with following to be correct:
python -c 'print("[{}]".format(", ".join("0x{:02X}".format(i) for i in range(0x20, 0x7F))))'