accumulate gathers n bytes from f and returns them as a string. It returns an empty string when f returns an error.
(n int, f func() (byte, error))
| 20 | // accumulate gathers n bytes from f and returns them as a string. It returns |
| 21 | // an empty string when f returns an error. |
| 22 | func accumulate(n int, f func() (byte, error)) (string, error) { |
| 23 | result := make([]byte, n) |
| 24 | |
| 25 | for i := range result { |
| 26 | if b, err := f(); err == nil { |
| 27 | result[i] = b |
| 28 | } else { |
| 29 | return "", err |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return string(result), nil |
| 34 | } |
| 35 | |
| 36 | // randomCharacter builds a function that returns random bytes from class. |
| 37 | func randomCharacter(random io.Reader, class string) func() (byte, error) { |
no outgoing calls