From b1bcc5d12fc57f0d39f3dadc0d159f4c71ae37d7 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 13 Apr 2022 16:33:03 +0200 Subject: one util file for now --- internal/util/crypto.go | 30 ---------------------------- internal/util/io.go | 30 ---------------------------- internal/util/util.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 60 deletions(-) delete mode 100644 internal/util/crypto.go delete mode 100644 internal/util/io.go create mode 100644 internal/util/util.go diff --git a/internal/util/crypto.go b/internal/util/crypto.go deleted file mode 100644 index a8c8fac..0000000 --- a/internal/util/crypto.go +++ /dev/null @@ -1,30 +0,0 @@ -package util - -import ( - "crypto" - "crypto/ed25519" - "fmt" - "io/ioutil" - - "git.sigsum.org/sigsum-go/pkg/hex" - "git.sigsum.org/sigsum-go/pkg/types" -) - -func SignerFromHex(s string) (crypto.Signer, error) { - b, err := hex.Deserialize(s) - if err != nil { - return nil, fmt.Errorf("util: parse key: %v", err) - } - if len(b) != ed25519.PrivateKeySize { - return nil, fmt.Errorf("util: invalid private key size %d", len(b)) - } - return ed25519.PrivateKey(b), nil -} - -func FileHash(path string) (*types.Hash, error) { - b, err := ioutil.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("util: read file %s: %v", path, err) - } - return types.HashFn(b), nil -} diff --git a/internal/util/io.go b/internal/util/io.go deleted file mode 100644 index 143a520..0000000 --- a/internal/util/io.go +++ /dev/null @@ -1,30 +0,0 @@ -package util - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - - "git.sigsum.org/sigsum-go/pkg/hex" -) - -func BytesFromStdin() ([]byte, error) { - b, err := ioutil.ReadAll(os.Stdin) - if err != nil { - return nil, fmt.Errorf("util: read stdin: %v", err) - } - return b, nil -} - -func HexFromStdin() ([]byte, error) { - b, err := BytesFromStdin() - if err != nil { - return nil, err - } - b, err = hex.Deserialize(string(bytes.TrimSpace(b))) - if err != nil { - return nil, fmt.Errorf("util: parse stdin: %v", err) - } - return b, nil -} diff --git a/internal/util/util.go b/internal/util/util.go new file mode 100644 index 0000000..4d52245 --- /dev/null +++ b/internal/util/util.go @@ -0,0 +1,52 @@ +package util + +import ( + "bytes" + "crypto" + "crypto/ed25519" + "fmt" + "io/ioutil" + "os" + + "git.sigsum.org/sigsum-go/pkg/hex" + "git.sigsum.org/sigsum-go/pkg/types" +) + +func BytesFromStdin() ([]byte, error) { + b, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return nil, fmt.Errorf("util: read stdin: %v", err) + } + return b, nil +} + +func HexFromStdin() ([]byte, error) { + b, err := BytesFromStdin() + if err != nil { + return nil, err + } + b, err = hex.Deserialize(string(bytes.TrimSpace(b))) + if err != nil { + return nil, fmt.Errorf("util: parse stdin: %v", err) + } + return b, nil +} + +func SignerFromHex(s string) (crypto.Signer, error) { + b, err := hex.Deserialize(s) + if err != nil { + return nil, fmt.Errorf("util: parse key: %v", err) + } + if len(b) != ed25519.PrivateKeySize { + return nil, fmt.Errorf("util: invalid private key size %d", len(b)) + } + return ed25519.PrivateKey(b), nil +} + +func FileHash(path string) (*types.Hash, error) { + b, err := ioutil.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("util: read file %s: %v", path, err) + } + return types.HashFn(b), nil +} -- cgit v1.2.3