MCPcopy Create free account
hub / github.com/prometheus/procfs / parseCrypto

Function parseCrypto

crypto.go:73–111  ·  view source on GitHub ↗

parseCrypto parses a /proc/crypto stream into Crypto elements.

(r io.Reader)

Source from the content-addressed store, hash-verified

71
72// parseCrypto parses a /proc/crypto stream into Crypto elements.
73func parseCrypto(r io.Reader) ([]Crypto, error) {
74 var out []Crypto
75
76 s := bufio.NewScanner(r)
77 for s.Scan() {
78 text := s.Text()
79 switch {
80 case strings.HasPrefix(text, "name"):
81 // Each crypto element begins with its name.
82 out = append(out, Crypto{})
83 case text == "":
84 continue
85 }
86
87 if len(out) == 0 {
88 return nil, fmt.Errorf("%w: parsed invalid line before name parsed: %q", ErrFileParse, text)
89 }
90
91 kv := strings.Split(text, ":")
92 if len(kv) != 2 {
93 return nil, fmt.Errorf("%w: Cannot parse line: %q", ErrFileParse, text)
94 }
95
96 k := strings.TrimSpace(kv[0])
97 v := strings.TrimSpace(kv[1])
98
99 // Parse the key/value pair into the currently focused element.
100 c := &out[len(out)-1]
101 if err := c.parseKV(k, v); err != nil {
102 return nil, err
103 }
104 }
105
106 if err := s.Err(); err != nil {
107 return nil, err
108 }
109
110 return out, nil
111}
112
113// parseKV parses a key/value pair into the appropriate field of c.
114func (c *Crypto) parseKV(k, v string) error {

Callers 1

CryptoMethod · 0.85

Calls 2

parseKVMethod · 0.80
ErrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…