github.com/linuxboot/fiano@v1.2.0/pkg/amd/psb/util.go (about) 1 // Copyright 2023 the LinuxBoot Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package psb 6 7 import ( 8 "fmt" 9 ) 10 11 func reverse(s []byte) []byte { 12 if len(s) == 0 { 13 return nil 14 } 15 d := make([]byte, len(s)) 16 copy(d, s) 17 18 for right := len(d)/2 - 1; right >= 0; right-- { 19 left := len(d) - 1 - right 20 d[right], d[left] = d[left], d[right] 21 } 22 return d 23 } 24 25 func checkBoundaries(start, end uint64, blob []byte) error { 26 if start > uint64(len(blob)) { 27 return fmt.Errorf("boundary check error: start is beyond blob boundary (%d > %d)", start, len(blob)) 28 } 29 if end > uint64(len(blob)) { 30 return fmt.Errorf("boundary check error: start is beyond blob boundary (%d > %d)", end, len(blob)) 31 } 32 if start > end { 33 return fmt.Errorf("boundary check error: start > end (%d > %d)", start, end) 34 } 35 return nil 36 }