blob: 143a520bf30ec763371ae0a4885ea85c1433df12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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
}
|