Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Fix static analysis issues #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
linters-settings:
goimports:
local-prefixes: "github.com/namecoin"
local-prefixes: github.com/namecoin
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
# lint with mandatory linters only. Add more like this:
# --disable=foo,bar
- go get -v -d -t ./...
- bash testdata/golangci-linter.bash --disable=exhaustive,gci,godot,gofumpt,nlreturn
- bash testdata/golangci-linter.bash --disable=exhaustive,godot,gofumpt
- os: linux
stage: lint
language: go
Expand Down
3 changes: 2 additions & 1 deletion cmd/certinject/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"io/ioutil"

"github.com/hlandau/xlog"
"github.com/namecoin/certinject"
easyconfig "gopkg.in/hlandau/easyconfig.v1"
"gopkg.in/hlandau/easyconfig.v1/cflag"

"github.com/namecoin/certinject"
)

var log, logp = xlog.New("certinject")
Expand Down
10 changes: 9 additions & 1 deletion cryptoapi_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package certinject

import (
"crypto/sha1" // #nosec G505

// #nosec G505
"crypto/sha1"
"crypto/x509"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -176,6 +178,7 @@ func injectCertCryptoAPI(derBytes []byte) {
store, err := cryptoAPINameToStore(cryptoAPIFlagPhysicalStoreName.Value())
if err != nil {
log.Errorf("error: %s", err.Error())

return
}

Expand All @@ -190,6 +193,7 @@ func injectCertCryptoAPI(derBytes []byte) {
fingerprintHexUpperList, err = allFingerprintsInStore(registryBase, storeKey)
if err != nil {
log.Errorf("Couldn't enumerate certificates in store: %s", err)

return
}
}
Expand All @@ -201,6 +205,7 @@ func injectCertCryptoAPI(derBytes []byte) {
if len(fingerprintHexUpperList) == 0 {
if derBytes == nil {
log.Errorf("No cert specified")

return
}

Expand All @@ -227,19 +232,22 @@ func injectSingleCertCryptoAPI(derBytes []byte, fingerprintHexUpper string,
blob, err := readInputBlob(derBytes, registryBase, storeKey+`\`+fingerprintHexUpper)
if err != nil {
log.Errorf("Couldn't read input blob: %s", err)

return
}

err = editBlob(blob)
if err != nil {
log.Errorf("Couldn't edit blob: %s", err)

return
}

// Marshal the Blob
blobBytes, err := blob.Marshal()
if err != nil {
log.Errorf("Couldn't marshal cert blob: %s", err)

return
}

Expand Down
4 changes: 4 additions & 0 deletions cryptoapi_windows_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ func TestRegistryKeyNames(t *testing.T) {
store, ok := cryptoAPIStores[tc.Physical]
if !ok {
t.Errorf("test %q is invalid (store not defined)", tc.Physical)

continue
}

if err := cryptoAPIFlagLogicalStoreName.CfSetValue(tc.Logical); err != nil {
t.Errorf("test %q: %v", tc.Name, err)

continue
}

key := store.Key()
if key != tc.Key {
t.Errorf("test %q: expected key to be %q, got %q", tc.Name, tc.Key, key)

continue
}

Expand All @@ -81,6 +84,7 @@ func TestRegistryKeyNames(t *testing.T) {
base := store.Base
if base != tc.Base {
t.Errorf("test %q: expected base to be %v, got %v", tc.Name, base2str(t, tc.Base), base2str(t, base))

continue
}

Expand Down
4 changes: 2 additions & 2 deletions testdata/golangci-linter.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo "Shell checks passed."
echo ----- Windows -----
GOOS=windows go generate ./...
# NSS support is unmaintained; don't bother us with complaints about it.
GOOS=windows "$(go env GOPATH)"/bin/golangci-lint run --no-config --enable-all \
GOOS=windows "$(go env GOPATH)"/bin/golangci-lint run --enable-all \
--color always \
--skip-files "file.go" \
--skip-files "nss.go" \
Expand All @@ -37,7 +37,7 @@ GOOS=windows "$(go env GOPATH)"/bin/golangci-lint run --no-config --enable-all \

echo ----- Linux -----
GOOS=linux go generate ./...
GOOS=linux "$(go env GOPATH)"/bin/golangci-lint run --no-config --enable-all \
GOOS=linux "$(go env GOPATH)"/bin/golangci-lint run --enable-all \
--color always \
--skip-files "file.go" \
--skip-files "nss.go" \
Expand Down