mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
94 stars 70 forks source link

PER encoding of INTEGER type is not possible #99

Closed jwpark0921 closed 2 years ago

jwpark0921 commented 2 years ago

hello. I found a problem with encoding/decoding 64 bit integers. The ASN definition is as follows:

Request ::= SEQUENCE { channelId ChannelNumber, timeSlot TimeSlot, dataRate DataRate, transmitPowerLevel TXpower, channelLoad Opaque OPTIONAL, infoElementIndicator WaveElementsIncluded, userPriority UserPriority, expiryTime Time64 }

Time64 ::= INTEGER (0..9223372036854775807)

For testing, I put a value in Time64 as below and performed encoding/decoding for BER, DER, OER, and PER.

asn_uint642INTEGER(&request->expiryTime, UINT64_MAX);

As a result of the test, there is a problem that only PER is not performed. Is there any way to solve this problem?

V2X library Test(ATS_BER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding success.(35bytes) Decoding success.(consumed = 35bytes)

V2X library Test(ATS_DER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding success.(35bytes) Decoding success.(consumed = 35bytes)

V2X library Test(ATS_BASIC_OER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding success.(18bytes) Decoding success.(consumed = 18bytes)

V2X library Test(ATS_CANONICAL_OER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding success.(18bytes) Decoding success.(consumed = 18bytes)

V2X library Test(ATS_UNALIGNED_BASIC_PER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding failed.(Time64) Decoding failed.(consumed = 0bytes)

V2X library Test(ATS_UNALIGNED_CANONICAL_PER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding failed.(Time64) Decoding failed.(consumed = 0bytes)

V2X library Test(ATS_ALIGNED_BASIC_PER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding failed.(Time64) Decoding failed.(consumed = 0bytes)

V2X library Test(ATS_ALIGNED_CANONICAL_PER)

172 6 10 0000001000000000000 3 00:FF:FF:FF:FF:FF:FF:FF:FF

Encoding failed.(Time64) Decoding failed.(consumed = 0bytes)

mouse07410 commented 2 years ago

I've no idea what V2X library is, what it uses underneath, or how it works.

Having said that, let me take a look at how asn1c would encoder and decode this integer.

mouse07410 commented 2 years ago

At this point I can only add that not having a small and self-contained code reproducer (should include ASN.1 file, main C file, XER encoding of the problematic PDU, if available - APER encoding of that PDU) to test this, it would be quite difficult for me to proceed.

mouse07410 commented 2 years ago

I've created an ASN.1 file

REQ DEFINITIONS IMPLICIT TAGS ::=

BEGIN

Time64 ::= INTEGER (0..9223372036854775807)

Req ::= SEQUENCE {
    currentTime Time64,
    expiryTime  Time64
}

END

and wrote a small test-program to encode and decode it in APER, using

rc = asn_uint642INTEGER(&pdu->expiryTime, expTime);

to set the values. It works fine:

APER-encoded buffer (14 bytes):
0x6062d7839be00ccccccccccccccc

APER-decoded buffer, consumed 14 bytes:
<Req>
    <currentTime>1658291099</currentTime>
    <expiryTime>922337203685477580</expiryTime>
</Req>

Please re-open if you have more input.