Skip to content

Commit a4dbefd

Browse files
Revert "Validate ocert counter, change encoding of validation failures"
only encoding changes were reverted - this reversion should be undone later when API is more stable This reverts commit a2807a6.
1 parent 6d1d12b commit a4dbefd

File tree

1 file changed

+6
-43
lines changed
  • dmq-node/src/DMQ/Protocol/LocalMsgSubmission

1 file changed

+6
-43
lines changed

dmq-node/src/DMQ/Protocol/LocalMsgSubmission/Codec.hs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import Codec.CBOR.Read qualified as CBOR
1111
import Control.Monad.Class.MonadST
1212
import Data.ByteString.Lazy (ByteString)
1313
import Data.Text qualified as T
14-
import Data.Tuple (swap)
1514
import Text.Printf
1615

17-
import Cardano.Binary
1816
import Cardano.KESAgent.KES.Crypto (Crypto (..))
1917

2018
import DMQ.Protocol.LocalMsgSubmission.Type
@@ -38,53 +36,18 @@ codecLocalMsgSubmission =
3836

3937
encodeReject :: TxValidationFail (Sig crypto) -> CBOR.Encoding
4038
encodeReject = \case
41-
SigInvalid reason -> CBOR.encodeListLen 2 <> CBOR.encodeWord8 0 <> e
42-
where
43-
e = case reason of
44-
InvalidKESSignature ocertKESPeriod sigKESPeriod err -> mconcat [
45-
CBOR.encodeListLen 4, CBOR.encodeWord8 0, toCBOR ocertKESPeriod, toCBOR sigKESPeriod, CBOR.encodeString (T.pack err)
46-
]
47-
InvalidSignatureOCERT ocertN sigKESPeriod err -> mconcat [
48-
CBOR.encodeListLen 4, CBOR.encodeWord8 1, CBOR.encodeWord64 ocertN, toCBOR sigKESPeriod, CBOR.encodeString (T.pack err)
49-
]
50-
KESBeforeStartOCERT startKESPeriod sigKESPeriod -> mconcat [
51-
CBOR.encodeListLen 3, CBOR.encodeWord8 2, toCBOR startKESPeriod, toCBOR sigKESPeriod
52-
]
53-
KESAfterEndOCERT endKESPeriod sigKESPeriod -> mconcat [
54-
CBOR.encodeListLen 3, CBOR.encodeWord8 3, toCBOR endKESPeriod, toCBOR sigKESPeriod
55-
]
56-
UnrecognizedPool -> CBOR.encodeListLen 1 <> CBOR.encodeWord8 4
57-
NotInitialized -> CBOR.encodeListLen 1 <> CBOR.encodeWord8 5
58-
ClockSkew -> CBOR.encodeListLen 1 <> CBOR.encodeWord8 6
59-
InvalidOCertCounter seen received
60-
-> mconcat
61-
[CBOR.encodeListLen 3, CBOR.encodeWord8 7, CBOR.encodeWord64 seen, CBOR.encodeWord64 received]
62-
SigDuplicate -> CBOR.encodeListLen 1 <> CBOR.encodeWord8 1
63-
SigExpired -> CBOR.encodeListLen 1 <> CBOR.encodeWord8 2
39+
SigInvalid reason -> CBOR.encodeListLen 2 <> CBOR.encodeWord 0 <> CBOR.encodeString (T.pack . show $ reason)
40+
SigDuplicate -> CBOR.encodeListLen 1 <> CBOR.encodeWord 1
41+
SigExpired -> CBOR.encodeListLen 1 <> CBOR.encodeWord 2
6442
SigResultOther reason
65-
-> CBOR.encodeListLen 2 <> CBOR.encodeWord8 3 <> CBOR.encodeString reason
43+
-> CBOR.encodeListLen 2 <> CBOR.encodeWord 3 <> CBOR.encodeString (T.pack . show $ reason)
6644

6745
decodeReject :: CBOR.Decoder s (TxValidationFail (Sig crypto))
6846
decodeReject = do
6947
len <- CBOR.decodeListLen
70-
tag <- CBOR.decodeWord8
48+
tag <- CBOR.decodeWord
7149
case (tag, len) of
72-
(0, 2) -> SigInvalid <$> decSigValidError
73-
where
74-
decSigValidError :: CBOR.Decoder s SigValidationError
75-
decSigValidError = do
76-
lenTag <- (,) <$> CBOR.decodeListLen <*> CBOR.decodeWord8
77-
case swap lenTag of
78-
(0, 4) -> InvalidKESSignature <$> fromCBOR <*> fromCBOR <*> (T.unpack <$> CBOR.decodeString)
79-
(1, 4) -> InvalidSignatureOCERT <$> CBOR.decodeWord64 <*> fromCBOR <*> (T.unpack <$> CBOR.decodeString)
80-
(2, 3) -> KESBeforeStartOCERT <$> fromCBOR <*> fromCBOR
81-
(3, 4) -> KESAfterEndOCERT <$> fromCBOR <*> fromCBOR
82-
(4, 1) -> pure UnrecognizedPool
83-
(5, 1) -> pure NotInitialized
84-
(6, 1) -> pure ClockSkew
85-
(7, 3) -> InvalidOCertCounter <$> fromCBOR <*> fromCBOR
86-
_otherwise -> fail $ printf "unrecognized (tag,len) = (%d, %d) when decoding SigInvalid tag" tag len
87-
50+
(0, 2) -> {- FIXME SigInvalid -} SigResultOther <$> CBOR.decodeString
8851
(1, 1) -> pure SigDuplicate
8952
(2, 1) -> pure SigExpired
9053
(3, 2) -> SigResultOther <$> CBOR.decodeString

0 commit comments

Comments
 (0)