Skip to content

Commit

Permalink
Implement review suggestions and fix tests and linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Sep 28, 2022
1 parent 19f008e commit 678c558
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 31 deletions.
6 changes: 3 additions & 3 deletions cmd/cmd-close.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -89,9 +89,9 @@ var (
// load file
var data []byte
if filename == "-" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
} else {
data, err = ioutil.ReadFile(filename)
data, err = os.ReadFile(filename)
}
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions cmd/cmd-open.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -79,9 +78,9 @@ var (
// load file
var data []byte
if filename == "-" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
} else {
data, err = ioutil.ReadFile(filename)
data, err = os.ReadFile(filename)
}
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/cmd-verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -185,9 +185,9 @@ func verifyLetter(filename string, silent bool) (signedBy []string, err error) {
// load file
var data []byte
if filename == "-" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
} else {
data, err = ioutil.ReadFile(filename)
data, err = os.ReadFile(filename)
}
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
const (
stdInOutFilename = "-"
letterFileExtension = ".letter"
sigFileExtension = ".sig"

warnFileSize = 12000000 // 120MB
)
Expand Down
17 changes: 7 additions & 10 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ func TestCoreAllCombinations(t *testing.T) {
t.Logf("of these, %d were successfully detected as invalid", combinationsDetectedInvalid)
}

func testStorage(t *testing.T, suite *Suite) (detectedInvalid bool) {
t.Helper()

// t.Logf("testing storage with %s", suite.ID)
func testStorage(t *testing.T, suite *Suite) (detectedInvalid bool) { //nolint:thelper
t.Logf("testing storage with %s", suite.ID)

e, err := setupEnvelopeAndTrustStore(t, suite)
if err != nil {
Expand Down Expand Up @@ -404,9 +402,7 @@ func setupEnvelopeAndTrustStore(t *testing.T, suite *Suite) (*Envelope, error) {
}

// check if we are missing key derivation - this is only ok if we are merely signing
if !keyDerPresent &&
(len(e.suite.Provides.all) != 1 ||
!e.suite.Provides.Has(SenderAuthentication)) {
if !keyDerPresent && len(e.Senders) != len(e.suite.Tools) {
return nil, testInvalidToolset(e, "omitting a key derivation tool is only allowed when merely signing")
}

Expand Down Expand Up @@ -514,9 +510,10 @@ func getOrMakeSignet(t *testing.T, tool tools.ToolLogic, recipient bool, signetI
}

// generateCombinations returns all possible combinations of the given []string slice.
// Forked from https://github.com/mxschmitt/golang-combinations/blob/a887187146560effd2677e987b069262f356297f/combinations.go
// Copyright (c) 2018 Max Schmitt,
// MIT License.
//
// Forked from https://github.com/mxschmitt/golang-combinations/blob/a887187146560effd2677e987b069262f356297f/combinations.go
// Copyright (c) 2018 Max Schmitt,
// MIT License.
func generateCombinations(set []string) (subsets [][]string) {
length := uint(len(set))

Expand Down
7 changes: 3 additions & 4 deletions filesig/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package filesig
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -51,7 +50,7 @@ func SignFile(dataFilePath, signatureFilePath string, metaData map[string]string
return nil, fmt.Errorf("failed to sign file: %w", err)
}

sigFileData, err := ioutil.ReadFile(signatureFilePath)
sigFileData, err := os.ReadFile(signatureFilePath)
var newSigFileData []byte
switch {
case err == nil:
Expand All @@ -71,7 +70,7 @@ func SignFile(dataFilePath, signatureFilePath string, metaData map[string]string
}

// Write the signature to file.
if err := ioutil.WriteFile(signatureFilePath, newSigFileData, 0o0644); err != nil { //nolint:gosec
if err := os.WriteFile(signatureFilePath, newSigFileData, 0o0644); err != nil { //nolint:gosec
return nil, fmt.Errorf("failed to write signature to file: %w", err)
}

Expand All @@ -86,7 +85,7 @@ func VerifyFile(dataFilePath, signatureFilePath string, metaData map[string]stri
var lastErr error

// Read signature from file.
sigFileData, err := ioutil.ReadFile(signatureFilePath)
sigFileData, err := os.ReadFile(signatureFilePath)
if err != nil {
return nil, fmt.Errorf("failed to read signature file: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions import_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
)

// Keywords and Prefixes for the export text format.
const (
ExportSenderKeyword = "sender"
ExportSenderPrefix = "sender:"
Expand Down
4 changes: 2 additions & 2 deletions lhash/labeledhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Digest(alg Algorithm, data []byte) *LabeledHash {
// DigestFile creates a new labeled hash and digests the given file.
func DigestFile(alg Algorithm, pathToFile string) (*LabeledHash, error) {
// Open file that should be hashed.
file, err := os.OpenFile(pathToFile, os.O_RDONLY, 0)
file, err := os.Open(pathToFile)
if err != nil {
return nil, fmt.Errorf("failed to open file: %w", err)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func (lh *LabeledHash) Matches(data []byte) bool {
}

// MatchesData returns true if the digest of the given data matches the hash.
// DEPRECATED: Use Matches instead.
// Deprecated: Use Matches instead.
func (lh *LabeledHash) MatchesData(data []byte) bool {
return lh.Equal(Digest(lh.alg, data))
}
Expand Down
9 changes: 4 additions & 5 deletions truststores/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package truststores

import (
"errors"
"io/ioutil"
"os"

"github.com/safing/jess"
Expand All @@ -27,7 +26,7 @@ func WriteSignetToFile(signet *jess.Signet, filename string) error {
}

// write
err = ioutil.WriteFile(filename, data, 0o0600)
err = os.WriteFile(filename, data, 0o0600)
if err != nil {
return err
}
Expand All @@ -37,7 +36,7 @@ func WriteSignetToFile(signet *jess.Signet, filename string) error {

// LoadSignetFromFile loads a signet from the given filepath.
func LoadSignetFromFile(filename string) (*jess.Signet, error) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
if os.IsNotExist(err) {
return nil, jess.ErrSignetNotFound
Expand Down Expand Up @@ -72,7 +71,7 @@ func WriteEnvelopeToFile(envelope *jess.Envelope, filename string) error {
}

// write to storage
err = ioutil.WriteFile(filename, data, 0600) //nolint:gofumpt // gofumpt is ignorant of octal numbers.
err = os.WriteFile(filename, data, 0600) //nolint:gofumpt // gofumpt is ignorant of octal numbers.
if err != nil {
return err
}
Expand All @@ -82,7 +81,7 @@ func WriteEnvelopeToFile(envelope *jess.Envelope, filename string) error {

// LoadEnvelopeFromFile loads an envelope from the given filepath.
func LoadEnvelopeFromFile(filename string) (*jess.Envelope, error) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
if os.IsNotExist(err) {
return nil, jess.ErrEnvelopeNotFound
Expand Down

0 comments on commit 678c558

Please sign in to comment.