Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Build

on:
pull_request:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
golang-checks:
name: Golang checks
uses: bodgit/workflows/.github/workflows/golang-checks.yml@f2ad91a9e0ba58982cdc180b62f69555ddf17d06 # v1.0.0
64 changes: 0 additions & 64 deletions .github/workflows/main.yml

This file was deleted.

128 changes: 121 additions & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,124 @@
---
version: "2"
linters:
enable-all: true
disable:
- exhaustivestruct
- exhaustruct
default: none
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
- cyclop
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- err113
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exptostd
- fatcontext
- forbidigo
- forcetypeassert
- funcorder
- funlen
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- nonamedreturns
- varnamelen
- gochecksumtype
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- goheader
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- govet
- grouper
- iface
- importas
- inamedparam
- ineffassign
- interfacebloat
- intrange
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnesserr
- nilnil
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- recvcheck
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagalign
- tagliatelle
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- wastedassign
- whitespace
- wrapcheck
- wsl
- zerologlint
exclusions:
rules:
- linters:
- revive
path: 'internal/util/*'
text: 'var-naming: avoid meaningless package names'
generated: lax
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
7 changes: 4 additions & 3 deletions cognito/cognito.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"github.com/bodgit/srp/internal/util"
)

//nolint:gochecknoglobals
var cognitoGroups = map[int]*srp.Group{
3072: util.Must(srp.NewGroup(2, 3072, rfc5054.Hex3072)), //nolint:gomnd
3072: util.Must(srp.NewGroup(2, 3072, rfc5054.Hex3072)),
}

// GetGroup returns the AWS Cognito group for the prime of n bits.
Expand All @@ -28,14 +29,14 @@ func GetGroup(n int) (*srp.Group, error) {
// NewSRP returns a new srp.SRP struct with the Cognito-specific options
// already set.
func NewSRP() (*srp.SRP, error) {
//nolint:gomnd,wrapcheck
//nolint:wrapcheck
return srp.NewSRP(crypto.SHA256, util.Must(GetGroup(3072)), srp.K(Multiplier), srp.U(ComputeU), srp.X(ComputeX))
}

// Pad prepends a zero byte to slice b if the first byte is greater than or
// equal to 0x80.
func Pad(b []byte) []byte {
if b[0] >= 0x80 { //nolint:gomnd
if b[0] >= 0x80 {
b = append([]byte{0x00}, b...)
}

Expand Down
17 changes: 9 additions & 8 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ type Group struct {
Size int
}

//nolint:gochecknoglobals
var rfcGroups = map[int]*Group{
1024: util.Must(NewGroup(2, 1024, rfc5054.Hex1024)), //nolint:gomnd
1536: util.Must(NewGroup(2, 1536, rfc5054.Hex1536)), //nolint:gomnd
2048: util.Must(NewGroup(2, 2048, rfc5054.Hex2048)), //nolint:gomnd
3072: util.Must(NewGroup(5, 3072, rfc5054.Hex3072)), //nolint:gomnd
4096: util.Must(NewGroup(5, 4096, rfc5054.Hex4096)), //nolint:gomnd
6144: util.Must(NewGroup(5, 6144, rfc5054.Hex6144)), //nolint:gomnd
8192: util.Must(NewGroup(19, 8192, rfc5054.Hex8192)), //nolint:gomnd
1024: util.Must(NewGroup(2, 1024, rfc5054.Hex1024)),
1536: util.Must(NewGroup(2, 1536, rfc5054.Hex1536)),
2048: util.Must(NewGroup(2, 2048, rfc5054.Hex2048)),
3072: util.Must(NewGroup(5, 3072, rfc5054.Hex3072)),
4096: util.Must(NewGroup(5, 4096, rfc5054.Hex4096)),
6144: util.Must(NewGroup(5, 6144, rfc5054.Hex6144)),
8192: util.Must(NewGroup(19, 8192, rfc5054.Hex8192)),
}

// NewGroup returns a Group with the generator g, and a prime of size bits set
Expand All @@ -36,7 +37,7 @@ func NewGroup(g int64, size int, s string) (*Group, error) {
group := &Group{
G: big.NewInt(g),
N: new(big.Int).SetBytes(b),
Size: size >> 3, //nolint:gomnd
Size: size >> 3,
}

return group, nil
Expand Down
1 change: 1 addition & 0 deletions internal/rfc5054/test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gochecknoglobals
package rfc5054

import "github.com/bodgit/srp/internal/util"
Expand Down
3 changes: 3 additions & 0 deletions internal/util/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"regexp"
)

// BytesFromHexString removes any characters that are not hex values from s
// and then decodes the string to a byte slice.
func BytesFromHexString(s string) ([]byte, error) {
b, err := hex.DecodeString(regexp.MustCompile("[^0-9a-fA-F]").ReplaceAllString(s, ""))
if err != nil {
Expand All @@ -16,6 +18,7 @@ func BytesFromHexString(s string) ([]byte, error) {
return b, nil
}

// Pad returns x as a byte slice, padding it to n bytes.
func Pad(x *big.Int, n int) []byte {
b := x.Bytes()
if len(b) < n {
Expand Down
2 changes: 2 additions & 0 deletions internal/util/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package util is a collection of utility functions shared between packages.
package util
1 change: 1 addition & 0 deletions internal/util/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package util

import "errors"

// ErrGroupNotFound is the error returned when an SRP group is not found.
var ErrGroupNotFound = errors.New("group not found")
1 change: 1 addition & 0 deletions internal/util/must.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package util

// Must will panic if err is non-nil.
func Must[T any](v T, err error) T { //nolint:ireturn
if err != nil {
panic(err)
Expand Down
4 changes: 3 additions & 1 deletion isv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (

"github.com/bodgit/srp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

//nolint:gochecknoglobals
var isv = []byte{0x00, 0x01, 0x01, 0x00, 0x01, 0x02, 0x00, 0x01, 0x03}

func TestISV_MarshalBinary(t *testing.T) {
Expand Down Expand Up @@ -135,7 +137,7 @@ func TestISV_UnmarshalBinary(t *testing.T) {

err := i.UnmarshalBinary(table.b)

assert.ErrorIs(t, err, table.err)
require.ErrorIs(t, err, table.err)

if err == nil {
assert.Equal(t, table.identity, i.Identity)
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestServer_MarshalBinary(t *testing.T) {
b, err := server.MarshalBinary()

assert.NotNil(t, b)
assert.Nil(t, err)
assert.NoError(t, err)
}

func TestServer_UnmarshalBinary(t *testing.T) {
Expand Down
Loading
Loading