var zbuf2 bytes.Buffer
zw := zip.NewWriter(&zbuf2)
+ foundVersion := false
for _, f := range zr.File {
// golang.org/fips140@v1.2.3/dir/file.go ->
// golang.org/fips140@v1.2.3/fips140/v1.2.3/dir/file.go
f.Name = "golang.org/fips140@" + version + "/fips140/" + version +
strings.TrimPrefix(f.Name, "golang.org/fips140@"+version)
}
+ // Inject version in [crypto/internal/fips140.Version].
+ if f.Name == "golang.org/fips140@"+version+"/fips140/"+version+"/fips140.go" {
+ rf, err := f.Open()
+ if err != nil {
+ log.Fatal(err)
+ }
+ contents, err := io.ReadAll(rf)
+ if err != nil {
+ log.Fatal(err)
+ }
+ returnLine := `return "latest" //mkzip:version`
+ if !bytes.Contains(contents, []byte(returnLine)) {
+ log.Fatalf("did not find %q in fips140.go", returnLine)
+ }
+ newLine := `return "` + version + `"`
+ contents = bytes.ReplaceAll(contents, []byte(returnLine), []byte(newLine))
+ wf, err := zw.Create(f.Name)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if _, err := wf.Write(contents); err != nil {
+ log.Fatal(err)
+ }
+ foundVersion = true
+ continue
+ }
wf, err := zw.CreateRaw(&f.FileHeader)
if err != nil {
log.Fatal(err)
if err := zw.Close(); err != nil {
log.Fatal(err)
}
+ if !foundVersion {
+ log.Fatal("did not find fips140.go file")
+ }
err = os.WriteFile(version+".zip", zbuf2.Bytes(), 0666)
if err != nil {
return "Go Cryptographic Module"
}
+// Version returns the formal version (such as "v1.0.0") if building against a
+// frozen module with GOFIPS140. Otherwise, it returns "latest".
func Version() string {
- return "v1.0"
+ // This return value is replaced by mkzip.go, it must not be changed or
+ // moved to a different file.
+ return "latest" //mkzip:version
}
// - GOARCH: the architecture target
// - GOAMD64/GOARM/GO386/etc: the architecture feature level for GOARCH
// - GOOS: the operating system target
+// - GOFIPS140: the frozen FIPS 140-3 module version, if any
// - vcs: the version control system for the source tree where the build ran
// - vcs.revision: the revision identifier for the current commit or checkout
// - vcs.time: the modification time associated with vcs.revision, in RFC3339 format