X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=internal%2Fgost34112012%2Fhash.go;h=f50b3c15235fc2337a870e997f75cba088bf3b4d;hb=c40d1e5634cf6d540d908a57423f4b504e39f186;hp=5f6b707d87a05a001326d464693406e10aa60672;hpb=c07494bbd559b9d00f391e28cfd070e18afe9900;p=gogost.git diff --git a/internal/gost34112012/hash.go b/internal/gost34112012/hash.go index 5f6b707..f50b3c1 100644 --- a/internal/gost34112012/hash.go +++ b/internal/gost34112012/hash.go @@ -1,5 +1,5 @@ // GoGOST -- Pure Go GOST cryptographic functions library -// Copyright (C) 2015-2019 Sergey Matveev +// Copyright (C) 2015-2020 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ import ( "bytes" "encoding/binary" "errors" + "fmt" ) const ( @@ -426,11 +427,12 @@ func (h *Hash) MarshalBinary() (data []byte, err error) { } func (h *Hash) UnmarshalBinary(data []byte) error { - if len(data) < len(MarshaledName)+1+8+3*BlockSize { - return errors.New("too short data") + expectedLen := len(MarshaledName) + 1 + 8 + 3*BlockSize + if len(data) < expectedLen { + return fmt.Errorf("gogost/internal/gost34112012: len(data) != %d", expectedLen) } if !bytes.HasPrefix(data, []byte(MarshaledName)) { - return errors.New("no hash name prefix") + return errors.New("gogost/internal/gost34112012: no hash name prefix") } idx := len(MarshaledName) h.size = int(data[idx])