@@ -73,11 +73,7 @@ static ssize_t fr_der_encode_len(fr_dbuff_t *dbuff, fr_dbuff_marker_t *length_st
7373static inline CC_HINT (always_inline ) ssize_t
7474 fr_der_encode_tag (fr_dbuff_t * dbuff , fr_der_tag_t tag_num , fr_der_tag_class_t tag_class ,
7575 fr_der_tag_constructed_t constructed ) CC_HINT (nonnull );
76- static ssize_t encode_value (fr_dbuff_t * dbuff , fr_da_stack_t * da_stack , unsigned int depth , fr_dcursor_t * cursor ,
77- void * encode_ctx );
78- static ssize_t encode_pair (fr_dbuff_t * dbuff , fr_da_stack_t * da_stack , unsigned int depth , fr_dcursor_t * cursor ,
79- void * encode_ctx );
80- static ssize_t der_encode_pair (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , void * encode_ctx ) CC_HINT (nonnull );
76+ static ssize_t encode_value (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , void * encode_ctx );
8177
8278/** Compare two pairs by their tag number.
8379 *
@@ -93,6 +89,12 @@ static inline CC_HINT(always_inline) int8_t fr_der_pair_cmp_by_da_tag(void const
9389 return CMP_PREFER_SMALLER (fr_der_flag_der_type (my_a -> da ), fr_der_flag_der_type (my_b -> da ));
9490}
9591
92+ static ssize_t encode_pair (fr_dbuff_t * dbuff , UNUSED fr_da_stack_t * da_stack , UNUSED unsigned int depth , fr_dcursor_t * cursor ,
93+ void * encode_ctx )
94+ {
95+ return encode_value (dbuff , cursor , encode_ctx );
96+ }
97+
9698static ssize_t fr_der_encode_boolean (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , UNUSED fr_der_encode_ctx_t * encode_ctx )
9799{
98100 fr_dbuff_t our_dbuff = FR_DBUFF (dbuff );
@@ -773,7 +775,6 @@ static ssize_t fr_der_encode_set(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, fr_der
773775 fr_dbuff_t our_dbuff = FR_DBUFF (dbuff );
774776 fr_pair_t * vp ;
775777 ssize_t slen ;
776- unsigned int depth = 0 ;
777778
778779 vp = fr_dcursor_current (cursor );
779780 PAIR_VERIFY (vp );
@@ -846,14 +847,14 @@ static ssize_t fr_der_encode_set(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, fr_der
846847
847848 fr_proto_da_stack_build (& da_stack , vp -> da );
848849
849- FR_PROTO_STACK_PRINT (& da_stack , depth );
850+ FR_PROTO_STACK_PRINT (& da_stack , vp -> da -> depth - 1 );
850851
851852 fr_pair_dcursor_child_iter_init (& child_cursor , & vp -> children , cursor );
852853
853854 for (i = 0 ; fr_dcursor_current (& child_cursor ) != NULL ; i ++ ) {
854855 ptr_pairs [i ].data = fr_dbuff_current (& work_dbuff );
855856
856- slen = encode_value (& work_dbuff , NULL , depth , & child_cursor , encode_ctx );
857+ slen = encode_value (& work_dbuff , & child_cursor , encode_ctx );
857858 if (unlikely (slen < 0 )) {
858859 fr_strerror_printf ("Failed to encode pair: %s" , fr_strerror ());
859860 talloc_free (buff );
@@ -1102,22 +1103,18 @@ static ssize_t fr_der_encode_choice(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, fr_
11021103 fr_da_stack_t da_stack ;
11031104 fr_dcursor_t child_cursor ;
11041105 ssize_t slen = 0 ;
1105- unsigned int depth = 0 ;
11061106
11071107 vp = fr_dcursor_current (cursor );
11081108 PAIR_VERIFY (vp );
11091109 fr_assert (!vp -> da -> flags .is_raw );
11101110
1111- depth = vp -> da -> depth - 1 ;
1112-
11131111 fr_proto_da_stack_build (& da_stack , vp -> da );
11141112
1115- FR_PROTO_STACK_PRINT (& da_stack , depth );
1113+ FR_PROTO_STACK_PRINT (& da_stack , vp -> da -> depth - 1 );
11161114
11171115 fr_pair_dcursor_child_iter_init (& child_cursor , & vp -> children , cursor );
11181116
1119- slen = fr_pair_cursor_to_network (& our_dbuff , & da_stack , depth , & child_cursor , encode_ctx ,
1120- encode_pair );
1117+ slen = fr_pair_cursor_to_network (& our_dbuff , & da_stack , vp -> da -> depth - 1 , & child_cursor , encode_ctx , encode_pair );
11211118 if (slen < 0 ) return -1 ;
11221119
11231120 return fr_dbuff_set (dbuff , & our_dbuff );
@@ -1354,17 +1351,17 @@ static ssize_t fr_der_encode_X509_extensions(fr_dbuff_t *dbuff, fr_dcursor_t *cu
13541351 fr_dbuff_marker (& length_start , & our_dbuff );
13551352 FR_DBUFF_ADVANCE_RETURN (& our_dbuff , 1 );
13561353
1357- /*
1358- * Encode the data either as raw garbage, or as an OID pair.
1359- */
1360- child = fr_dcursor_current (& child_cursor );
1361- fr_assert (child != NULL );
1362-
1363- if (child -> da -> flags .is_raw ) {
1364- slen = fr_der_encode_octetstring (& our_dbuff , & child_cursor , encode_ctx );
1365- } else {
1366- slen = der_encode_pair (& our_dbuff , & child_cursor , encode_ctx );
1367- }
1354+ /*
1355+ * Encode the data either as raw garbage, or as an OID pair.
1356+ */
1357+ child = fr_dcursor_current (& child_cursor );
1358+ fr_assert (child != NULL );
1359+
1360+ if (child -> da -> flags .is_raw ) {
1361+ slen = fr_der_encode_octetstring (& our_dbuff , & child_cursor , encode_ctx );
1362+ } else {
1363+ slen = encode_value (& our_dbuff , & child_cursor , encode_ctx );
1364+ }
13681365 if (slen < 0 ) {
13691366 fr_dbuff_marker_release (& length_start );
13701367 fr_dbuff_marker_release (& inner_seq_len_start );
@@ -1534,7 +1531,7 @@ static ssize_t fr_der_encode_oid_and_value(fr_dbuff_t *dbuff, fr_dcursor_t *curs
15341531 if (child -> da -> flags .is_raw ) {
15351532 slen = fr_der_encode_octetstring (& our_dbuff , & child_cursor , encode_ctx );
15361533 } else {
1537- slen = der_encode_pair (& our_dbuff , & child_cursor , encode_ctx );
1534+ slen = encode_value (& our_dbuff , & child_cursor , encode_ctx );
15381535 }
15391536 if (slen < 0 ) return slen ;
15401537
@@ -1727,8 +1724,7 @@ static inline CC_HINT(always_inline) ssize_t
17271724 *
17281725 * @return The number of bytes written to the buffer
17291726 */
1730- static ssize_t encode_value (fr_dbuff_t * dbuff , UNUSED fr_da_stack_t * da_stack , UNUSED unsigned int depth ,
1731- fr_dcursor_t * cursor , void * encode_ctx )
1727+ static ssize_t encode_value (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , void * encode_ctx )
17321728{
17331729 fr_pair_t const * vp ;
17341730 fr_dbuff_t our_dbuff = FR_DBUFF (dbuff );
@@ -1854,12 +1850,12 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, UNUSED fr_da_stack_t *da_stack, U
18541850 fr_dbuff_marker (& marker , & our_dbuff );
18551851 FR_DBUFF_ADVANCE_RETURN (& our_dbuff , 1 );
18561852
1857- if (flags -> is_extensions ) {
1858- slen = fr_der_encode_X509_extensions (& our_dbuff , cursor , uctx );
1859-
1860- } else if (vp -> da -> flags .is_raw ) {
1853+ if (vp -> da -> flags .is_raw ) {
18611854 slen = fr_der_encode_octetstring (& our_dbuff , cursor , uctx );
18621855
1856+ } else if (flags -> is_extensions ) {
1857+ slen = fr_der_encode_X509_extensions (& our_dbuff , cursor , uctx );
1858+
18631859 } else {
18641860 slen = func -> encode (& our_dbuff , cursor , uctx );
18651861 }
@@ -1879,17 +1875,6 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, UNUSED fr_da_stack_t *da_stack, U
18791875 return fr_dbuff_set (dbuff , & our_dbuff );
18801876}
18811877
1882- static ssize_t encode_pair (fr_dbuff_t * dbuff , fr_da_stack_t * da_stack , unsigned int depth , fr_dcursor_t * cursor ,
1883- void * encode_ctx )
1884- {
1885- return encode_value (dbuff , da_stack , depth , cursor , encode_ctx );
1886- }
1887-
1888- static ssize_t der_encode_pair (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , void * encode_ctx )
1889- {
1890- return encode_pair (dbuff , NULL , 0 , cursor , encode_ctx );
1891- }
1892-
18931878static ssize_t fr_der_encode_proto (UNUSED TALLOC_CTX * ctx , fr_pair_list_t * vps , uint8_t * data , size_t data_len ,
18941879 void * encode_ctx )
18951880{
@@ -1901,7 +1886,7 @@ static ssize_t fr_der_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps,
19011886
19021887 fr_pair_dcursor_init (& cursor , vps );
19031888
1904- slen = der_encode_pair (& dbuff , & cursor , encode_ctx );
1889+ slen = encode_value (& dbuff , & cursor , encode_ctx );
19051890
19061891 if (slen < 0 ) {
19071892 fr_strerror_printf ("Failed to encode data: %s" , fr_strerror ());
@@ -1931,7 +1916,7 @@ static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *
19311916extern fr_test_point_pair_encode_t der_tp_encode_pair ;
19321917fr_test_point_pair_encode_t der_tp_encode_pair = {
19331918 .test_ctx = encode_test_ctx ,
1934- .func = der_encode_pair ,
1919+ .func = encode_value ,
19351920};
19361921
19371922extern fr_test_point_proto_encode_t der_tp_encode_proto ;
0 commit comments