Commit 71b96b59 authored by v0-e's avatar v0-e

copy: Implementation for all types

parent 648f0bc3
......@@ -866,6 +866,15 @@ OCTET_STRING_compare(const asn_TYPE_descriptor_t *td, const void *a,
return 0;
}
int
OCTET_STRING_copy(const asn_TYPE_descriptor_t *td, void **a,
const void *b) {
(void)td;
(void)a;
(void)b;
return 0;
}
intmax_t
asn_random_between(intmax_t a, intmax_t b) {
(void)b;
......
......@@ -18,6 +18,7 @@ asn_TYPE_operation_t asn_OP_ANY = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber,
OCTET_STRING_encode_der,
......
......@@ -29,6 +29,7 @@ extern asn_OCTET_STRING_specifics_t asn_SPC_ANY_specs;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define ANY_compare OCTET_STRING_compare
#define ANY_copy OCTET_STRING_copy
#define ANY_constraint asn_generic_no_constraint
......
......@@ -24,6 +24,7 @@ asn_TYPE_operation_t asn_OP_BIT_STRING = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
BIT_STRING_compare,
BIT_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
......@@ -213,3 +214,37 @@ BIT_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 1;
}
}
int
BIT_STRING_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
const asn_OCTET_STRING_specifics_t *specs = td->specifics;
BIT_STRING_t *a = (BIT_STRING_t *)*aptr;
const BIT_STRING_t *b = (const BIT_STRING_t *)bptr;
if(!b) {
if(a) {
FREEMEM(a->buf);
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = CALLOC(1, specs->struct_size);
if(!a) return -1;
}
uint8_t* buf = MALLOC(b->size + 1);
if(!buf) return -1;
memcpy(buf, b->buf, b->size);
buf[b->size] = 0;
FREEMEM(a->buf);
a->buf = buf;
a->size = b->size;
a->bits_unused = b->bits_unused;
return 0;
}
......@@ -31,6 +31,7 @@ asn_struct_print_f BIT_STRING_print; /* Human-readable output */
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f BIT_STRING_compare;
asn_struct_copy_f BIT_STRING_copy;
asn_constr_check_f BIT_STRING_constraint;
......
......@@ -32,6 +32,7 @@ asn_TYPE_operation_t asn_OP_BMPString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber,
OCTET_STRING_encode_der,
......
......@@ -28,6 +28,7 @@ asn_struct_print_f BMPString_print; /* Human-readable output */
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define BMPString_compare OCTET_STRING_compare
#define BMPString_copy OCTET_STRING_copy
asn_constr_check_f BMPString_constraint;
......
......@@ -19,6 +19,7 @@ asn_TYPE_operation_t asn_OP_BOOLEAN = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
BOOLEAN_compare,
BOOLEAN_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
BOOLEAN_decode_ber,
BOOLEAN_encode_der,
......@@ -128,3 +129,29 @@ BOOLEAN_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 1;
}
}
int
BOOLEAN_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
BOOLEAN_t *a = *aptr;
const BOOLEAN_t *b = bptr;
(void)td;
if(!b) {
if(a) {
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = MALLOC(sizeof(BOOLEAN_t));
if(!a) return -1;
}
*a = *b;
return 0;
}
......@@ -28,6 +28,7 @@ asn_struct_print_f BOOLEAN_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f BOOLEAN_compare;
asn_struct_copy_f BOOLEAN_copy;
#define BOOLEAN_constraint asn_generic_no_constraint
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_ENUMERATED = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
INTEGER_compare, /* Implemented in terms of INTEGER */
INTEGER_copy, /* Implemented in terms of INTEGER */
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
INTEGER_encode_der, /* Implemented in terms of INTEGER */
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_ENUMERATED;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define ENUMERATED_compare INTEGER_compare
#define ENUMERATED_copy INTEGER_copy
#define ENUMERATED_constraint asn_generic_no_constraint
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_GeneralString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_GeneralString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define GeneralString_compare OCTET_STRING_compare
#define GeneralString_copy OCTET_STRING_copy
#define GeneralString_constraint asn_generic_unknown_constraint
......
......@@ -182,6 +182,7 @@ asn_TYPE_operation_t asn_OP_GeneralizedTime = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
GeneralizedTime_compare,
GeneralizedTime_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
GeneralizedTime_encode_der,
......
......@@ -23,6 +23,7 @@ asn_struct_print_f GeneralizedTime_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f GeneralizedTime_compare;
#define GeneralizedTime_copy OCTET_STRING_copy
asn_constr_check_f GeneralizedTime_constraint;
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_GraphicString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_GraphicString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define GraphicString_compare OCTET_STRING_compare
#define GraphicString_copy OCTET_STRING_copy
#define GraphicString_constraint asn_generic_unknown_constraint
......
......@@ -27,6 +27,7 @@ asn_TYPE_operation_t asn_OP_IA5String = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -26,6 +26,7 @@ extern asn_TYPE_operation_t asn_OP_IA5String;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define IA5String_compare OCTET_STRING_compare
#define IA5String_copy OCTET_STRING_copy
asn_constr_check_f IA5String_constraint;
......
......@@ -22,6 +22,7 @@ asn_TYPE_operation_t asn_OP_INTEGER = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
INTEGER_compare,
INTEGER_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
INTEGER_encode_der,
......@@ -738,3 +739,40 @@ INTEGER_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
}
}
int
INTEGER_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
(void)td;
INTEGER_t *a = *aptr;
const INTEGER_t *b = bptr;
if(!b) {
if(a) {
FREEMEM(a->buf);
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = CALLOC(1, sizeof(*a));
if(!a) return -1;
}
if(b->size) {
uint8_t* buf = MALLOC(b->size);
if(!buf) return -1;
memcpy(buf, b->buf, b->size);
FREEMEM(a->buf);
a->buf = buf;
a->size = b->size;
} else {
FREEMEM(a->buf);
a->buf = 0;
a->size = 0;
}
return 0;
}
......@@ -47,6 +47,7 @@ asn_struct_print_f INTEGER_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f INTEGER_compare;
asn_struct_copy_f INTEGER_copy;
#define INTEGER_constraint asn_generic_no_constraint
......
......@@ -27,6 +27,7 @@ asn_TYPE_operation_t asn_OP_ISO646String = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -24,6 +24,7 @@ extern asn_TYPE_operation_t asn_OP_ISO646String;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define ISO646String_compare OCTET_STRING_compare
#define ISO646String_copy OCTET_STRING_copy
#define ISO646String_constraint VisibleString_constraint
......
......@@ -19,6 +19,7 @@ asn_TYPE_operation_t asn_OP_NULL = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
NULL_compare,
NULL_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
NULL_decode_ber,
NULL_encode_der, /* Special handling of DER encoding */
......@@ -113,3 +114,15 @@ NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
(void)b;
return 0;
}
int
NULL_copy(const asn_TYPE_descriptor_t *td, void **a, const void *b) {
(void)td;
if(b && !*a) {
*a = CALLOC(1, sizeof(NULL_t));
if (!*a) return -1;
}
return 0;
}
......@@ -27,6 +27,7 @@ asn_struct_print_f NULL_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f NULL_compare;
asn_struct_copy_f NULL_copy;
#define NULL_constraint asn_generic_no_constraint
......
......@@ -26,6 +26,7 @@ asn_TYPE_operation_t asn_OP_NativeEnumerated = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
NativeInteger_compare,
NativeInteger_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
NativeInteger_decode_ber,
NativeInteger_encode_der,
......
......@@ -29,6 +29,7 @@ extern asn_TYPE_operation_t asn_OP_NativeEnumerated;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define NativeEnumerated_compare NativeInteger_compare
#define NativeEnumerated_copy NativeInteger_copy
#define NativeEnumerated_constraint asn_generic_no_constraint
......
......@@ -27,6 +27,7 @@ asn_TYPE_operation_t asn_OP_NativeInteger = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
NativeInteger_compare,
NativeInteger_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
NativeInteger_decode_ber,
NativeInteger_encode_der,
......@@ -152,3 +153,30 @@ NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const v
return 1;
}
}
int
NativeInteger_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) {
unsigned long *a = *aptr;
const unsigned long *b = bptr;
(void)td;
/* Check if source has data */
if(!b) {
/* Clear destination */
if(a) {
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = MALLOC(sizeof(*a));
if(!a) return -1;
}
*a = *b;
return 0;
}
......@@ -29,6 +29,7 @@ asn_struct_print_f NativeInteger_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f NativeInteger_compare;
asn_struct_copy_f NativeInteger_copy;
#define NativeInteger_constraint asn_generic_no_constraint
......
......@@ -46,6 +46,7 @@ asn_TYPE_operation_t asn_OP_NativeReal = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
NativeReal_compare,
NativeReal_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
NativeReal_decode_ber,
NativeReal_encode_der,
......@@ -149,6 +150,35 @@ NativeReal_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
}
}
int
NativeReal_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
size_t float_size = NativeReal__float_size(td);
void *a = *aptr;
const void *b = bptr;
if(!b) {
if(a) {
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = MALLOC(float_size);
if(!a) return -1;
}
if(float_size == sizeof(float)) {
*(float *)a = *(const float *)b;
} else {
*(double *)a = *(const double *)b;
}
return 0;
}
void
NativeReal_free(const asn_TYPE_descriptor_t *td, void *ptr,
enum asn_struct_free_method method) {
......
......@@ -37,6 +37,7 @@ asn_struct_print_f NativeReal_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f NativeReal_compare;
asn_struct_copy_f NativeReal_copy;
#define NativeReal_constraint asn_generic_no_constraint
......
......@@ -47,6 +47,7 @@ asn_TYPE_operation_t asn_OP_NumericString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_NumericString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define NumericString_compare OCTET_STRING_compare
#define NumericString_copy OCTET_STRING_copy
asn_constr_check_f NumericString_constraint;
......
......@@ -24,6 +24,7 @@ asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare, /* Implemented in terms of a string comparison */
OCTET_STRING_copy, /* Implemented in terms of a string copy */
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
der_encode_primitive,
......
......@@ -32,6 +32,7 @@ asn_struct_print_f OBJECT_IDENTIFIER_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define OBJECT_IDENTIFIER_compare OCTET_STRING_compare
#define OBJECT_IDENTIFIER_copy OCTET_STRING_copy
asn_constr_check_f OBJECT_IDENTIFIER_constraint;
......
......@@ -26,6 +26,7 @@ asn_TYPE_operation_t asn_OP_OCTET_STRING = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber,
OCTET_STRING_encode_der,
......@@ -249,6 +250,43 @@ OCTET_STRING_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
}
int
OCTET_STRING_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
const asn_OCTET_STRING_specifics_t *specs =
td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
: &asn_SPC_OCTET_STRING_specs;
OCTET_STRING_t *a = *aptr;
const OCTET_STRING_t *b = bptr;
if(!b) {
if(a) {
FREEMEM(a->buf);
a->buf = 0;
a->size = 0;
FREEMEM(a);
}
*aptr = 0;
return 0;
}
if(!a) {
a = *aptr = (OCTET_STRING_t *)CALLOC(1, specs->struct_size);
if(!a) return -1;
}
void *buf = MALLOC(b->size + 1);
if(!buf) return -1;
memcpy(buf, b->buf, b->size);
((uint8_t *)buf)[b->size] = '\0';
FREEMEM(a->buf);
a->buf = (uint8_t *)buf;
a->size = b->size;
return 0;
}
#if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
int
OCTET_STRING_per_get_characters(asn_per_data_t *po, uint8_t *buf,
......
......@@ -29,6 +29,7 @@ asn_struct_print_f OCTET_STRING_print_utf8;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f OCTET_STRING_compare;
asn_struct_copy_f OCTET_STRING_copy;
#define OCTET_STRING_constraint asn_generic_no_constraint
......
......@@ -14,6 +14,7 @@ asn_TYPE_operation_t asn_OP_OPEN_TYPE = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OPEN_TYPE_compare,
OPEN_TYPE_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OPEN_TYPE_decode_ber,
OPEN_TYPE_encode_der,
......
......@@ -33,6 +33,7 @@ extern "C" {
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define OPEN_TYPE_compare CHOICE_compare
#define OPEN_TYPE_copy CHOICE_copy
#define OPEN_TYPE_constraint CHOICE_constraint
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_ObjectDescriptor = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -57,6 +57,7 @@ asn_TYPE_operation_t asn_OP_PrintableString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_PrintableString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define PrintableString_compare OCTET_STRING_compare
#define PrintableString_copy OCTET_STRING_copy
asn_constr_check_f PrintableString_constraint;
......
......@@ -62,6 +62,7 @@ asn_TYPE_operation_t asn_OP_REAL = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
REAL_compare,
REAL_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
der_encode_primitive,
......@@ -361,6 +362,41 @@ REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
}
}
int
REAL_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
REAL_t *a = *aptr;
const REAL_t *b = bptr;
(void)td;
if(!b) {
if(a) {
FREEMEM(a->buf);
FREEMEM(a);
*aptr = 0;
}
return 0;
}
if(!a) {
a = *aptr = CALLOC(1, sizeof(*a));
if(!a) return -1;
}
if(b->size) {
uint8_t* buf = (uint8_t*)MALLOC(b->size);
if(!buf) return -1;
memcpy(buf, b->buf, b->size);
FREEMEM(a->buf);
a->buf = buf;
a->size = b->size;
}
return 0;
}
int
asn_REAL2double(const REAL_t *st, double *dbl_value) {
unsigned int octv;
......
......@@ -54,6 +54,7 @@ asn_struct_print_f REAL_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f REAL_compare;
asn_struct_copy_f REAL_copy;
#define REAL_constraint asn_generic_no_constraint
......
......@@ -22,6 +22,7 @@ asn_TYPE_operation_t asn_OP_RELATIVE_OID = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare, /* Implemented in terms of opaque comparison */
OCTET_STRING_copy, /* Implemented in terms of opaque copy */
#if !defined(ASN_DISABLE_BER_SUPPORT)
ber_decode_primitive,
der_encode_primitive,
......
......@@ -28,6 +28,7 @@ asn_struct_print_f RELATIVE_OID_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define RELATIVE_OID_compare OCTET_STRING_compare
#define RELATIVE_OID_copy OCTET_STRING_copy
#define RELATIVE_OID_constraint asn_generic_no_constraint
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_T61String = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_T61String;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define T61String_compare OCTET_STRING_compare
#define T61String_copy OCTET_STRING_copy
#define T61String_constraint asn_generic_unknown_constraint
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_TeletexString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_TeletexString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define TeletexString_compare OCTET_STRING_compare
#define TeletexString_copy OCTET_STRING_copy
#define TeletexString_constraint asn_generic_unknown_constraint
......
......@@ -38,6 +38,7 @@ asn_TYPE_operation_t asn_OP_UTCTime = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
UTCTime_compare,
UTCTime_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der, /* Implemented in terms of OCTET STRING */
......
......@@ -23,6 +23,7 @@ asn_struct_print_f UTCTime_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f UTCTime_compare;
#define UTCTime_copy OCTET_STRING_copy
asn_constr_check_f UTCTime_constraint;
......
......@@ -21,6 +21,7 @@ asn_TYPE_operation_t asn_OP_UTF8String = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ asn_struct_print_f UTF8String_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define UTF8String_compare OCTET_STRING_compare
#define UTF8String_copy OCTET_STRING_copy
asn_constr_check_f UTF8String_constraint;
......
......@@ -32,6 +32,7 @@ asn_TYPE_operation_t asn_OP_UniversalString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber,
OCTET_STRING_encode_der,
......
......@@ -24,6 +24,7 @@ asn_struct_print_f UniversalString_print; /* Human-readable output */
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define UniversalString_compare OCTET_STRING_compare
#define UniversalString_copy OCTET_STRING_copy
asn_constr_check_f UniversalString_constraint;
......
......@@ -20,6 +20,7 @@ asn_TYPE_operation_t asn_OP_VideotexString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_VideotexString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define VideotexString_compare OCTET_STRING_compare
#define VideotexString_copy OCTET_STRING_copy
#define VideotexString_constraint asn_generic_unknown_constraint
......
......@@ -27,6 +27,7 @@ asn_TYPE_operation_t asn_OP_VisibleString = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
OCTET_STRING_compare,
OCTET_STRING_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
OCTET_STRING_encode_der,
......
......@@ -23,6 +23,7 @@ extern asn_TYPE_operation_t asn_OP_VisibleString;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
#define VisibleString_compare OCTET_STRING_compare
#define VisibleString_copy OCTET_STRING_copy
asn_constr_check_f VisibleString_constraint;
......
......@@ -13,6 +13,7 @@ asn_TYPE_operation_t asn_OP_CHOICE = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
CHOICE_compare,
CHOICE_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
CHOICE_decode_ber,
CHOICE_encode_der,
......@@ -314,6 +315,59 @@ CHOICE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bp
}
}
int
CHOICE_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) {
if(!td) return -1;
void *st = *aptr;
const asn_CHOICE_specifics_t *specs =
(const asn_CHOICE_specifics_t *)td->specifics;
const asn_TYPE_member_t *elm; /* CHOICE's element */
int present;
int ret;
void *amemb;
void **amembp;
const void *bmemb;
if(!bptr) {
if(st) {
ASN_STRUCT_FREE(*td, st);
*aptr = NULL;
}
return 0;
}
if(!st) {
st = *aptr = CALLOC(1, specs->struct_size);
if(!st) return -1;
}
present = _fetch_present_idx(bptr,
specs->pres_offset, specs->pres_size);
if(present <= 0 && (unsigned)present > td->elements_count) return -1;
--present;
elm = &td->elements[present];
if(elm->flags & ATF_POINTER) {
/* Member is a pointer to another structure */
amembp = (void **)((char *)st + elm->memb_offset);
bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset);
} else {
amemb = (char *)st + elm->memb_offset;
amembp = &amemb;
bmemb = (const void*)((const char*)bptr + elm->memb_offset);
}
ret = elm->type->op->copy_struct(elm->type, amembp, bmemb);
if (ret != 0) return ret;
_set_present_idx(st,
specs->pres_offset,
specs->pres_size, present + 1);
return 0;
}
/*
* Return the 1-based choice variant presence index.
* Returns 0 in case of error.
......
......@@ -46,6 +46,7 @@ asn_struct_print_f CHOICE_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f CHOICE_compare;
asn_struct_copy_f CHOICE_copy;
asn_constr_check_f CHOICE_constraint;
......
......@@ -14,6 +14,7 @@ asn_TYPE_operation_t asn_OP_SEQUENCE = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
SEQUENCE_compare,
SEQUENCE_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
......@@ -198,3 +199,53 @@ SEQUENCE_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 0;
}
int
SEQUENCE_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
if(!td) return -1;
const asn_SEQUENCE_specifics_t *specs =
(const asn_SEQUENCE_specifics_t *)td->specifics;
size_t edx;
void *st = *aptr; /* Target structure */
if(!bptr) {
if(st) {
SEQUENCE_free(td, st, 0);
*aptr = 0;
}
return 0;
}
/*
* Create the target structure if it is not present already.
*/
if(st == 0) {
st = *aptr = CALLOC(1, specs->struct_size);
if(st == 0) return -1;
}
for(edx = 0; edx < td->elements_count; edx++) {
asn_TYPE_member_t *elm = &td->elements[edx];
void *amemb;
void **amembp;
const void *bmemb;
int ret;
if(elm->flags & ATF_POINTER) {
/* Member is a pointer to another structure */
amembp = (void **)((char *)st + elm->memb_offset);
bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset);
} else {
amemb = (char *)st + elm->memb_offset;
amembp = &amemb;
bmemb = (const void*)((const char*)bptr + elm->memb_offset);
}
ret = elm->type->op->copy_struct(elm->type, amembp, bmemb);
if(ret != 0) return ret;
}
return 0;
}
......@@ -51,6 +51,7 @@ asn_struct_print_f SEQUENCE_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f SEQUENCE_compare;
asn_struct_copy_f SEQUENCE_copy;
asn_constr_check_f SEQUENCE_constraint;
......
......@@ -15,6 +15,7 @@ asn_TYPE_operation_t asn_OP_SEQUENCE_OF = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
SEQUENCE_OF_compare,
SEQUENCE_OF_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
SEQUENCE_OF_decode_ber,
SEQUENCE_OF_encode_der,
......
......@@ -23,6 +23,7 @@ extern "C" {
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f SEQUENCE_OF_compare;
#define SEQUENCE_OF_copy SET_OF_copy
#define SEQUENCE_OF_constraint SET_OF_constraint
......
......@@ -14,6 +14,7 @@ asn_TYPE_operation_t asn_OP_SET = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
SET_compare,
SET_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
SET_decode_ber,
SET_encode_der,
......@@ -216,3 +217,53 @@ SET_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 0;
}
int
SET_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
if(!td) return -1;
const asn_SET_specifics_t *specs =
(const asn_SET_specifics_t *)td->specifics;
size_t edx;
void *st = *aptr; /* Target structure */
if(!bptr) {
if(st) {
SET_free(td, st, ASFM_FREE_EVERYTHING);
*aptr = 0;
}
return 0;
}
/*
* Create the target structure if it is not present already.
*/
if(st == 0) {
st = *aptr = CALLOC(1, specs->struct_size);
if(st == 0) return -1;
}
for(edx = 0; edx < td->elements_count; edx++) {
asn_TYPE_member_t *elm = &td->elements[edx];
void *amemb;
void **amembp;
const void *bmemb;
int ret;
if(elm->flags & ATF_POINTER) {
/* Member is a pointer to another structure */
amembp = (void **)((char *)st + elm->memb_offset);
bmemb = *(const void* const*)((const char*)bptr + elm->memb_offset);
} else {
amemb = (char *)st + elm->memb_offset;
amembp = &amemb;
bmemb = (const void*)((const char*)bptr + elm->memb_offset);
}
ret = elm->type->op->copy_struct(elm->type, amembp, bmemb);
if(ret != 0) return ret;
}
return 0;
}
......@@ -52,6 +52,7 @@ asn_struct_print_f SET_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f SET_compare;
asn_struct_copy_f SET_copy;
asn_constr_check_f SET_constraint;
......
......@@ -14,6 +14,7 @@ asn_TYPE_operation_t asn_OP_SET_OF = {
0,
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
SET_OF_compare,
SET_OF_copy,
#if !defined(ASN_DISABLE_BER_SUPPORT)
SET_OF_decode_ber,
SET_OF_encode_der,
......@@ -371,3 +372,58 @@ SET_OF_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
return 0;
}
int
SET_OF_copy(const asn_TYPE_descriptor_t *td, void **aptr,
const void *bptr) {
if(!td) return -1;
const asn_SET_OF_specifics_t *specs =
(const asn_SET_OF_specifics_t *)td->specifics;
void *st = *aptr;
if(!bptr) {
if(*aptr) {
asn_set_empty(_A_SET_FROM_VOID(*aptr));
*aptr = 0;
}
return 0;
}
if(st == 0) {
st = *aptr = CALLOC(1, specs->struct_size);
if(st == 0) return -1;
}
asn_anonymous_set_ *a = _A_SET_FROM_VOID(*aptr);
const asn_anonymous_set_ *b = _A_CSET_FROM_VOID(bptr);
if(b->size) {
void *_new_arr;
_new_arr = REALLOC(a->array, b->size * sizeof(b->array[0]));
if(_new_arr) {
a->array = (void **)_new_arr;
a->size = b->size;
} else {
return -1;
}
a->count = b->count;
for(int i = 0; i < b->count; i++) {
void *bmemb = b->array[i];
if(bmemb) {
void *amemb = 0;
int ret;
ret = td->elements->type->op->copy_struct(
td->elements->type,
&amemb, bmemb);
if(ret != 0) return ret;
a->array[i] = amemb;
} else {
a->array[i] = 0;
}
}
}
return 0;
}
......@@ -33,6 +33,7 @@ asn_struct_print_f SET_OF_print;
#endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
asn_struct_compare_f SET_OF_compare;
asn_struct_copy_f SET_OF_copy;
asn_constr_check_f SET_OF_constraint;
......
......@@ -143,6 +143,16 @@ typedef int (asn_struct_compare_f)(
const void *struct_A,
const void *struct_B);
/*
* Copies struct B into struct A.
* Allocates memory for struct A, if necessary.
*/
typedef int (asn_struct_copy_f)(
const struct asn_TYPE_descriptor_s *type_descriptor,
void **struct_A,
const void *struct_B
);
/*
* Return the outmost tag of the type.
* If the type is untagged CHOICE, the dynamic operation is performed.
......@@ -175,6 +185,7 @@ typedef struct asn_TYPE_operation_s {
asn_struct_free_f *free_struct; /* Free the structure */
asn_struct_print_f *print_struct; /* Human readable output */
asn_struct_compare_f *compare_struct; /* Compare two structures */
asn_struct_copy_f *copy_struct; /* Copy method */
ber_type_decoder_f *ber_decoder; /* Generic BER decoder */
der_type_encoder_f *der_encoder; /* Canonical DER encoder */
xer_type_decoder_f *xer_decoder; /* Generic XER decoder */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment