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

Incorrect code generated for choice sequence? #56

Closed
bklop opened this issue Nov 23, 2023 · 2 comments
Closed

Incorrect code generated for choice sequence? #56

bklop opened this issue Nov 23, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@bklop
Copy link

bklop commented Nov 23, 2023

In case of a choice sequence (for example in din_PGPDataType), the generated encoding code looks wrong/weird.

For example. in encode_din_PGPDataType we find this:

            // Grammar: ID=81; read/write bits=2; START (PGPKeyID), START (PGPKeyPacket)
            if (PGPDataType->choice_1_isUsed == 1u)
            {
                error = exi_basetypes_encoder_nbit_uint(stream, 2, 0);
                if (error == EXI_ERROR__NO_ERROR)
                {
                    // Event: START (PGPKeyID, base64Binary); next=82
                    error = exi_basetypes_encoder_nbit_uint(stream, 1, 0);
                    if (error == EXI_ERROR__NO_ERROR)
                    {
                        error = exi_basetypes_encoder_uint_16(stream, (uint16_t)PGPDataType->choice_1.PGPKeyID.bytesLen);
                        if (error == EXI_ERROR__NO_ERROR)
                        {
                            error = exi_basetypes_encoder_bytes(stream, PGPDataType->choice_1.PGPKeyID.bytesLen, PGPDataType->choice_1.PGPKeyID.bytes, din_base64Binary_BYTES_SIZE);
                            if (error == EXI_ERROR__NO_ERROR)
                            {
                                // encode END Element
                                error = exi_basetypes_encoder_nbit_uint(stream, 1, 0);
                                if (error == EXI_ERROR__NO_ERROR)
                                {
                                    grammar_id = 82;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                error = exi_basetypes_encoder_nbit_uint(stream, 2, 1);
                if (error == EXI_ERROR__NO_ERROR)
                {
                    // Event: START (PGPKeyPacket, base64Binary); next=83
                    error = exi_basetypes_encoder_nbit_uint(stream, 1, 0);
                    if (error == EXI_ERROR__NO_ERROR)
                    {
                        error = exi_basetypes_encoder_uint_16(stream, (uint16_t)PGPDataType->choice_1.PGPKeyPacket.bytesLen);
                        if (error == EXI_ERROR__NO_ERROR)
                        {
                            error = exi_basetypes_encoder_bytes(stream, PGPDataType->choice_1.PGPKeyPacket.bytesLen, PGPDataType->choice_1.PGPKeyPacket.bytes, din_base64Binary_BYTES_SIZE);
                            if (error == EXI_ERROR__NO_ERROR)
                            {
                                // encode END Element
                                error = exi_basetypes_encoder_nbit_uint(stream, 1, 0);
                                if (error == EXI_ERROR__NO_ERROR)
                                {
                                    grammar_id = 83;
                                }
                            }
                        }
                    }
                }
            }
            break;

So if choice_1 is not used (i.e. choice_1_isUsed is 0), we still access choice_1.PGPKeyPacket in the else case.

@barsnick
Copy link
Contributor

Hi @bklop,
we are aware that there are coding issues with choice sequences. These are somewhat special and require special handling.

Yet according to the requirements [V2G2-771] (ISO 15118-2) and [V2G20-771] (ISO 15118-20) ("The following message elements of the XML Signature framework shall not be used"), the KeyInfo element is not to be used. The only choice sequences occur in PGPData, which is an element in KeyInfo. (And in DIN 70121, messages and their elements are not signed.)

As long as there is no actual use for choice sequences, and the generated code compiles correctly, we see no need to implement them correctly.

@bklop
Copy link
Author

bklop commented Dec 8, 2023

Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants