| 242 | } |
| 243 | |
| 244 | func parseSerialBytes(serial []byte) ([]byte, error) { |
| 245 | res := make([]byte, (len(serial)+2)/3) |
| 246 | |
| 247 | var i int |
| 248 | for ; i < len(res) && i*3+1 < len(serial); i++ { |
| 249 | if _, err := hex.Decode(res[i:i+1], serial[i*3:i*3+2]); err != nil { |
| 250 | return nil, fmt.Errorf("parseSerialBytes() failed: %w", err) |
| 251 | } |
| 252 | if i*3+2 < len(serial) && serial[i*3+2] != ':' { |
| 253 | return nil, errors.New("missing colon delimiter") |
| 254 | } |
| 255 | } |
| 256 | if i < len(res) { |
| 257 | return nil, errors.New("incomplete serial number string") |
| 258 | } |
| 259 | |
| 260 | return res, nil |
| 261 | } |