Skip to content

Commit

Permalink
Merge pull request #174 from v0-e/copy-op
Browse files Browse the repository at this point in the history
Copy operation
  • Loading branch information
mouse07410 authored Feb 4, 2024
2 parents a6bdcd2 + edfc7e7 commit 4cfcd4f
Show file tree
Hide file tree
Showing 76 changed files with 769 additions and 2 deletions.
9 changes: 9 additions & 0 deletions asn1-tools/unber/libasn1_unber_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions skeletons/ANY.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/ANY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 35 additions & 0 deletions skeletons/BIT_STRING.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions skeletons/BIT_STRING.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions skeletons/BMPString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/BMPString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
27 changes: 27 additions & 0 deletions skeletons/BOOLEAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions skeletons/BOOLEAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/ENUMERATED.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions skeletons/ENUMERATED.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/GeneralString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/GeneralString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/GeneralizedTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/GeneralizedTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions skeletons/GraphicString.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/GraphicString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/IA5String.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/IA5String.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 38 additions & 0 deletions skeletons/INTEGER.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions skeletons/INTEGER.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/ISO646String.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/ISO646String.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions skeletons/NULL.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions skeletons/NULL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions skeletons/NativeEnumerated.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions skeletons/NativeEnumerated.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions skeletons/NativeInteger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions skeletons/NativeInteger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 4cfcd4f

Please sign in to comment.