Skip to content

Commit

Permalink
Merge pull request #30 from D3vl0per/dependency-bump
Browse files Browse the repository at this point in the history
Version bump and linter fixes
  • Loading branch information
D3vl0per authored Mar 14, 2024
2 parents 1b5a362 + dd9abf9 commit ce570d4
Show file tree
Hide file tree
Showing 43 changed files with 496 additions and 384 deletions.
27 changes: 6 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ linters-settings:
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- rangeValCopy

# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
Expand All @@ -143,9 +141,6 @@ linters-settings:
hugeParam:
# size in bytes that makes the warning trigger (default 80)
sizeThreshold: 1700 # TODO our context is 1648 bytes, we should consider increase this
nestingReduce:
# min number of statements inside a branch to trigger a warning (default 5)
bodyWidth: 5
rangeExprCopy:
# size in bytes that makes the warning trigger (default 512)
sizeThreshold: 512
Expand All @@ -156,18 +151,6 @@ linters-settings:
sizeThreshold: 1300 # TODO our transaction.Data is 1208 bytes, we should consider increase this
# whether to check test functions (default true)
skipTestFuncs: true
ruleguard:
# path to a gorules file for the ruleguard checker
rules: ''
truncateCmp:
# whether to skip int/uint/uintptr types (default true)
skipArchDependent: true
underef:
# whether to skip (*x).method() calls where x is a pointer receiver (default true)
skipRecvDeref: true
unnamedResult:
# whether to check exported functions
checkExported: true

goimports:
# put imports beginning with prefix after 3rd-party packages;
Expand Down Expand Up @@ -202,7 +185,7 @@ linters-settings:

gosimple:
# Select the Go version to target. The default is '1.13'.
go: "1.23"
go: "1.22.1"
# https://staticcheck.io/docs/options#checks
checks: [ "all" ]

Expand Down Expand Up @@ -230,7 +213,7 @@ linters-settings:

staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.23"
go: "1.22.1"
# https://staticcheck.io/docs/options#checks
checks: [ "all" ]

Expand Down Expand Up @@ -273,7 +256,7 @@ linters-settings:

unused:
# Select the Go version to target. The default is '1.13'.
go: "1.23"
go: "1.22.1"


linters:
Expand All @@ -293,9 +276,11 @@ linters:
- gosimple
- govet
- staticcheck
- ifshort
- lll
- misspell
- prealloc
- unparam
- unused
- gomnd
- forcetypeassert
- golint
2 changes: 0 additions & 2 deletions aged/age_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ type Parameters struct {
}

func (k Keychain) Encrypt(p Parameters) ([]byte, error) {

in, err := compressor(p)
if err != nil {
return nil, err
Expand Down Expand Up @@ -175,7 +174,6 @@ func compressor(p Parameters) (*bytes.Reader, error) {
}

in = bytes.NewReader(writer.Bytes())

} else {
in = bytes.NewReader(p.Data)
}
Expand Down
6 changes: 2 additions & 4 deletions aged/obf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Obfuscation interface {
Deobfuscate([]byte) ([]byte, error)
}

// AgeV1Obf is a obfuscation for age encryption header
// AgeV1Obf is a obfuscation for age encryption header.
type AgeV1Obf struct{}

var (
Expand All @@ -21,11 +21,9 @@ var (
endFlag = []byte{0, 255, 1, 254}
)

//nolint:gochecknoglobals
const lengthOfKey = 47

func (a *AgeV1Obf) Obfuscate(payload []byte) ([]byte, error) {

headerIndex := bytes.Index(payload, endOfHeader)
if headerIndex == -1 {
return nil, errors.New("missing end flag")
Expand All @@ -41,7 +39,7 @@ func (a *AgeV1Obf) Obfuscate(payload []byte) ([]byte, error) {
pad[i] = e ^ counter
counter--
}
// nolint:gocritic
//nolint:gocritic
obfHeader := append(pad, endFlag...)
return bytes.ReplaceAll(payload, header, obfHeader), nil
}
Expand Down
8 changes: 5 additions & 3 deletions aged/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
"io"

"golang.org/x/crypto/chacha20poly1305"

// nolint:staticcheck
//nolint:staticcheck
"golang.org/x/crypto/poly1305"
)

Expand All @@ -38,6 +37,7 @@ const (
)

func NewReader(key []byte, src io.Reader) (*Reader, error) {
//nolint:gomnd
if len(key) != 32 {
return nil, errors.New("key length must be 32 byte long")
}
Expand Down Expand Up @@ -136,6 +136,7 @@ func (r *Reader) readChunk() (last bool, err error) {
}

func incNonce(nonce *[chacha20poly1305.NonceSizeX]byte) {
//nolint:gomnd
for i := len(nonce) - 2; i >= 0; i-- {
nonce[i]++
if nonce[i] != 0 {
Expand Down Expand Up @@ -165,6 +166,7 @@ type Writer struct {
}

func NewWriter(key []byte, dst io.Writer) (*Writer, error) {
//nolint:gomnd
if len(key) != 32 {
return nil, errors.New("key length must be 32 byte long")
}
Expand All @@ -181,7 +183,7 @@ func NewWriter(key []byte, dst io.Writer) (*Writer, error) {
}

func (w *Writer) Write(p []byte) (n int, err error) {
// nolint:godox
//nolint:godox
// TODO: consider refactoring with a bytes.Buffer.
if w.err != nil {
return 0, w.err
Expand Down
1 change: 0 additions & 1 deletion asymmetric/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Minimalistic struct {
}

func (m *Minimalistic) Sign(payload []byte) (string, error) {

if m.Suite == nil {
return "", errors.New("missing signing suite declaration")
}
Expand Down
2 changes: 0 additions & 2 deletions asymmetric/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestMinimalisticAttestation(t *testing.T) {

ecdsa := asymmetric.Ed25519{}
err := ecdsa.Generate()
r.NoError(t, err)
Expand Down Expand Up @@ -108,7 +107,6 @@ func TestMinimalisticAttestation(t *testing.T) {
}

func TestFaultMinimalisticAttestation(t *testing.T) {

ecdsa := asymmetric.Ed25519{}
err := ecdsa.Generate()
r.NoError(t, err)
Expand Down
6 changes: 5 additions & 1 deletion asymmetric/ecdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"golang.org/x/crypto/curve25519"
)

const (
Ed25519PrivateKeySize = 32
)

type DH interface {
GenerateKeypair() error
GenerateSharedSecret([]byte) ([]byte, error)
Expand All @@ -16,7 +20,7 @@ type Curve25519 struct {
}

func (c *Curve25519) GenerateKeypair() error {
secretKey, err := generic.CSPRNG(32)
secretKey, err := generic.CSPRNG(Ed25519PrivateKeySize)
if err != nil {
return err
}
Expand Down
24 changes: 11 additions & 13 deletions asymmetric/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ func (e *Ed25519) Sign(msg []byte) string {
}

func (e *Ed25519) Verify(msg []byte, sig string) (bool, error) {

if e.Encoder == nil {
return ed25519.Verify(e.PublicKey, msg, []byte(sig)), nil
} else {
sig_raw, err := e.Encoder.Decode(sig)
if err != nil {
return false, err
}
return ed25519.Verify(e.PublicKey, msg, sig_raw), nil
}
sigRaw, err := e.Encoder.Decode(sig)
if err != nil {
return false, err
}
return ed25519.Verify(e.PublicKey, msg, sigRaw), nil

}

func (e *Ed25519) GetSecretKey() []byte {
Expand Down Expand Up @@ -124,13 +123,12 @@ func (e *Ed448) Sign(msg []byte) string {
func (e *Ed448) Verify(msg []byte, sig string) (bool, error) {
if e.Encoder == nil {
return ed448.Verify(e.PublicKey, msg, []byte(sig), e.Context), nil
} else {
sig_raw, err := e.Encoder.Decode(sig)
if err != nil {
return false, err
}
return ed448.Verify(e.PublicKey, msg, sig_raw, e.Context), nil
}
sigRaw, err := e.Encoder.Decode(sig)
if err != nil {
return false, err
}
return ed448.Verify(e.PublicKey, msg, sigRaw, e.Context), nil
}

func (e *Ed448) GetSecretKey() []byte {
Expand Down
8 changes: 4 additions & 4 deletions asymmetric/ecdsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func TestE2EEEd25519SignVerify(t *testing.T) {
{
name: "UrlBase64 encoder",
asym: asymmetric.Ed25519{
Encoder: &generic.UrlBase64{},
Encoder: &generic.URLBase64{},
},
},
{
name: "RawUrlBase64 encoder",
asym: asymmetric.Ed25519{
Encoder: &generic.RawUrlBase64{},
Encoder: &generic.RawURLBase64{},
},
},
{
Expand Down Expand Up @@ -169,13 +169,13 @@ func TestE2EEEd448SignVerify(t *testing.T) {
{
name: "UrlBase64 encoder",
asym: asymmetric.Ed448{
Encoder: &generic.UrlBase64{},
Encoder: &generic.URLBase64{},
},
},
{
name: "RawUrlBase64 encoder",
asym: asymmetric.Ed448{
Encoder: &generic.RawUrlBase64{},
Encoder: &generic.RawURLBase64{},
},
},
{
Expand Down
6 changes: 0 additions & 6 deletions compression/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (g *Gzip) Compress(in []byte) ([]byte, error) {
}

func (g *Gzip) CompressStream(in io.Reader, out io.Writer) error {

enc, err := gzip.NewWriterLevel(out, g.Level)
if err != nil {
return err
Expand Down Expand Up @@ -157,7 +156,6 @@ func (z *Zstd) Compress(in []byte) ([]byte, error) {
}

func (z *Zstd) CompressStream(in io.Reader, out io.Writer) error {

enc, err := zstd.NewWriter(out, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(z.Level)))
if err != nil {
return err
Expand Down Expand Up @@ -233,7 +231,6 @@ func (f *Flate) Compress(in []byte) ([]byte, error) {
}

func (f *Flate) CompressStream(in io.Reader, out io.Writer) error {

enc, err := flate.NewWriter(out, f.Level)
if err != nil {
return err
Expand Down Expand Up @@ -308,7 +305,6 @@ func (zl *Zlib) Compress(in []byte) ([]byte, error) {
}

func (zl *Zlib) CompressStream(in io.Reader, out io.Writer) error {

enc, err := zlib.NewWriterLevel(out, zl.Level)
if err != nil {
return err
Expand Down Expand Up @@ -389,7 +385,6 @@ func (b *Brotli) Compress(in []byte) ([]byte, error) {
}

func (b *Brotli) CompressStream(in io.Reader, out io.Writer) error {

b.bw.Reset(out)
_, err := io.Copy(b.bw, in)
if err != nil {
Expand All @@ -416,7 +411,6 @@ func (b *Brotli) Decompress(in []byte) ([]byte, error) {
}

func (b *Brotli) DecompressStream(in io.Reader, out io.Writer) error {

if err := b.br.Reset(in); err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions compression/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/D3vl0per/crypt/asymmetric"
"github.com/D3vl0per/crypt/compression"
"github.com/D3vl0per/crypt/generic"

r "github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -59,7 +58,6 @@ type compressionSample struct {
}

func compressionSamples() []compressionSample {

ed25519 := asymmetric.Ed25519{}
if err := ed25519.Generate(); err != nil {
panic(err)
Expand Down Expand Up @@ -87,7 +85,7 @@ func compressionSamples() []compressionSample {
data: ed25519.SecretKey,
},
{
name: "ed15519-public-key",
name: "ed25519-public-key",
data: ed25519.PublicKey,
},
}
Expand All @@ -113,7 +111,6 @@ func BenchmarkRoundTrip(b *testing.B) {
}

func benchmarkRoundTrip(b *testing.B, compressor compression.Compressor, data []byte) {

compressed, err := compressor.Compress(data)
r.NoError(b, err)

Expand Down Expand Up @@ -157,7 +154,6 @@ func TestRoundTrips(t *testing.T) {
}

func testRoundTrip(t *testing.T, compressor compression.Compressor, data []byte) {

compressed, err := compressor.Compress(data)
r.NoError(t, err)

Expand Down Expand Up @@ -317,7 +313,6 @@ func TestRoundTripsFault(t *testing.T) {
}

func TestZstdWrongDecompressData(t *testing.T) {

data, err := generic.CSPRNG(16)
r.NoError(t, err)

Expand Down
Loading

0 comments on commit ce570d4

Please sign in to comment.