Skip to content

Commit

Permalink
key non-extended-key: make pattern match exhaustive, so that we are n…
Browse files Browse the repository at this point in the history
…otified of possible extensions
  • Loading branch information
smelc committed Apr 9, 2024
1 parent fcd0d1a commit ed8bb88
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ runNonExtendedKeyCmd
{ Cmd.extendedVkeyFileIn = evkf
, Cmd.nonExtendedVkeyFileOut = vkf
} =
writeVerificationKey =<< readExtendedVerificationKeyFile evkf
writeExtendedVerificationKey =<< readExtendedVerificationKeyFile evkf
where
-- TODO: Expose a function specifically for this purpose
-- and explain the extended verification keys can be converted
-- to their non-extended counterparts however this is NOT the case
-- for extended signing keys

writeVerificationKey
writeExtendedVerificationKey
:: SomeAddressVerificationKey
-> ExceptT KeyCmdError IO ()
writeVerificationKey ssk =
writeExtendedVerificationKey ssk =
case ssk of
APaymentExtendedVerificationKey vk ->
writeToDisk vkf (Just paymentVkeyDesc) (castVerificationKey vk :: VerificationKey PaymentKey)
Expand All @@ -169,7 +169,16 @@ runNonExtendedKeyCmd
writeToDisk vkf (Just genesisVkeyDesc) (castVerificationKey vk :: VerificationKey GenesisKey)
AGenesisDelegateExtendedVerificationKey vk ->
writeToDisk vkf (Just genesisVkeyDelegateDesc) (castVerificationKey vk :: VerificationKey GenesisDelegateKey)
nonExtendedKey -> left $ KeyCmdExpectedExtendedVerificationKey nonExtendedKey
-- Non-extended keys are below and cause failure.
vk@AByronVerificationKey {} -> goFail vk
vk@APaymentVerificationKey {} -> goFail vk
vk@AGenesisUTxOVerificationKey {} -> goFail vk
vk@AKesVerificationKey {} -> goFail vk
vk@AVrfVerificationKey {} -> goFail vk
vk@AStakeVerificationKey {} -> goFail vk
vk@ADRepVerificationKey {} -> goFail vk
where
goFail nonExtendedKey = left $ KeyCmdExpectedExtendedVerificationKey nonExtendedKey


writeToDisk
Expand All @@ -196,8 +205,16 @@ readExtendedVerificationKeyFile evkfile = do
k@AStakeExtendedVerificationKey{} -> return k
k@AGenesisExtendedVerificationKey{} -> return k
k@AGenesisDelegateExtendedVerificationKey{} -> return k
nonExtendedKey ->
left $ KeyCmdExpectedExtendedVerificationKey nonExtendedKey
-- Non-extended keys are below and cause failure.
k@AByronVerificationKey{} -> goFail k
k@APaymentVerificationKey{} -> goFail k
k@AGenesisUTxOVerificationKey{} -> goFail k
k@AKesVerificationKey{} -> goFail k
k@AVrfVerificationKey{} -> goFail k
k@AStakeVerificationKey{} -> goFail k
k@ADRepVerificationKey{} -> goFail k
where
goFail k = left $ KeyCmdExpectedExtendedVerificationKey k


runConvertByronKeyCmd
Expand Down

0 comments on commit ed8bb88

Please sign in to comment.