Skip to content

Commit 56c82ed

Browse files
committed
WIP
1 parent c8e1b01 commit 56c82ed

File tree

1 file changed

+8
-4
lines changed
  • libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding

1 file changed

+8
-4
lines changed

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import Cardano.Crypto.DSIGN.Class (
2626
SignedDSIGN,
2727
VerKeyDSIGN,
2828
)
29-
import Cardano.Crypto.Hash.Class (Hash, HashAlgorithm, hashFromBytesShort)
29+
import Cardano.Crypto.Hash.Class (Hash, HashAlgorithm, PackedBytes, hashFromPackedBytes)
3030
import Cardano.Crypto.KES.Class (KESAlgorithm, SigKES, VerKeyKES)
31+
import Cardano.Crypto.PackedBytes (packByteString)
3132
import Cardano.Crypto.VRF.Class (
3233
CertVRF,
3334
CertifiedVRF (..),
@@ -56,6 +57,7 @@ import Codec.CBOR.Term (Term (..))
5657
import Codec.Serialise as Serialise (Serialise (decode))
5758
import qualified Data.ByteString as BS
5859
import qualified Data.ByteString.Lazy as BSL
60+
import GHC.TypeLits (KnownNat)
5961
#if MIN_VERSION_bytestring(0,11,1)
6062
import Data.ByteString.Short (ShortByteString(SBS))
6163
#else
@@ -472,10 +474,12 @@ instance (DSIGNAlgorithm v, Typeable a) => DecCBOR (SignedDSIGN v a) where
472474
-- Hash
473475
--------------------------------------------------------------------------------
474476

477+
instance KnownNat n => DecCBOR (PackedBytes n) where
478+
decCBOR = decCBOR >>= packByteString
479+
{-# INLINE decCBOR #-}
480+
475481
instance (HashAlgorithm h, Typeable a) => DecCBOR (Hash h a) where
476-
decCBOR = do
477-
sbs <- decCBOR @ShortByteString
478-
maybe (fail "Invalid hash size") pure $ hashFromBytesShort sbs
482+
decCBOR = hashFromPackedBytes <$> decCBOR
479483
{-# INLINE decCBOR #-}
480484

481485
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)