Skip to content

Commit

Permalink
Remove unnecessary readSigningKeyFileAnyOf and readSigningKeyFile fro…
Browse files Browse the repository at this point in the history
…m cardano-cli
  • Loading branch information
Jordan committed Dec 7, 2022
1 parent 02050ba commit 45557f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 52 deletions.
40 changes: 1 addition & 39 deletions cardano-cli/src/Cardano/CLI/Shelley/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

-- | Shelley CLI option data types and functions for cryptographic keys.
module Cardano.CLI.Shelley.Key
( readSigningKeyFile
, readSigningKeyFileAnyOf

, VerificationKeyOrFile (..)
( VerificationKeyOrFile (..)
, readVerificationKeyOrFile
, readVerificationKeyOrTextEnvFile

Expand Down Expand Up @@ -38,41 +35,6 @@ import qualified Data.Text.Encoding as Text

import Cardano.CLI.Types

------------------------------------------------------------------------------
-- Signing key deserialisation
------------------------------------------------------------------------------

-- | Read a signing key from a file.
--
-- The contents of the file can either be Bech32-encoded, hex-encoded, or in
-- the text envelope format.
readSigningKeyFile
:: forall keyrole.
( HasTextEnvelope (SigningKey keyrole)
, SerialiseAsBech32 (SigningKey keyrole)
)
=> AsType keyrole
-> SigningKeyFile
-> IO (Either (FileError InputDecodeError) (SigningKey keyrole))
readSigningKeyFile asType (SigningKeyFile fp) =
readKeyFile
(AsSigningKey asType)
(NE.fromList [InputFormatBech32, InputFormatHex, InputFormatTextEnvelope])
fp

-- | Read a signing key from a file given that it is one of the provided types
-- of signing key.
--
-- The contents of the file can either be Bech32-encoded or in the text
-- envelope format.
readSigningKeyFileAnyOf
:: forall b.
[FromSomeType SerialiseAsBech32 b]
-> [FromSomeType HasTextEnvelope b]
-> SigningKeyFile
-> IO (Either (FileError InputDecodeError) b)
readSigningKeyFileAnyOf bech32Types textEnvTypes (SigningKeyFile fp) =
readKeyFileAnyOf bech32Types textEnvTypes fp

------------------------------------------------------------------------------
-- Verification key deserialisation
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import Cardano.Api.Shelley
import qualified Cardano.CLI.Byron.Key as Byron
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (VerificationKeyTextOrFile (..),
VerificationKeyTextOrFileError, readSigningKeyFileAnyOf,
readVerificationKeyTextOrFileAnyOf, renderVerificationKeyTextOrFileError)
VerificationKeyTextOrFileError, readVerificationKeyTextOrFileAnyOf,
renderVerificationKeyTextOrFileError)
import Cardano.CLI.Types (SigningKeyFile (..), VerificationKeyFile (..))


Expand Down Expand Up @@ -156,9 +156,9 @@ withSomeSigningKey ssk f =
readSigningKeyFile
:: SigningKeyFile
-> ExceptT (FileError InputDecodeError) IO SomeSigningKey
readSigningKeyFile skFile =
readSigningKeyFile (SigningKeyFile skFile) =
newExceptT $
readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
where
textEnvFileTypes =
[ FromSomeType (AsSigningKey AsByronKey)
Expand Down
7 changes: 3 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readSigningKeyFileAnyOf,
readVerificationKeyOrFile)
import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile)
import Cardano.CLI.Types (SigningKeyFile (..), VerificationKeyFile (..))

{- HLINT ignore "Reduce duplication" -}
Expand Down Expand Up @@ -178,7 +177,7 @@ runNodeIssueOpCert :: VerificationKeyOrFile KesKey
-> OutputFile
-> ExceptT ShelleyNodeCmdError IO ()
runNodeIssueOpCert kesVerKeyOrFile
stakePoolSKeyFile
(SigningKeyFile stakePoolSKeyFile)
(OpCertCounterFile ocertCtrPath)
kesPeriod
(OutputFile certFile) = do
Expand All @@ -193,7 +192,7 @@ runNodeIssueOpCert kesVerKeyOrFile

signKey <- firstExceptT ShelleyNodeCmdReadKeyFileError
. newExceptT
$ readSigningKeyFileAnyOf
$ readKeyFileAnyOf
bech32PossibleBlockIssuers
textEnvPossibleBlockIssuers
stakePoolSKeyFile
Expand Down
9 changes: 4 additions & 5 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import Cardano.Api.Shelley
import qualified Cardano.Binary as CBOR
import Data.Text (Text)

import Cardano.CLI.Shelley.Key
import Cardano.CLI.Shelley.Parsers
import Cardano.CLI.Types

Expand Down Expand Up @@ -640,9 +639,9 @@ renderReadWitnessSigningDataError err =
readWitnessSigningData
:: WitnessSigningData
-> IO (Either ReadWitnessSigningDataError SomeWitness)
readWitnessSigningData (KeyWitnessSigningData skFile mbByronAddr) = do
readWitnessSigningData (KeyWitnessSigningData (SigningKeyFile skFile) mbByronAddr) = do
eRes <- first ReadWitnessSigningDataSigningKeyDecodeError
<$> readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
<$> readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
return $ do
res <- eRes
case (res, mbByronAddr) of
Expand Down Expand Up @@ -706,8 +705,8 @@ instance Error RequiredSignerError where

readRequiredSigner :: RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey))
readRequiredSigner (RequiredSignerHash h) = return $ Right h
readRequiredSigner (RequiredSignerSkeyFile skFile) = do
eKeyWit <- first RequiredSignerErrorFile <$> readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile
readRequiredSigner (RequiredSignerSkeyFile skFile@(SigningKeyFile skFp)) = do
eKeyWit <- first RequiredSignerErrorFile <$> readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFp
return $ do
keyWit <- eKeyWit
case categoriseSomeWitness keyWit of
Expand Down

0 comments on commit 45557f4

Please sign in to comment.