2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <constr_SEQUENCE_OF.h>
8 #include <asn_SEQUENCE_OF.h>
11 * The DER encoder of the SEQUENCE OF type.
14 SEQUENCE_OF_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr,
15 int tag_mode, ber_tlv_tag_t tag,
16 asn_app_consume_bytes_f *cb, void *app_key) {
17 asn_TYPE_member_t *elm = td->elements;
18 const asn_anonymous_sequence_ *list = _A_CSEQUENCE_FROM_VOID(ptr);
19 size_t computed_size = 0;
20 ssize_t encoding_size = 0;
21 asn_enc_rval_t erval = {0,0,0};
24 ASN_DEBUG("Estimating size of SEQUENCE OF %s", td->name);
27 * Gather the length of the underlying members sequence.
29 for(edx = 0; edx < list->count; edx++) {
30 void *memb_ptr = list->array[edx];
31 if(!memb_ptr) continue;
32 erval = elm->type->op->der_encoder(elm->type, memb_ptr,
35 if(erval.encoded == -1)
37 computed_size += erval.encoded;
41 * Encode the TLV for the sequence itself.
43 encoding_size = der_write_tags(td, computed_size, tag_mode, 1, tag,
45 if(encoding_size == -1) {
47 erval.failed_type = td;
48 erval.structure_ptr = ptr;
52 computed_size += encoding_size;
54 erval.encoded = computed_size;
55 ASN__ENCODED_OK(erval);
58 ASN_DEBUG("Encoding members of SEQUENCE OF %s", td->name);
63 for(edx = 0; edx < list->count; edx++) {
64 void *memb_ptr = list->array[edx];
65 if(!memb_ptr) continue;
66 erval = elm->type->op->der_encoder(elm->type, memb_ptr,
69 if(erval.encoded == -1)
71 encoding_size += erval.encoded;
74 if(computed_size != (size_t)encoding_size) {
76 * Encoded size is not equal to the computed size.
79 erval.failed_type = td;
80 erval.structure_ptr = ptr;
82 erval.encoded = computed_size;
83 erval.structure_ptr = 0;
84 erval.failed_type = 0;