Several improvements required for <openssl/bn.h>:
authorschwarze <schwarze@openbsd.org>
Wed, 23 Nov 2022 17:20:23 +0000 (17:20 +0000)
committerschwarze <schwarze@openbsd.org>
Wed, 23 Nov 2022 17:20:23 +0000 (17:20 +0000)
* List internal constants and types that are intentionally undocumented.
* List unused constants and types that are intentionally undocumented.
* Cope with intentionally undocumented identifiers being declared
more than once (in this case, because of #if and #else).
* Require exact matches for man -k searches (in this case,
such that BN_BITS does not match BN_BITS2).
* Handle the weird BN_ULONG, which is #define'd instead of using typedef.

regress/lib/libcrypto/man/check_complete.pl

index 6a55bdc..964191f 100755 (executable)
@@ -25,7 +25,10 @@ my %internal = (
        CHARTYPE_FIRST_ESC_2253 CHARTYPE_LAST_ESC_2253 CHARTYPE_PRINTABLESTRING
     )],
     bn => [qw(
-       BN_MUL_COMBA BN_RECURSION BN_SQR_COMBA
+       BN_BITS BN_BITS4 BN_BYTES
+       BN_DEC_CONV BN_DEC_FMT1 BN_DEC_FMT2 BN_DEC_NUM BN_LLONG BN_LONG
+       BN_MASK2 BN_MASK2h BN_MASK2h1 BN_MASK2l BN_MUL_COMBA
+       BN_RECURSION BN_SQR_COMBA BN_TBIT BN_ULLONG
     )],
     objects => [qw(
        OBJ_bsearch OBJ_bsearch_ OBJ_bsearch_ex OBJ_bsearch_ex_
@@ -47,7 +50,8 @@ my %obsolete = (
        X509_algor_st
     )],
     bn => [qw(
-       BN_set_params BN_get_params
+       BN_FLG_EXP_CONSTTIME BN_FLG_FREE BN_get_params
+       BN_HEX_FMT1 BN_HEX_FMT2 BN_MASK BN_set_params
     )],
     objects => [qw(
        _DECLARE_OBJ_BSEARCH_CMP_FN
@@ -98,7 +102,8 @@ my $in_define = 0;
 my $in_function = 0;
 my $in_struct = 0;
 my $in_typedef_struct = 0;
-my %undoc = ();
+my %expect_undoc = ();
+my %found_undoc = ();
 my $verbose = 0;
 
 if (defined $ARGV[0] && $ARGV[0] eq '-v') {
@@ -109,9 +114,9 @@ $#ARGV == 0 or die "usage: $0 [-v] headername";
 $hfile .= "/$ARGV[0].h";
 open my $in_fh, '<', $hfile or die "$hfile: $!";
 
-$undoc{$_} = 1 foreach @{$internal{$ARGV[0]}};
-$undoc{$_} = 1 foreach @{$obsolete{$ARGV[0]}};
-$undoc{$_} = 1 foreach @{$postponed{$ARGV[0]}};
+$expect_undoc{$_} = 1 foreach @{$internal{$ARGV[0]}};
+$expect_undoc{$_} = 1 foreach @{$obsolete{$ARGV[0]}};
+$expect_undoc{$_} = 1 foreach @{$postponed{$ARGV[0]}};
 
 while (<$in_fh>) {
 try_again:
@@ -164,13 +169,13 @@ try_again:
                $in_typedef_struct = 0;
                my ($id) = /^\s*(\w+);$/
                    or die "at end of typedef struct: $_";
-               unless (system "$MANW -k Vt=$id > /dev/null 2>&1") {
+               unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
                        print "Vt $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "V- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -236,7 +241,12 @@ try_again:
 
        if (my ($id) = /^#\s*define\s+(\w+)\s+\S/) {
                /\\$/ and $in_define = 1;
-               unless (system "$MANW -k Dv=$id > /dev/null 2>&1") {
+               if ($id eq 'BN_ULONG' &&
+                   not system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
+                       print "Vt $line\n" if $verbose;
+                       next;
+               }
+               unless (system "$MANW -k 'Dv~^$id\$' > /dev/null 2>&1") {
                        print "Dv $line\n" if $verbose;
                        next;
                }
@@ -265,9 +275,9 @@ try_again:
                        print "D- $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "D- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -288,9 +298,9 @@ try_again:
                        print "F- $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "F- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -301,9 +311,9 @@ try_again:
                next;
        }
        if (my ($id) = /^#\s*define\s+(\w+)$/) {
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "-- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -317,7 +327,7 @@ try_again:
        # Handle global variables.
 
        if (my ($id) = /^extern\s+int\s+(\w+);$/) {
-               unless (system "$MANW -k Va=$id > /dev/null 2>&1") {
+               unless (system "$MANW -k 'Va~^$id\$' > /dev/null 2>&1") {
                        print "Va $line\n" if $verbose;
                        next;
                }
@@ -332,13 +342,13 @@ try_again:
        # Handle variable type declarations.
 
        if (my ($id) = /^struct\s+(\w+);$/) {
-               unless (system "$MANW -k Vt=$id > /dev/null 2>&1") {
+               unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
                        print "Vt $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "V- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -350,13 +360,13 @@ try_again:
        }
 
        if (my ($id) = /^typedef\s+(?:const\s+)?(?:struct\s+)?\S+\s+(\w+);$/) {
-               unless (system "$MANW -k Vt=$id > /dev/null 2>&1") {
+               unless (system "$MANW -k 'Vt~^$id\$' > /dev/null 2>&1") {
                        print "Vt $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "V- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($verbose) {
@@ -403,9 +413,9 @@ try_again:
                        print "F- $line\n" if $verbose;
                        next;
                }
-               if ($undoc{$id}) {
+               if ($expect_undoc{$id}) {
                        print "F- $line\n" if $verbose;
-                       delete $undoc{$id};
+                       $found_undoc{$id} = 1;
                        next;
                }
                if ($id =~ /^ASN1_PCTX_\w+$/) {
@@ -430,5 +440,8 @@ try_again:
        die "parse error: $_";
 }
 close $in_fh;
-warn "expected as undocumented but not found: $_" foreach keys %undoc;
+foreach (keys %expect_undoc) {
+       warn "expected as undocumented but not found: $_"
+           unless $found_undoc{$_};
+}
 exit 0;