Pkcs7.hs (839B)
1 {-# LANGUAGE OverloadedStrings #-} 2 {-# LANGUAGE RecordWildCards #-} 3 4 module Main where 5 6 import qualified Cryptopals.Util as CU 7 import qualified Data.Text as T 8 import qualified Data.Text.IO as TIO 9 import qualified Data.Text.Encoding as TE 10 import qualified Options.Applicative as O 11 import qualified System.IO as SIO 12 13 data Args = Args { 14 argsPad :: Int 15 , argsInp :: T.Text 16 } 17 18 ops :: O.Parser Args 19 ops = Args 20 <$> O.argument O.auto (O.metavar "BYTES") 21 <*> O.argument O.str (O.metavar "INPUT") 22 23 pkcs :: Args -> IO () 24 pkcs Args {..} = do 25 let b = CU.pkcs7 argsPad (TE.encodeUtf8 argsInp) 26 TIO.putStr . TE.decodeUtf8 $ b 27 28 main :: IO () 29 main = do 30 let pars = O.info (O.helper <*> ops) $ 31 O.fullDesc 32 <> O.progDesc "pad INPUT to BYTES via PKCS#7" 33 <> O.header "pkcs7" 34 35 args <- O.execParser pars 36 37 pkcs args 38