DEFAULT values are not omitted in DER encoding.
I'm trying to encode the eUICC profile package to DER using asn1c. Despite passing in the DEFAULT values, they still appear in the DER TLV hex values.
As an example, I tested the Rocket example mentioned https://asn1.io/asn1playground/Default.aspx with asn1c, but still the hex TLV of the default "Hello World" message was in the DER output.
ASN.1 module:
--<ASN1.HugeInteger World-Schema.Rocket.range>--
World-Schema DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Rocket ::= SEQUENCE
{
range INTEGER, -- huge (see a special directive above)
name UTF8String (SIZE(1..16)),
message UTF8String DEFAULT "Hello World" ,
fuel ENUMERATED {solid, liquid, gas},
speed CHOICE
{
mph INTEGER,
kmph INTEGER
} OPTIONAL,
payload SEQUENCE OF UTF8String
}
END
The rocket: value Rocket ::= { range 340282366920938463463374607431768211455, name "Falcon", message "Hello World", fuel solid, speed mph : 18000, payload { "Car", "GPS" } }
Below is what I've got from the ./converter-example. "820b48656c6c6f20576f726c64" is the "Hello World", which is the default value and shouldn't be present in the DER encoded values.
`./converter-example -p Rocket -ixer sample.xml -oder > s.der
open('s.der','rb').read().hex(): "302d800101810646616c636f6e 820b48656c6c6f20576f726c64 830100a40480024650a50a0c034361720c03475053" ` PS. I have also tried with "-fcompound-names", "-fwide-types", and "-funnamed-unions".
Hi @farhadh,
which is the default value and shouldn't be present in the DER encoded values.
Can you cite the specification?
Hi @velichkov! :) It is according to X.690 : Information technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER) https://www.itu.int/rec/T-REC-X.690-201508-I/en, section 11.5:
11.5 Set and sequence components with default value: The encoding of a set value or sequence value shall not include an encoding for any component value which is equal to its default value.
Hi!
I just realized that all DEFAULT values are omitted except string ones like STRING, UTF8String, OCTET STRING, etc.
When I change the message type from UTF8STtring to INTEGER and set the value to 1, the value got omitted in the DER output hex values and the part below got added to the Rocket.c file.
static int asn_DFL_4_cmp_1(const void *sptr) {
const long *st = sptr;
if(!st) {
return -1; /* No value is not a default value */
}
/* Test default value 1 */
return (*st != 1);
}
static int asn_DFL_4_set_1(void **sptr) {
long *st = *sptr;
if(!st) {
st = (*sptr = CALLOC(1, sizeof(*st)));
if(!st) return -1;
}
/* Install default value 1 */
*st = 1;
return 0;
}
...
{ ATF_POINTER, 1, offsetof(struct Rocket, message),
(ASN_TAG_CLASS_CONTEXT | (2 << 2)),
-1, /* IMPLICIT tag at current level */
&asn_DEF_NativeInteger,
0,
{ 0, 0, 0 },
&asn_DFL_4_cmp_1, /* Compare DEFAULT 1 */
&asn_DFL_4_set_1, /* Set DEFAULT 1 */
"message"
}, ```
New discovery!
It turned out that the DEFAULT value doesn’t get emitted for OCTET STRING and the code for comparing and setting doesn’t appear on its .c file like the other parameters.
Some help for figuring this out would be appropriated a lot.
Hi! @vlm,
Would you please take a look at this issue/bug and guide me on how I can make it work with OCTET STRING DEFAULT values as well?
PS I have also posted it here.