dissertation-2-code/mocks/mac.go

26 lines
362 B
Go
Raw Normal View History

2020-10-25 21:44:56 +00:00
package mocks
2020-11-27 20:17:59 +00:00
import (
"mpbl3p/shared"
)
2020-10-25 21:44:56 +00:00
2021-05-13 22:11:07 +01:00
type AlmostUselessMac string
2020-10-25 21:44:56 +00:00
2021-05-13 22:11:07 +01:00
func (a AlmostUselessMac) CodeLength() int {
return len(a)
2020-10-25 21:44:56 +00:00
}
2021-05-13 22:11:07 +01:00
func (a AlmostUselessMac) Generate([]byte) []byte {
return []byte(a)
2020-10-25 21:44:56 +00:00
}
2021-05-13 22:11:07 +01:00
func (a AlmostUselessMac) Verify(_, sum []byte) error {
for i, c := range sum {
if a[i] != c {
return shared.ErrBadChecksum
}
2020-10-25 21:44:56 +00:00
}
2021-05-13 22:11:07 +01:00
2020-10-25 21:44:56 +00:00
return nil
}