in imfg/imfg.go [230:252]
func replaceKey(mfgBin []byte, okey []byte, nkey []byte) (int, error) {
if len(okey) > len(mfgBin) {
return 0, errors.Errorf(
"key longer than flash section (%d > %d)", len(okey), len(mfgBin))
}
idx := bytes.Index(mfgBin, okey)
if idx == -1 {
return 0, errors.Errorf("old key not present in flash section")
}
lastIdx := bytes.LastIndex(mfgBin, okey)
if idx != lastIdx {
return 0, errors.Errorf(
"multiple instances of old key in flash section")
}
iutil.PrintfVerbose("Replacing key at offset %d\n", idx)
copy(mfgBin[idx:idx+len(okey)], nkey)
return idx, nil
}