@@ -1000,6 +1000,60 @@ void wolfSSL_ASN1_INTEGER_free(WOLFSSL_ASN1_INTEGER* in)
10001000 XFREE (in , NULL , DYNAMIC_TYPE_OPENSSL );
10011001}
10021002
1003+ /* Get the length of the raw integer value bytes, stripping the DER tag/length
1004+ * header if present. Required for OpenSSL compatibility where ASN1_INTEGER is
1005+ * typedef'd to ASN1_STRING and callers use ASN1_STRING_length() on integers.
1006+ *
1007+ * @param [in] ai ASN.1 INTEGER object.
1008+ * @return Length of the raw integer value on success.
1009+ * @return 0 when ai is NULL or data is invalid.
1010+ */
1011+ int wolfSSL_ASN1_INTEGER_get_length (const WOLFSSL_ASN1_INTEGER * ai )
1012+ {
1013+ if (ai == NULL || ai -> data == NULL || ai -> length <= 0 ) {
1014+ return 0 ;
1015+ }
1016+ if (ai -> data [0 ] == ASN_INTEGER ) {
1017+ word32 idx = 1 ;
1018+ int len = 0 ;
1019+ if (GetLength (ai -> data , & idx , & len , (word32 )ai -> length ) > 0 &&
1020+ idx + (word32 )len == (word32 )ai -> length ) {
1021+ return len ;
1022+ }
1023+ }
1024+ /* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1025+ * or data that coincidentally starts with 0x02 but whose header+value
1026+ * boundaries do not span exactly ai->length. */
1027+ return ai -> length ;
1028+ }
1029+
1030+ /* Get a pointer to the raw integer value bytes, skipping the DER tag/length
1031+ * header if present. Required for OpenSSL compatibility where ASN1_INTEGER is
1032+ * typedef'd to ASN1_STRING and callers use ASN1_STRING_get0_data() on integers.
1033+ *
1034+ * @param [in] ai ASN.1 INTEGER object.
1035+ * @return Pointer to the raw integer value bytes on success.
1036+ * @return NULL when ai is NULL or data is invalid.
1037+ */
1038+ const unsigned char * wolfSSL_ASN1_INTEGER_get0_data (const WOLFSSL_ASN1_INTEGER * ai )
1039+ {
1040+ if (ai == NULL || ai -> data == NULL || ai -> length <= 0 ) {
1041+ return NULL ;
1042+ }
1043+ if (ai -> data [0 ] == ASN_INTEGER ) {
1044+ word32 idx = 1 ;
1045+ int len = 0 ;
1046+ if (GetLength (ai -> data , & idx , & len , (word32 )ai -> length ) > 0 &&
1047+ idx + (word32 )len == (word32 )ai -> length ) {
1048+ return ai -> data + idx ;
1049+ }
1050+ }
1051+ /* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1052+ * or data that coincidentally starts with 0x02 but whose header+value
1053+ * boundaries do not span exactly ai->length. */
1054+ return ai -> data ;
1055+ }
1056+
10031057#if defined(OPENSSL_EXTRA )
10041058/* Reset the data of ASN.1 INTEGER object back to empty fixed array.
10051059 *
0 commit comments