BerElement *ber,
ber_int_t *num )
{
- ber_tag_t tag;
- ber_len_t len;
struct berval bv;
+ ber_tag_t tag = ber_skip_element( ber, &bv );
- assert( num != NULL );
-
- tag = ber_skip_element( ber, &bv );
- len = bv.bv_len;
- if ( tag == LBER_DEFAULT || len > sizeof(ber_int_t) ) {
- return LBER_DEFAULT;
+ if ( tag == LBER_DEFAULT ) {
+ return tag;
}
+ return ber_decode_int( &bv, num ) ? LBER_DEFAULT : tag;
+}
+
+int
+ber_decode_int( const struct berval *bv, ber_int_t *num )
+{
+ ber_len_t len = bv->bv_len;
+ if ( len > sizeof(ber_int_t) )
+ return -1;
+
+ assert( num != NULL );
+
/* parse two's complement integer */
if( len ) {
- unsigned char *buf = (unsigned char *) bv.bv_val;
+ unsigned char *buf = (unsigned char *) bv->bv_val;
ber_len_t i;
ber_int_t netnum = buf[0] & 0xff;
*num = 0;
}
- return tag;
+ return 0;
}
ber_tag_t