-
Notifications
You must be signed in to change notification settings - Fork 8
/
read.go
107 lines (85 loc) · 2.55 KB
/
read.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package sec
import (
"io/ioutil"
"github.com/apache/mynewt-artifact/errors"
)
// ReadPubSignKey reads a public signing key from a file.
func ReadPubSignKey(filename string) (PubSignKey, error) {
keyBytes, err := ioutil.ReadFile(filename)
if err != nil {
return PubSignKey{}, errors.Wrapf(err, "error reading key file")
}
return ParsePubSignKey(keyBytes)
}
// ReadPubSignKeys reads a set of public signing keys from several files.
func ReadPubSignKeys(filenames []string) ([]PubSignKey, error) {
keys := make([]PubSignKey, len(filenames))
for i, filename := range filenames {
key, err := ReadPubSignKey(filename)
if err != nil {
return nil, err
}
keys[i] = key
}
return keys, nil
}
// ReadPrivSignKey reads a private signing key from a file.
func ReadPrivSignKey(filename string) (PrivSignKey, error) {
keyBytes, err := ioutil.ReadFile(filename)
if err != nil {
return PrivSignKey{}, errors.Wrapf(err, "error reading key file")
}
return ParsePrivSignKey(keyBytes)
}
// ReadPubSignKeys reads a set of private signing keys from several files.
func ReadPrivSignKeys(filenames []string) ([]PrivSignKey, error) {
keys := make([]PrivSignKey, len(filenames))
for i, filename := range filenames {
key, err := ReadPrivSignKey(filename)
if err != nil {
return nil, err
}
keys[i] = key
}
return keys, nil
}
// ReadPubEncKey reads a public encryption key from a file.
func ReadPubEncKey(filename string) (PubEncKey, error) {
keyBytes, err := ioutil.ReadFile(filename)
if err != nil {
return PubEncKey{}, errors.Wrapf(err, "error reading key file")
}
return ParsePubEncKey(keyBytes)
}
// ReadPubSignKeys reads a set of public encryption keys from several files.
func ReadPubEncKeys(filenames []string) ([]PubEncKey, error) {
keys := make([]PubEncKey, len(filenames))
for i, filename := range filenames {
key, err := ReadPubEncKey(filename)
if err != nil {
return nil, err
}
keys[i] = key
}
return keys, nil
}
// ReadPubEncKey reads a private encryption key from a file.
func ReadPrivEncKey(filename string) (PrivEncKey, error) {
keyBytes, err := ioutil.ReadFile(filename)
if err != nil {
return PrivEncKey{}, errors.Wrapf(err, "error reading key file")
}
return ParsePrivEncKey(keyBytes)
}
// ReadPubSignKeys reads a set of private encryption keys from several files.
func ReadPrivEncKeys(filenames []string) ([]PrivEncKey, error) {
keys := make([]PrivEncKey, len(filenames))
for i, filename := range filenames {
key, err := ReadPrivEncKey(filename)
if err != nil {
return nil, err
}
keys[i] = key
}
return keys, nil
}