Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Update go #21

Merged
merged 5 commits into from
Feb 22, 2024
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
134 changes: 134 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches:
- master
types: [opened, synchronize]
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest

codeql:
name: CodeQL
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

test_cover:
name: Coverage
runs-on: ubuntu-latest

env:
CGO_ENABLED: 0
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'true'

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: true

- name: Write coverage profile
run: go test -v ./... -coverprofile=./coverage.txt -covermode=atomic

- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true # if something is wrong on uploading codecov results, then this job will fail
files: ./coverage.txt
verbose: true

tests:
name: Run tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2022, macos-12]
go_versions: [ '1.20', '1.21', '1.22' ]
exclude:
# Only latest Go version for Windows and MacOS.
- os: windows-2022
go_versions: '1.20'
- os: windows-2022
go_versions: '1.21'
- os: macos-12
go_versions: '1.20'
- os: macos-12
go_versions: '1.21'
# Exclude latest Go version for Ubuntu as Coverage uses it.
- os: ubuntu-20.04
go_versions: '1.22'
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'true'

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '${{ matrix.go_versions }}'
cache: true

- name: Run tests
run: go test -v -race ./...
69 changes: 69 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m

# include test files or not, default is true
tests: false

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: tab

# all available settings of specific linters
linters-settings:
exhaustive:
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
default-signifies-exhaustive: true
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
govet:
# report about shadowed variables
check-shadowing: false
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
reason: "Obsolete after the 1.13 release; use the standard `errors` package"
revive:
rules:
- name: duplicated-imports

linters:
enable:
# mandatory linters
- govet
- revive

# some default golangci-lint linters
- errcheck
- gosimple
- godot
- ineffassign
- staticcheck
- typecheck
- unused

# extra linters
- bidichk
- durationcheck
- exhaustive
- exportloopref
- gofmt
- goimports
- gomodguard
- misspell
- predeclared
- reassign
- whitespace
disable-all: true
fast: false

1 change: 0 additions & 1 deletion ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (

// PublicKeyUncompressedSize is constant with uncompressed size of public key (PK).
// First byte always should be 0x4 other 64 bytes is X and Y (32 bytes per coordinate).
// 2 * 32 + 1
PublicKeyUncompressedSize = 65
)

Expand Down
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module github.com/nspcc-dev/neofs-crypto

go 1.16
go 1.20

require (
github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/rfc6979 v0.2.0
github.com/stretchr/testify v1.7.0
github.com/nspcc-dev/rfc6979 v0.2.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 8 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/rfc6979 v0.2.1 h1:8wWxkamHWFmO790GsewSoKUSJjVnL1fmdRpokU/RgRM=
github.com/nspcc-dev/rfc6979 v0.2.1/go.mod h1:Tk7h5kyUWkhjyO3zUgFFhy1v2vQv3BvQEntakdtqrWc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions internal/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package internal

// Error is a custom error
// Error is a custom error returned from the library.
type Error string

// Error is an implementation of error interface
// Error is an implementation of error interface.
func (e Error) Error() string { return string(e) }
6 changes: 3 additions & 3 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

// LoadPrivateKey allows to load private key from various formats:
// - wif string
// - hex string
// - file path (D-bytes or SEC 1 / ASN.1 DER form)
// - wif string
// - hex string
// - file path (D-bytes or SEC 1 / ASN.1 DER form).
func LoadPrivateKey(val string) (*ecdsa.PrivateKey, error) {
if data, err := os.ReadFile(val); err == nil {
return UnmarshalPrivateKey(data)
Expand Down
2 changes: 1 addition & 1 deletion rfc6979.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
// RFC6979SignatureSize contains r and s coordinates (32 bytes)
// RFC6979SignatureSize contains r and s coordinates (32 bytes).
RFC6979SignatureSize = 64

// ErrWrongHashSize when passed signature to VerifyRFC6979 has wrong size.
Expand Down
4 changes: 2 additions & 2 deletions test/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
)

// Keys is pre-generated PrivateKeys (SK) for tests only
// Keys is pre-generated PrivateKeys (SK) for tests only.
var Keys = []string{
"307702010104203ee1fd84dd7199925f8d32f897aaa7f2d6484aa3738e5e0abd03f8240d7c6d8ca00a06082a8648ce3d030107a1440342000475099c302b77664a2508bec1cae47903857b762c62713f190e8d99912ef76737f36191e4c0ea50e47b0e0edbae24fd6529df84f9bd63f87219df3a086efe9195",
"3077020101042035f2b425109b17b1d8f3b5c50daea1091e27d2452bce1126080bd4b98de9bb67a00a06082a8648ce3d030107a144034200045188d33a3113ac77fea0c17137e434d704283c234400b9b70bcdf4829094374abb5818767e460a94f36046ffcef44576fa59ef0e5f31fb86351c06c3d84e156c",
Expand Down Expand Up @@ -113,7 +113,7 @@ var Keys = []string{
"3077020101042089c2c73d08bd03da4c3111aa0b78bb1edc5243d8e119513035d3741e851dec1ca00a06082a8648ce3d030107a14403420004ec9ebc34f45150334fd1d8c92274fe43c5b3b059f15cb1963f6cf7d54bc6b1b0b4ef1c5d56d2d06ab54ce2e7606e0fa5d2f188a2d593b22d9cf6a0098aa00cb6",
}

// DecodeKey method for test usage only
// DecodeKey method for test usage only.
func DecodeKey(i int) *ecdsa.PrivateKey {
var (
err error
Expand Down
2 changes: 1 addition & 1 deletion wif.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func WIFEncode(key *ecdsa.PrivateKey) (string, error) {
func WIFDecode(wif string) (*ecdsa.PrivateKey, error) {
data, err := base58.Decode(wif)
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrBadWIF, err)
return nil, fmt.Errorf("%w: %w", ErrBadWIF, err)
} else if actual := len(data); actual != WIFLength {
return nil, fmt.Errorf("%w: expect: %d, actual: %d", ErrBadWIF, WIFLength, actual)
} else if sum := wifCheckSum(data[:34]); !bytes.Equal(data[34:], sum) {
Expand Down
Loading