From a15059b0452ba9d730404ce5c5a6b91a3828fdbc Mon Sep 17 00:00:00 2001 From: joe Date: Sat, 27 Aug 2016 04:29:39 -0400 Subject: Replaced dataenc with memory. --- kiki.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 3eb1d2a..a0eff1a 100644 --- a/kiki.hs +++ b/kiki.hs @@ -34,7 +34,12 @@ import System.Directory import System.Environment import System.Exit import System.IO (hPutStrLn,stderr) +#if defined(VERSION_memory) +import qualified Data.ByteString.Char8 as S8 +import Data.ByteArray.Encoding +#elif defined(VERSION_dataenc) import qualified Codec.Binary.Base64 as Base64 +#endif import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar.Entry as Tar #if !defined(VERSION_cryptonite) @@ -69,6 +74,7 @@ import Data.Time.Clock.POSIX ( posixSecondsToUTCTime ) import Kiki import Debug.Trace import Network.Socket (SockAddr) +import FunctorToMaybe -- {-# ANN module ("HLint: ignore Eta reduce"::String) #-} -- {-# ANN module ("HLint: ignore Use camelCase"::String) #-} @@ -316,7 +322,11 @@ dnsPresentationFromPacket k = do let RSAKey (MPI n) (MPI e) = fromJust $ rsaKeyFromPacket k dnskey = DNS.RSA n e bin = runPut (DNS.putRSA dnskey) +#if defined(VERSION_memory) + qq = S8.unpack $ convertToBase Base64 (L.toStrict bin) +#elif defined(VERSION_dataenc) qq = Base64.encode (L.unpack bin) +#endif ttl = 24*60*60 -- 24 hours in seconds flags = 256 -- (ZONE-key = bit7) TODO: is this a zone key or a key-signing key? algo = 8 -- RSASHA256 -- TODO: support other algorithm @@ -351,7 +361,11 @@ show_wip keyspec wkgrip db = do show_torhash pubkey _ = do bs <- Char8.readFile pubkey let parsekey f dta = do +#if defined(VERSION_memory) + let mdta = fmap L.fromStrict $ functorToMaybe $ convertFromBase Base64 (Char8.toStrict dta) +#elif defined(VERSION_dataenc) let mdta = L.pack <$> Base64.decode (Char8.unpack dta) +#endif e <- decodeASN1 DER <$> mdta asn1 <- either (const Nothing) (Just) e k <- either (const Nothing) (Just . fst) (fromASN1 asn1) @@ -381,7 +395,11 @@ show_cert keyspec wkgrip db = do -} let cs = mapMaybe x509cert $ (sigs >>= hashed_subpackets) ds = map decodeBlob $ map (ParsedCert k (posixSecondsToUTCTime $ fromIntegral $ timestamp k)) cs +#if defined(VERSION_memory) + qqs = map (S8.unpack . convertToBase Base64 . L.toStrict) ds +#elif defined(VERSION_dataenc) qqs = map (Base64.encode . L.unpack) ds +#endif pems = map (writePEM "CERTIFICATE") qqs forM_ pems putStrLn _ -> void $ warn (keyspec ++ ": ambiguous") -- cgit v1.2.3