@@ -70,7 +70,6 @@ static ssize_t fr_der_encode_bitstring(fr_dbuff_t *dbuff, fr_dcursor_t *cursor,
7070static ssize_t fr_der_encode_octetstring (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull );
7171static ssize_t fr_der_encode_null (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull (2 ));
7272static ssize_t fr_der_encode_oid (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull (1 ,2 ));
73- static ssize_t fr_der_encode_enumerated (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull (1 ,2 ));
7473static ssize_t fr_der_encode_sequence (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull );
7574static ssize_t fr_der_encode_set (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull );
7675static ssize_t fr_der_encode_utc_time (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull (1 ,2 ));
@@ -80,6 +79,14 @@ static ssize_t fr_der_encode_oid_value_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cur
8079
8180static ssize_t fr_der_encode_string (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx ) CC_HINT (nonnull (1 ,2 ));
8281
82+ /*
83+ * We have per-type function names to make it clear that different types have different encoders.
84+ * However, the methods to encode them are the same. So rather than having trampoline functions, we just
85+ * use defines.
86+ */
87+ #define fr_der_encode_enumerated fr_der_encode_integer
88+
89+
8390static ssize_t fr_der_encode_len (fr_dbuff_t * dbuff , fr_dbuff_marker_t * length_start , ssize_t len ) CC_HINT (nonnull );
8491static inline CC_HINT (always_inline ) ssize_t
8592 fr_der_encode_tag (fr_dbuff_t * dbuff , fr_der_tag_num_t tag_num , fr_der_tag_class_t tag_class ,
@@ -573,68 +580,6 @@ static ssize_t fr_der_encode_oid(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, UNUSED
573580 return fr_dbuff_set (dbuff , & our_dbuff );
574581}
575582
576- static ssize_t fr_der_encode_enumerated (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , UNUSED fr_der_encode_ctx_t * encode_ctx )
577- {
578- fr_dbuff_t our_dbuff = FR_DBUFF (dbuff );
579- fr_pair_t const * vp ;
580- int64_t value ;
581- uint8_t first_octet = 0 ;
582- size_t i , len ;
583-
584- vp = fr_dcursor_current (cursor );
585- PAIR_VERIFY (vp );
586-
587- /*
588- * ISO/IEC 8825-1:2021
589- * 8.4 Encoding of an enumerated value
590- * The encoding of an enumerated value shall be that of the integer value with which it is
591- * associated.
592- * NOTE - It is primitive.
593- */
594- value = vp -> vp_int64 ;
595-
596- for (i = 0 , len = 0 ; i < sizeof (value ); i ++ ) {
597- uint8_t byte = (value >> 56 ) & 0xff ;
598-
599- value <<= 8 ;
600-
601- if (len == 0 ) {
602- first_octet = byte ;
603- len ++ ;
604- continue ;
605-
606- } else if (len == 1 ) {
607- /*
608- * 8.3.2 If the contents octets of an integer value encoding consist of more than one
609- * octet, then the bits of the first octet and bit 8 of the second octet: a) shall not
610- * all be ones; and b) shall not all be zero.
611- */
612- if ((first_octet == 0xff && (byte & 0x80 )) || ((first_octet == 0x00 ) && (byte >> 7 == 0 ))) {
613- if (i == sizeof (value ) - 1 ) {
614- /*
615- * If this is the only byte, then we can encode it in a single byte.
616- */
617- FR_DBUFF_IN_RETURN (& our_dbuff , byte );
618- continue ;
619- }
620-
621- first_octet = byte ;
622- continue ;
623- } else {
624- FR_DBUFF_IN_RETURN (& our_dbuff , first_octet );
625- FR_DBUFF_IN_RETURN (& our_dbuff , byte );
626- len ++ ;
627- continue ;
628- }
629- }
630-
631- FR_DBUFF_IN_RETURN (& our_dbuff , byte );
632- len ++ ;
633- }
634-
635- return fr_dbuff_set (dbuff , & our_dbuff );
636- }
637-
638583static ssize_t fr_der_encode_sequence (fr_dbuff_t * dbuff , fr_dcursor_t * cursor , fr_der_encode_ctx_t * encode_ctx )
639584{
640585 fr_dbuff_t our_dbuff = FR_DBUFF (dbuff );
0 commit comments