Skip to content

Commit

Permalink
Module name of referenced types is incorrect (#88)
Browse files Browse the repository at this point in the history
* Changed module name lookup in compile_type: Now the module name of the referenced type is used instead of the name of the referencing type
  • Loading branch information
Futsch1 committed Aug 3, 2020
1 parent ae9a7d2 commit 5386008
Show file tree
Hide file tree
Showing 17 changed files with 575 additions and 14 deletions.
2 changes: 1 addition & 1 deletion asn1tools/codecs/ber.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ def compile_implicit_type(self, name, type_descriptor, module_name):
return compiled

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
compiled = self.compile_implicit_type(name,
type_descriptor,
module_name)
Expand Down
9 changes: 9 additions & 0 deletions asn1tools/codecs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,15 @@ def is_explicit_tag(self, type_descriptor):

return False

def get_module_name(self, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
try:
_, module_name = self.lookup_type_descriptor(type_descriptor['type'],
module_name)
except CompileError:
pass
return module_name

def lookup_in_modules(self, section, debug_string, name, module_name):
begin_debug_string = debug_string[:1].upper() + debug_string[1:]
module = self._specification[module_name]
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/gser.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(type_name, compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/jer.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/oer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/per.py
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/uper.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
2 changes: 1 addition & 1 deletion asn1tools/codecs/xer.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def process_type(self, type_name, type_descriptor, module_name):
return CompiledType(compiled_type)

def compile_type(self, name, type_descriptor, module_name):
module_name = type_descriptor.get('module-name', module_name)
module_name = self.get_module_name(type_descriptor, module_name)
type_name = type_descriptor['type']

if type_name == 'SEQUENCE':
Expand Down
14 changes: 14 additions & 0 deletions tests/files/c_source/c_source.asn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CSource DEFINITIONS AUTOMATIC TAGS ::=

BEGIN

IMPORTS REFERENCED-TYPE FROM CRef;

A ::= SEQUENCE {
a INTEGER (-128..127),
b INTEGER (-32768..32767),
Expand Down Expand Up @@ -485,4 +487,16 @@ AO ::= SEQUENCE {
d BIT STRING { a(1), b(2), c(31) } (SIZE(32))
}

AP ::= SEQUENCE {
b REFERENCED-TYPE
}

END

CRef DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

REFERENCED-TYPE ::= SEQUENCE {
a INTEGER (0..127)
}
END
82 changes: 81 additions & 1 deletion tests/files/c_source/oer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

/**
* This file was generated by asn1tools version 0.152.0 Wed Jul 15 13:11:15 2020.
* This file was generated by asn1tools version 0.152.0 Sun Aug 2 11:52:02 2020.
*/

#include <string.h>
Expand Down Expand Up @@ -4544,6 +4544,34 @@ static void oer_c_source_ao_decode_inner(
dst_p->d = (uint32_t)decoder_read_int(decoder_p, 4);
}

static void oer_c_ref_referenced_type_encode_inner(
struct encoder_t *encoder_p,
const struct oer_c_ref_referenced_type_t *src_p)
{
encoder_append_uint8(encoder_p, src_p->a);
}

static void oer_c_ref_referenced_type_decode_inner(
struct decoder_t *decoder_p,
struct oer_c_ref_referenced_type_t *dst_p)
{
dst_p->a = decoder_read_uint8(decoder_p);
}

static void oer_c_source_ap_encode_inner(
struct encoder_t *encoder_p,
const struct oer_c_source_ap_t *src_p)
{
oer_c_ref_referenced_type_encode_inner(encoder_p, &src_p->b);
}

static void oer_c_source_ap_decode_inner(
struct decoder_t *decoder_p,
struct oer_c_source_ap_t *dst_p)
{
oer_c_ref_referenced_type_decode_inner(decoder_p, &dst_p->b);
}

static void oer_c_source_b_encode_inner(
struct encoder_t *encoder_p,
const struct oer_c_source_b_t *src_p)
Expand Down Expand Up @@ -5856,6 +5884,58 @@ ssize_t oer_c_source_ao_decode(
return (decoder_get_result(&decoder));
}

ssize_t oer_c_ref_referenced_type_encode(
uint8_t *dst_p,
size_t size,
const struct oer_c_ref_referenced_type_t *src_p)
{
struct encoder_t encoder;

encoder_init(&encoder, dst_p, size);
oer_c_ref_referenced_type_encode_inner(&encoder, src_p);

return (encoder_get_result(&encoder));
}

ssize_t oer_c_ref_referenced_type_decode(
struct oer_c_ref_referenced_type_t *dst_p,
const uint8_t *src_p,
size_t size)
{
struct decoder_t decoder;

decoder_init(&decoder, src_p, size);
oer_c_ref_referenced_type_decode_inner(&decoder, dst_p);

return (decoder_get_result(&decoder));
}

ssize_t oer_c_source_ap_encode(
uint8_t *dst_p,
size_t size,
const struct oer_c_source_ap_t *src_p)
{
struct encoder_t encoder;

encoder_init(&encoder, dst_p, size);
oer_c_source_ap_encode_inner(&encoder, src_p);

return (encoder_get_result(&encoder));
}

ssize_t oer_c_source_ap_decode(
struct oer_c_source_ap_t *dst_p,
const uint8_t *src_p,
size_t size)
{
struct decoder_t decoder;

decoder_init(&decoder, src_p, size);
oer_c_source_ap_decode_inner(&decoder, dst_p);

return (decoder_get_result(&decoder));
}

ssize_t oer_c_source_b_encode(
uint8_t *dst_p,
size_t size,
Expand Down
72 changes: 71 additions & 1 deletion tests/files/c_source/oer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

/**
* This file was generated by asn1tools version 0.152.0 Wed Jul 15 12:49:00 2020.
* This file was generated by asn1tools version 0.152.0 Sun Aug 2 11:52:02 2020.
*/

#ifndef OER_H
Expand Down Expand Up @@ -868,6 +868,20 @@ struct oer_c_source_ao_t {
uint32_t d;
};

/**
* Type REFERENCED-TYPE in module CRef.
*/
struct oer_c_ref_referenced_type_t {
uint8_t a;
};

/**
* Type AP in module CSource.
*/
struct oer_c_source_ap_t {
struct oer_c_ref_referenced_type_t b;
};

/**
* Type B in module CSource.
*/
Expand Down Expand Up @@ -1643,6 +1657,62 @@ ssize_t oer_c_source_ao_decode(
const uint8_t *src_p,
size_t size);

/**
* Encode type REFERENCED-TYPE defined in module CRef.
*
* @param[out] dst_p Buffer to encode into.
* @param[in] size Size of dst_p.
* @param[in] src_p Data to encode.
*
* @return Encoded data length or negative error code.
*/
ssize_t oer_c_ref_referenced_type_encode(
uint8_t *dst_p,
size_t size,
const struct oer_c_ref_referenced_type_t *src_p);

/**
* Decode type REFERENCED-TYPE defined in module CRef.
*
* @param[out] dst_p Decoded data.
* @param[in] src_p Data to decode.
* @param[in] size Size of src_p.
*
* @return Number of bytes decoded or negative error code.
*/
ssize_t oer_c_ref_referenced_type_decode(
struct oer_c_ref_referenced_type_t *dst_p,
const uint8_t *src_p,
size_t size);

/**
* Encode type AP defined in module CSource.
*
* @param[out] dst_p Buffer to encode into.
* @param[in] size Size of dst_p.
* @param[in] src_p Data to encode.
*
* @return Encoded data length or negative error code.
*/
ssize_t oer_c_source_ap_encode(
uint8_t *dst_p,
size_t size,
const struct oer_c_source_ap_t *src_p);

/**
* Decode type AP defined in module CSource.
*
* @param[out] dst_p Decoded data.
* @param[in] src_p Data to decode.
* @param[in] size Size of src_p.
*
* @return Number of bytes decoded or negative error code.
*/
ssize_t oer_c_source_ap_decode(
struct oer_c_source_ap_t *dst_p,
const uint8_t *src_p,
size_t size);

/**
* Encode type B defined in module CSource.
*
Expand Down
Loading

0 comments on commit 5386008

Please sign in to comment.