- status: open --> closed-fixed
- milestone: -->
Compiling the type below and then trying to encode
value6 Type6 ::= element15: 2
as PER gives
dom@heisenberg:~/asn15/asn1/manyTypes> ./per foo.per
Could not encode Type6 (at element12)
but trying to encode it as BER gives
dom@heisenberg:~/asn15/asn1/manyTypes> ./ber foo.per
Created foo.per with BER encoded Type6
<Type6>
<element15>2</element15>
</Type6>
and the BER encoding looks correct. I've attached the PER and BER C
Programs. I'll raise it as a bug.
Type6 ::= CHOICE {
element9 [4] IMPLICIT SEQUENCE {
element10 [5] EXPLICIT CHOICE {
element11 [6] IMPLICIT SEQUENCE {
element12 [7] EXPLICIT CHOICE {
element13 INTEGER
}
},
element14 INTEGER
}
},
element15 INTEGER
}
C for BER Encoding
#include <stdio.h> /* for stdout */
#include <stdlib.h> /* for malloc () */
#include <assert.h> /* for run-time control */
#include <Type6.h> /* Type6 ASN.1 type */
/*
* This is a custom function which writes the
* encoded output into some FILE stream.
*/
static int
write_out(const void *buffer, size_t size, void *app_key) {
FILE *out_fp = app_key;
size_t wrote;
wrote = fwrite(buffer, 1, size, out_fp);
return (wrote == size) ? 0 : -1;
}
int main(int ac, char **av) {
/* Encoder return value */
asn_enc_rval_t ec;
/* Declare a pointer to a Type6 type */
Type6_t *type6;
/* Allocate an instance of Type6 */
type6 = calloc(1, sizeof(Type6_t)); /* not malloc! */
assert(type6); /* Assume infinite memory */
(*type6).present = Type6_PR_element15;
(*type6).choice.element15 = 2;
if(ac < 2) {
fprintf(stderr,"Specify filename for BER output\n");
} else {
const char *filename = av[1];
FILE *fp = fopen(filename,"wb"); /* for BER output */
if(!fp) {
perror(filename);
exit(71); /* better, EX_OSERR */
}
/* Encode Type6 as BER */
ec = der_encode(&asn_DEF_Type6,type6,write_out,fp);
if(ec.encoded == -1) {
fprintf(stderr,"Could not encode Type6 (at %s)\n",
ec.failed_type ? ec.failed_type->name : "unknown");
exit(65); /* better, EX_DATAERR */
} else {
fprintf(stderr,"Created %s with BER encoded Type6\n",filename);
}
fclose(fp);
}
/* Also print the constructed Type6 XER encoded (XML) */
xer_fprint(stdout,&asn_DEF_Type6,type6);
return 0; /* Encoding finished successfully */
}
C for PER Encoding
#include <stdio.h> /* for stdout */
#include <stdlib.h> /* for malloc () */
#include <assert.h> /* for run-time control */
#include <Type6.h> /* Type6 ASN.1 type */
/*
* This is a custom function which writes the
* encoded output into some FILE stream.
*/
static int
write_out(const void *buffer, size_t size, void *app_key) {
FILE *out_fp = app_key;
size_t wrote;
wrote = fwrite(buffer, 1, size, out_fp);
return (wrote == size) ? 0 : -1;
}
int main(int ac, char **av) {
/* Encoder return value */
asn_enc_rval_t ec;
/* Declare a pointer to a Type6 type */
Type6_t *type6;
/* Allocate an instance of Type6 */
type6 = calloc(1, sizeof(Type6_t)); /* not malloc! */
assert(type6); /* Assume infinite memory */
(*type6).present = Type6_PR_element15;
(*type6).choice.element15 = 2;
if(ac < 2) {
/* fprintf(stderr,"Specify filename for PER output\n");*/
fprintf(stderr,"Specify filename for BER output\n");
} else {
const char *filename = av[1];
FILE *fp = fopen(filename,"wb"); /* for PER output */
if(!fp) {
perror(filename);
exit(71); /* better, EX_OSERR */
}
/* Encode Type6 as PER */
ec = uper_encode(&asn_DEF_Type6,type6,write_out,fp);
if(ec.encoded == -1) {
fprintf(stderr,"Could not encode Type6 (at %s)\n",
ec.failed_type ? ec.failed_type->name : "unknown");
exit(65); /* better, EX_DATAERR */
} else {
fprintf(stderr,"Created %s with PER encoded Type6\n",filename);
}
fclose(fp);
}
/* Also print the constructed Type6 XER encoded (XML) */
xer_fprint(stdout,&asn_DEF_Type6,type6);
return 0; /* Encoding finished successfully */
}