-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vkubiv/refactor-move-from-aries
chore: copy kmscrypto component from aries-framework-go
- Loading branch information
Showing
229 changed files
with
43,590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,44 @@ jobs: | |
- uses: amannn/action-semantic-pull-request@v4 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
Checks: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Run checks | ||
run: | | ||
echo $PATH | ||
go env | ||
echo ${{ github.workspace }} | ||
make checks | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
UnitTest: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 10 | ||
steps: | ||
|
||
- name: Setup Go 1.20 | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.20' | ||
id: go | ||
|
||
- uses: actions/checkout@v3 | ||
|
||
- name: Run unit test | ||
timeout-minutes: 15 | ||
run: make unit-test | ||
|
||
- name: Upload coverage to Codecov | ||
timeout-minutes: 10 | ||
uses: codecov/[email protected] | ||
with: | ||
file: ./coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# | ||
# Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
run: | ||
concurrency: 4 | ||
deadline: 3m | ||
issues-exit-code: 1 | ||
tests: true | ||
build-tags: [""] | ||
skip-dirs: | ||
- pkg/crypto/primitive/bbs12381g2pub/internal/kilic/bls12-381 | ||
|
||
output: | ||
format: colored-line-number | ||
print-issued-lines: true | ||
print-linter-name: true | ||
|
||
linters-settings: | ||
errcheck: | ||
check-type-assertions: true | ||
check-blank: true | ||
ignore: fmt:.*,io/ioutil:^Read.* | ||
govet: | ||
check-shadowing: true | ||
settings: | ||
printf: | ||
funcs: | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Debugf | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Infof | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Warnf | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Errorf | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Fatalf | ||
- (github.com/hyperledger/aries-framework-go/pkg/common/log.Log).Panicf | ||
golint: | ||
min-confidence: 0.6 | ||
gofmt: | ||
simplify: true | ||
goimports: | ||
local-prefixes: github.com/hyperledger/aries-framework-go | ||
gocyclo: | ||
min-complexity: 10 | ||
maligned: | ||
suggest-new: true | ||
dupl: | ||
threshold: 500 | ||
goconst: | ||
min-len: 3 | ||
min-occurrences: 3 | ||
misspell: | ||
# default locale is a neutral variety of English. | ||
locale: | ||
ignore-words: [] | ||
lll: | ||
line-length: 120 | ||
tab-width: 1 | ||
unused: | ||
check-exported: false | ||
unparam: | ||
check-exported: false | ||
nakedret: | ||
max-func-lines: 0 | ||
gocritic: | ||
enabled-tags: | ||
- diagnostic | ||
- performance | ||
- style | ||
- opinionated | ||
disabled-checks: | ||
- unnamedResult | ||
- whyNoLint # TODO enable. | ||
funlen: | ||
lines: 60 | ||
statements: 40 | ||
wsl: | ||
strict-append: true | ||
allow-assign-and-call: true | ||
allow-multiline-assign: true | ||
allow-case-traling-whitespace: true | ||
allow-cuddle-declarations: false | ||
godot: | ||
check-all: false | ||
gomoddirectives: | ||
replace-local: true | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- nolintlint | ||
- varnamelen | ||
- tenv | ||
- tagliatelle | ||
- testpackage | ||
- maligned | ||
- prealloc | ||
- exhaustive #TODO enable | ||
- goerr113 # TODO enable | ||
- nlreturn # TODO enable | ||
- noctx # TODO enable | ||
- interfacer # deprecated by the author https://github.com/mvdan/interfacer#interfacer | ||
- scopelint # deprecated by the author https://github.com/kyoh86/scopelint#obsoleted | ||
- exhaustivestruct | ||
- paralleltest | ||
- tparallel | ||
- cyclop # TODO consider replacing gocyclo with cyclop | ||
- ifshort # TODO enable | ||
- makezero # TODO enable | ||
- wrapcheck # TODO enable | ||
- thelper # TODO enable | ||
- usestdlibvars | ||
- testableexamples | ||
- stylecheck | ||
- nosnakecase | ||
- gci | ||
- staticcheck | ||
- nonamedreturns | ||
- nilnil | ||
- ireturn | ||
- gomnd | ||
- gosimple | ||
- errchkjson | ||
- errname | ||
- dupword | ||
- interfacebloat | ||
- forcetypeassert | ||
- exhaustruct | ||
- contextcheck | ||
- containedctx | ||
- bodyclose | ||
- revive | ||
- gosec | ||
- gofumpt | ||
- gofmt | ||
- gocritic | ||
- goimports | ||
- gocognit | ||
- forbidigo | ||
- nosprintfhostport | ||
- typecheck | ||
- maintidx | ||
- depguard | ||
- musttag | ||
- mirror | ||
- errorlint | ||
- nakedret | ||
|
||
issues: | ||
exclude-use-default: false | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- dupl | ||
- funlen | ||
- gomnd | ||
- maintidx | ||
- gomnd | ||
- usestdlibvars | ||
- testableexamples | ||
- stylecheck | ||
- typecheck | ||
- maintidx | ||
- mirror | ||
- path: example_[^\/]*_test\.go | ||
linters: | ||
- dupl | ||
- funlen | ||
- gomnd | ||
- goconst | ||
- lll | ||
- source: "swagger:route" | ||
linters: | ||
- lll | ||
|
||
exclude: | ||
# Allow package logger variables (for now) | ||
- logger is a global variable | ||
# Add comments for package | ||
- at least one file in a package should have a package comment | ||
- Line contains TODO/BUG/FIXME | ||
# Allow magic number 1 | ||
- Magic number[:] 1[^\d] | ||
# Temporarily allow old protobuf reference | ||
- package github.com/golang/protobuf/proto is deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright SecureKey Technologies Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
# Tool commands (overridable) | ||
DOCKER_CMD ?= docker | ||
|
||
GO_VER ?= 1.20.5 | ||
PROJECT_ROOT = github.com/hyperledger/aries-framework-go | ||
GOBIN_PATH=$(abspath .)/build/bin | ||
MOCKGEN=$(GOBIN_PATH)/mockgen | ||
GOMOCKS=pkg/internal/gomocks | ||
|
||
.PHONY: all | ||
all: clean checks unit-test | ||
|
||
.PHONY: checks | ||
checks: license lint | ||
|
||
.PHONY: lint | ||
lint: | ||
@scripts/check_lint.sh | ||
|
||
.PHONY: license | ||
license: | ||
@scripts/check_license.sh | ||
|
||
.PHONY: unit-test | ||
unit-test: | ||
@scripts/check_unit.sh | ||
|
||
.PHONY: clean | ||
clean: | ||
@rm -rf ./.build | ||
@rm -rf coverage*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package crypto | ||
|
||
// DefKeySize is the default key size for crypto primitives. | ||
const DefKeySize = 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package crypto | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/trustbloc/kms-crypto-go/spi/crypto" | ||
) | ||
|
||
// ToECKey converts key to an ecdsa public key. It returns an error if the curve is invalid. | ||
func ToECKey(key *crypto.PublicKey) (*ecdsa.PublicKey, error) { | ||
crv, err := toCurve(key.Curve) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ecdsa.PublicKey{ | ||
Curve: crv, | ||
X: new(big.Int).SetBytes(key.X), | ||
Y: new(big.Int).SetBytes(key.Y), | ||
}, nil | ||
} | ||
|
||
func toCurve(crv string) (elliptic.Curve, error) { | ||
switch crv { | ||
case "P-256", "NIST_P256": | ||
return elliptic.P256(), nil | ||
case "P-384", "NIST_P384": | ||
return elliptic.P384(), nil | ||
case "P-521", "NIST_P521": | ||
return elliptic.P521(), nil | ||
} | ||
|
||
return nil, fmt.Errorf("invalid curve '%s'", crv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package crypto | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/trustbloc/kms-crypto-go/spi/crypto" | ||
) | ||
|
||
func TestToECKey(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
curve elliptic.Curve | ||
}{ | ||
{ | ||
name: "to P-256 key", | ||
curve: elliptic.P256(), | ||
}, | ||
{ | ||
name: "to P-384 key", | ||
curve: elliptic.P384(), | ||
}, | ||
{ | ||
name: "to P-521 key", | ||
curve: elliptic.P521(), | ||
}, | ||
{ | ||
name: "invalid curve", | ||
curve: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tc := tt | ||
t.Run(tc.name, func(t *testing.T) { | ||
if tc.name == "invalid curve" { | ||
_, err := ToECKey(&crypto.PublicKey{ | ||
Curve: "undefined", | ||
Type: "EC", | ||
}) | ||
require.EqualError(t, err, "invalid curve 'undefined'") | ||
|
||
return | ||
} | ||
|
||
privKey, err := ecdsa.GenerateKey(tc.curve, rand.Reader) | ||
require.NoError(t, err) | ||
|
||
pubKey := &crypto.PublicKey{ | ||
X: privKey.X.Bytes(), | ||
Y: privKey.Y.Bytes(), | ||
Curve: tc.curve.Params().Name, | ||
Type: "EC", | ||
} | ||
|
||
pubECKey, err := ToECKey(pubKey) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.curve.Params().Name, pubECKey.Curve.Params().Name) | ||
require.EqualValues(t, privKey.X.Bytes(), pubECKey.X.Bytes()) | ||
require.EqualValues(t, privKey.Y.Bytes(), pubECKey.Y.Bytes()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.