@@ -45,24 +45,54 @@ func TestImports(t *testing.T) {
45
45
t .Fatalf ("go list: %v\n %s" , err , out )
46
46
}
47
47
48
- // Ensure we don't import any unexpected internal package from the FIPS
49
- // module, since we can't change the module source after it starts
50
- // validation. This locks in the API of otherwise internal packages.
48
+ allPackages := make (map [string ]bool )
49
+
50
+ // importCheck is the set of packages that import crypto/internal/fips/check.
51
+ importCheck := make (map [string ]bool )
52
+
51
53
for _ , line := range strings .Split (string (out ), "\n " ) {
52
54
if line == "" {
53
55
continue
54
56
}
55
- parts := strings .Fields (line )
56
- if parts [1 ] == "crypto/internal/fips" ||
57
- strings .HasPrefix (parts [1 ], "crypto/internal/fips/" ) ||
58
- strings .HasPrefix (parts [1 ], "crypto/internal/fipsdeps/" ) {
57
+ pkg , importedPkg , _ := strings .Cut (line , " " )
58
+
59
+ allPackages [pkg ] = true
60
+
61
+ if importedPkg == "crypto/internal/fips/check" {
62
+ importCheck [pkg ] = true
63
+ }
64
+
65
+ // Ensure we don't import any unexpected internal package from the FIPS
66
+ // module, since we can't change the module source after it starts
67
+ // validation. This locks in the API of otherwise internal packages.
68
+ if importedPkg == "crypto/internal/fips" ||
69
+ strings .HasPrefix (importedPkg , "crypto/internal/fips/" ) ||
70
+ strings .HasPrefix (importedPkg , "crypto/internal/fipsdeps/" ) {
59
71
continue
60
72
}
61
- if AllowedInternalPackages [parts [ 1 ] ] {
73
+ if AllowedInternalPackages [importedPkg ] {
62
74
continue
63
75
}
64
- if strings .Contains (parts [1 ], "internal" ) {
65
- t .Errorf ("unexpected import of internal package: %s -> %s" , parts [0 ], parts [1 ])
76
+ if strings .Contains (importedPkg , "internal" ) {
77
+ t .Errorf ("unexpected import of internal package: %s -> %s" , pkg , importedPkg )
78
+ }
79
+ }
80
+
81
+ // Ensure that all packages except check and check's dependencies import check.
82
+ for pkg := range allPackages {
83
+ switch pkg {
84
+ case "crypto/internal/fips/check" :
85
+ case "crypto/internal/fips" :
86
+ case "crypto/internal/fips/alias" :
87
+ case "crypto/internal/fips/subtle" :
88
+ case "crypto/internal/fips/hmac" :
89
+ case "crypto/internal/fips/sha3" :
90
+ case "crypto/internal/fips/sha256" :
91
+ case "crypto/internal/fips/sha512" :
92
+ default :
93
+ if ! importCheck [pkg ] {
94
+ t .Errorf ("package %s does not import crypto/internal/fips/check" , pkg )
95
+ }
66
96
}
67
97
}
68
98
}
0 commit comments