in EVChecker/main.go [182:233]
func extractFingerprint(r io.RuneReader) (string, error) {
_, err := consumeWhiteSpace(r)
if err != nil {
return "", errors.Wrap(err, "failed to consume the whitespace prefixing a fingerprint")
}
str := strings.Builder{}
for i := 0; i < 32; i++ {
zero, err := consumeWhiteSpace(r)
if err != nil {
return "", errors.Wrap(err, "failed to consume whitespace while extracting fingerprint")
}
if zero != '0' {
return "", errors.New(fmt.Sprintf(`Expected the character "0" while decoding hex, got "%s"`, string(zero)))
}
x, _, err := r.ReadRune() // read the x in 0xAA
if err != nil {
return "", errors.Wrap(err, `failed to read the "x" in a hex literal`)
}
if x != 'x' {
return "", errors.New(fmt.Sprintf(`Expected the character "x" while decoding hex, got "%s"`, string(x)))
}
b, _, err := r.ReadRune() // get the upper byte of 0xAA
if err != nil {
return "", errors.Wrap(err, `failed to read the upper byte in a hex literal`)
}
str.WriteRune(b)
b, _, err = r.ReadRune() // get the lower byte of 0xAA
if err != nil {
return "", errors.Wrap(err, `failed to read the lower byte in a hex literal`)
}
str.WriteRune(b)
comma, _, err := r.ReadRune() // read the , in the array literal
if err != nil {
return "", errors.Wrap(err, `failed to read the hex literal array delimiter`)
}
if comma != ',' && comma != ' ' {
return "", errors.New(fmt.Sprintf(`Expected the character "," or " " while decoding the internals of a hex array, got "%s"`, string(x)))
}
}
brace, err := consumeWhiteSpace(r)
if err != nil {
return "", errors.Wrap(err, "failed to consume the closing brace while extracting a fingerprint")
}
if brace != '}' {
return "", errors.New(fmt.Sprintf(`Expected the character "}" while decoding a hex array, got "%s"`, string(brace)))
}
comma, err := consumeWhiteSpace(r)
if comma != ',' {
return "", errors.New(fmt.Sprintf(`Expected the character "," while decoding the end of a hex array, got "%s"`, string(comma)))
}
return str.String(), nil
}