Skip to content

Commit

Permalink
Update minimum required go version to 1.20 (#1161)
Browse files Browse the repository at this point in the history
* Update CI to use go1.20, and use atomi.Int64

* Update go version in go.mod to go 1.20

* stringify the version name
  • Loading branch information
lestrrat authored Jul 27, 2024
1 parent 8f99f17 commit 67496fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.19
go-version: "1.20"
check-latest: true
- uses: golangci/golangci-lint-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lestrrat-go/jwx/v2

go 1.19
go 1.20

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
Expand Down
15 changes: 6 additions & 9 deletions jwe/internal/aescbc/aescbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,17 @@ const (

const defaultBufSize int64 = 256 * 1024 * 1024

// Grr, we would like to use atomic.Int64, but that's only available
// from Go 1.19. Yes, we will cut support for Go 1.19 at some point,
// but not today (probably going to up the minimum required Go version
// some time after 1.22 is released)
var maxBufSize int64
var maxBufSize atomic.Int64

func init() {
atomic.StoreInt64(&maxBufSize, defaultBufSize)
SetMaxBufferSize(defaultBufSize)
}

func SetMaxBufferSize(siz int64) {
if siz <= 0 {
siz = defaultBufSize
}
atomic.StoreInt64(&maxBufSize, siz)
maxBufSize.Store(siz)
}

func pad(buf []byte, n int) []byte {
Expand All @@ -43,7 +39,7 @@ func pad(buf []byte, n int) []byte {
}

bufsiz := len(buf) + rem
mbs := atomic.LoadInt64(&maxBufSize)
mbs := maxBufSize.Load()
if int64(bufsiz) > mbs {
panic(fmt.Errorf("failed to allocate buffer"))
}
Expand Down Expand Up @@ -200,7 +196,8 @@ func ensureSize(dst []byte, n int) []byte {
func (c Hmac) Seal(dst, nonce, plaintext, data []byte) []byte {
ctlen := len(plaintext)
bufsiz := ctlen + c.Overhead()
mbs := atomic.LoadInt64(&maxBufSize)
mbs := maxBufSize.Load()

if int64(bufsiz) > mbs {
panic(fmt.Errorf("failed to allocate buffer"))
}
Expand Down

0 comments on commit 67496fb

Please sign in to comment.