1+ {-# OPTIONS_GHC -Wno-redundant-constraints #-}
2+
13{-# LANGUAGE DataKinds #-}
24{-# LANGUAGE DerivingVia #-}
35{-# LANGUAGE EmptyCase #-}
@@ -30,10 +32,10 @@ import Data.Typeable
3032import Data.Word
3133import Network.TypedProtocol.Core
3234
33- data AgentInfo c =
35+ data AgentInfo =
3436 AgentInfo
35- { agentInfoCurrentBundle :: ! (Maybe ( BundleInfo c ) )
36- , agentInfoStagedKey :: ! (Maybe ( KeyInfo c ) )
37+ { agentInfoCurrentBundle :: ! (Maybe BundleInfo )
38+ , agentInfoStagedKey :: ! (Maybe KeyInfo )
3739 , agentInfoBootstrapConnections :: ! [BootstrapInfo ]
3840 }
3941 deriving (Show , Eq )
@@ -50,7 +52,6 @@ deriving via (ViaEnum Command)
5052 instance
5153 ( Codec codec
5254 , HasInfo codec (DefEnumEncoding codec )
53- , Integral (DefEnumEncoding codec )
5455 ) => HasInfo codec Command
5556
5657instance
@@ -63,16 +64,16 @@ instance
6364 encode codec = encodeEnum codec (Proxy @ (DefEnumEncoding codec ))
6465 decode codec = decodeEnum codec (Proxy @ (DefEnumEncoding codec ))
6566
66- newtype FakeKey k = FakeKey { fakeKeyData :: ByteString }
67+ newtype FakeKey = FakeKey { fakeKeyData :: ByteString }
6768 deriving (Show , Eq , Ord )
6869
6970newtype VersionIdentifier = VersionIdentifier { versionIdentifierData :: ByteString }
7071 deriving (Show , Eq , Ord )
7172
72- instance HasInfo ( TestCodec () ) VersionIdentifier where
73+ instance HasInfo TestCodec VersionIdentifier where
7374 info _ _ = basicField " Bytes" (FixedSize 32 )
7475
75- instance HasInfo ( TestCodec () ) ( FakeKey k ) where
76+ instance HasInfo TestCodec FakeKey where
7677 info _ _ = basicField " Bytes" (FixedSize 128 )
7778
7879data BootstrapInfo =
@@ -92,25 +93,25 @@ deriving via (ViaEnum ConnectionStatus)
9293 instance (Codec codec , HasInfo codec (DefEnumEncoding codec ))
9394 => HasInfo codec ConnectionStatus
9495
95- data BundleInfo c =
96+ data BundleInfo =
9697 BundleInfo
9798 { bundleInfoEvolution :: ! Word32
9899 , bundleInfoOCertN :: ! Word64
99- , bundleInfoVK :: ! ( FakeKey c )
100+ , bundleInfoVK :: ! FakeKey
100101 }
101102 deriving (Show , Eq )
102103
103- newtype KeyInfo c =
104+ newtype KeyInfo =
104105 KeyInfo
105- { keyInfoVK :: FakeKey c
106+ { keyInfoVK :: FakeKey
106107 }
107108 deriving (Show , Eq )
108109
109110deriving newtype
110111 instance
111- ( HasInfo codec ( FakeKey c )
112+ ( HasInfo codec FakeKey
112113 , Codec codec
113- ) => HasInfo codec ( KeyInfo c )
114+ ) => HasInfo codec KeyInfo
114115
115116$ (deriveSerDoc ''TestCodec [] ''BundleInfo)
116117$ (deriveSerDoc ''TestCodec [] ''BootstrapInfo)
@@ -129,27 +130,27 @@ $(deriveSerDoc ''TestCodec [] ''AgentInfo)
129130-- through. This allows the control client to report success to the user, but it
130131-- also helps make things more predictable in testing, because it means that
131132-- sending keys is now synchronous.
132- data ControlProtocol (m :: Type -> Type ) (k :: Type ) where
133+ data ControlProtocol (m :: Type -> Type ) (c :: Type ) where
133134 -- | Default state after connecting, but before the protocol version has been
134135 -- negotiated.
135- InitialState :: ControlProtocol m k
136+ InitialState :: ControlProtocol m c
136137
137138 -- | System is idling, waiting for the server to push the next key.
138- IdleState :: ControlProtocol m k
139+ IdleState :: ControlProtocol m c
139140
140141 -- | Client has requested a new KES key to be generated in the staging area.
141- WaitForPublicKeyState :: ControlProtocol m k
142+ WaitForPublicKeyState :: ControlProtocol m c
142143
143144 -- | Client has requested agent information
144- WaitForInfoState :: ControlProtocol m k
145+ WaitForInfoState :: ControlProtocol m c
145146
146147 -- | An OpCert has been pushed, client must now confirm that it has been
147148 -- received, and that it matches the staged KES key.
148- WaitForConfirmationState :: ControlProtocol m k
149+ WaitForConfirmationState :: ControlProtocol m c
149150
150151 -- | The server has closed the connection, thus signalling the end of the
151152 -- session.
152- EndState :: ControlProtocol m k
153+ EndState :: ControlProtocol m c
153154
154155{-# ANN VersionMessage (Description ["Announce the protocol version."]) #-}
155156{-# ANN GenStagedKeyMessage
@@ -217,61 +218,49 @@ instance Protocol (ControlProtocol m c) where
217218
218219 DropStagedKeyMessage :: Message (ControlProtocol m c ) IdleState WaitForPublicKeyState
219220
220- PublicKeyMessage :: Maybe ( FakeKey c )
221+ PublicKeyMessage :: Maybe FakeKey
221222 -> Message (ControlProtocol m c ) WaitForPublicKeyState IdleState
222223
223- InstallKeyMessage :: FakeKey c
224+ InstallKeyMessage :: FakeKey
224225 -> Message (ControlProtocol m c ) IdleState WaitForConfirmationState
225226
226227 InstallResultMessage :: Word32
227228 -> Message (ControlProtocol m c ) WaitForConfirmationState IdleState
228229
229230 RequestInfoMessage :: Message (ControlProtocol m c ) IdleState WaitForInfoState
230231
231- InfoMessage :: AgentInfo c
232+ InfoMessage :: AgentInfo
232233 -> Message (ControlProtocol m c ) WaitForInfoState IdleState
233234
234235 AbortMessage :: Message (ControlProtocol m c ) InitialState EndState
235236 EndMessage :: Message (ControlProtocol m c ) IdleState EndState
236237 ProtocolErrorMessage :: Message (ControlProtocol m c ) a EndState
237238
238239 -- | Server always has agency, except between sending a key and confirming it
239- data ServerHasAgency st where
240- TokInitial :: ServerHasAgency InitialState
241- TokIdle :: ServerHasAgency IdleState
242-
243- -- | Client only has agency between sending a key and confirming it
244- data ClientHasAgency st where
245- TokWaitForConfirmation :: ClientHasAgency WaitForConfirmationState
246- TokWaitForPublicKey :: ClientHasAgency WaitForPublicKeyState
247- TokWaitForInfo :: ClientHasAgency WaitForInfoState
248-
249- -- | Someone, i.e., the server, always has agency
250- data NobodyHasAgency st where
251- TokEnd :: NobodyHasAgency EndState
252-
253- exclusionLemma_ClientAndServerHaveAgency tok1 tok2 =
254- case tok1 of
255- TokWaitForConfirmation ->
256- case tok2 of {}
257- TokWaitForPublicKey ->
258- case tok2 of {}
259- TokWaitForInfo ->
260- case tok2 of {}
261- exclusionLemma_NobodyAndClientHaveAgency tok1 tok2 =
262- case tok1 of
263- TokEnd -> case tok2 of {}
264- exclusionLemma_NobodyAndServerHaveAgency tok1 tok2 =
265- case tok1 of
266- TokEnd -> case tok2 of {}
267-
268- instance HasInfo (TestCodec () ) (Message (ControlProtocol m c ) InitialState IdleState ) where
240+ type StateAgency InitialState = ServerAgency
241+ type StateAgency IdleState = ServerAgency
242+ type StateAgency WaitForConfirmationState = ClientAgency
243+ type StateAgency WaitForPublicKeyState = ClientAgency
244+ type StateAgency WaitForInfoState = ClientAgency
245+ type StateAgency EndState = NobodyAgency
246+
247+ type StateToken = SControlProtocol
248+
249+ data SControlProtocol (st :: ControlProtocol m c ) where
250+ SInitialState :: SControlProtocol InitialState
251+ SIdleState :: SControlProtocol IdleState
252+ SWaitForConfirmationState :: SControlProtocol WaitForConfirmationState
253+ SWaitForPublicKeyState :: SControlProtocol WaitForPublicKeyState
254+ SWaitForInfoState :: SControlProtocol WaitForInfoState
255+ SEndState :: SControlProtocol EndState
256+
257+ instance HasInfo TestCodec (Message (ControlProtocol m c ) InitialState IdleState ) where
269258 info codec _ = aliasField
270259 (" Message<" ++
271260 " InitialState,IdleState" ++
272261 " >" )
273262 (info codec (Proxy @ VersionIdentifier ))
274- instance HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) IdleState WaitForPublicKeyState ) where
263+ instance HasInfo TestCodec (Message (ControlProtocol m c ) IdleState WaitForPublicKeyState ) where
275264 info codec _ = aliasField
276265 (" Message<" ++
277266 " IdleState,WaitForPublicKeyState" ++
@@ -283,39 +272,39 @@ instance HasInfo (TestCodec ()) (Message (ControlProtocol m c) IdleState WaitFor
283272-- QueryStagedKeyMessage -> infoOf QueryStagedKeyCmd
284273-- DropStagedKeyMessage -> infoOf DropStagedKeyCmd
285274
286- instance (HasInfo ( TestCodec () ) ( FakeKey c )) => HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) WaitForPublicKeyState IdleState ) where
275+ instance (HasInfo TestCodec FakeKey ) => HasInfo TestCodec (Message (ControlProtocol m c ) WaitForPublicKeyState IdleState ) where
287276 info codec _ = aliasField
288277 (" Message<" ++
289278 " WaitForPublicKeyState,IdleState" ++
290279 " >" )
291- (info codec (Proxy @ (Maybe ( FakeKey c ) )))
292- instance (HasInfo ( TestCodec () ) ( FakeKey c )) => HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) IdleState WaitForConfirmationState ) where
280+ (info codec (Proxy @ (Maybe FakeKey )))
281+ instance (HasInfo TestCodec FakeKey ) => HasInfo TestCodec (Message (ControlProtocol m c ) IdleState WaitForConfirmationState ) where
293282 info codec _ = aliasField
294283 (" Message<" ++
295284 " IdleState,WaitForConfirmationState" ++
296285 " >" )
297- (info codec (Proxy @ ( FakeKey c ) ))
298- instance HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) WaitForConfirmationState IdleState ) where
286+ (info codec (Proxy @ FakeKey ))
287+ instance HasInfo TestCodec (Message (ControlProtocol m c ) WaitForConfirmationState IdleState ) where
299288 info codec _ = aliasField
300289 (" Message<" ++
301290 " WaitForConfirmationState,IdleState" ++
302291 " >" )
303292 (info codec (Proxy @ Word32 ))
304- instance HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) IdleState WaitForInfoState ) where
293+ instance HasInfo TestCodec (Message (ControlProtocol m c ) IdleState WaitForInfoState ) where
305294 info codec _ = aliasField
306295 (" Message<" ++
307296 " IdleState,WaitForInfoState" ++
308297 " >" )
309298 (info codec (Proxy @ () ))
310- instance ( HasInfo ( TestCodec () ) ( FakeKey c )
311- , HasInfo ( TestCodec () ) ( AgentInfo c )
312- ) => HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) WaitForInfoState IdleState ) where
299+ instance ( HasInfo TestCodec FakeKey
300+ , HasInfo TestCodec AgentInfo
301+ ) => HasInfo TestCodec (Message (ControlProtocol m c ) WaitForInfoState IdleState ) where
313302 info codec _ = aliasField
314303 (" Message<" ++
315304 " WaitForInfoState,IdleState" ++
316305 " >" )
317- (info codec (Proxy @ ( AgentInfo c ) ))
318- instance HasInfo ( TestCodec () ) (Message (ControlProtocol m c ) _st EndState ) where
306+ (info codec (Proxy @ AgentInfo ))
307+ instance HasInfo TestCodec (Message (ControlProtocol m c ) _st EndState ) where
319308 info codec _ = aliasField
320309 (" Message<" ++
321310 " st,EndState" ++
0 commit comments