diff options
Diffstat (limited to 'lib/SSHKey.hs')
-rw-r--r-- | lib/SSHKey.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/SSHKey.hs b/lib/SSHKey.hs index 488f55f..bd47169 100644 --- a/lib/SSHKey.hs +++ b/lib/SSHKey.hs | |||
@@ -1,9 +1,16 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE CPP #-} | ||
2 | module SSHKey where | 3 | module SSHKey where |
3 | 4 | ||
4 | import qualified Data.ByteString.Lazy.Char8 as L8 | 5 | import qualified Data.ByteString.Lazy.Char8 as L8 |
5 | import qualified Data.ByteString.Lazy as L | 6 | import qualified Data.ByteString.Lazy as L |
7 | #if defined(VERSION_memory) | ||
8 | import qualified Data.ByteString.Char8 as S8 | ||
9 | import Data.ByteArray.Encoding | ||
10 | import FunctorToMaybe | ||
11 | #elif defined(VERSION_dataenc) | ||
6 | import qualified Codec.Binary.Base64 as Base64 | 12 | import qualified Codec.Binary.Base64 as Base64 |
13 | #endif | ||
7 | import Data.Binary.Get ( runGet ) | 14 | import Data.Binary.Get ( runGet ) |
8 | import Data.Binary.Put ( putWord32be, runPut, putByteString ) | 15 | import Data.Binary.Put ( putWord32be, runPut, putByteString ) |
9 | import Data.Binary ( get, put ) | 16 | import Data.Binary ( get, put ) |
@@ -19,7 +26,11 @@ keyblob :: Key -> L.ByteString | |||
19 | keyblob (n,e) = "ssh-rsa " <> blob | 26 | keyblob (n,e) = "ssh-rsa " <> blob |
20 | where | 27 | where |
21 | bs = sshrsa e n | 28 | bs = sshrsa e n |
29 | #if defined(VERSION_memory) | ||
30 | blob = L.fromStrict $ convertToBase Base64 (L.toStrict bs) | ||
31 | #elif defined(VERSION_dataenc) | ||
22 | blob = L8.pack $ Base64.encode (L.unpack bs) | 32 | blob = L8.pack $ Base64.encode (L.unpack bs) |
33 | #endif | ||
23 | 34 | ||
24 | sshrsa :: Integer -> Integer -> L.ByteString | 35 | sshrsa :: Integer -> Integer -> L.ByteString |
25 | sshrsa e n = runPut $ do | 36 | sshrsa e n = runPut $ do |
@@ -35,7 +46,11 @@ blobkey bs = do | |||
35 | let (sp,bs2) = L8.span isSpace bs1 | 46 | let (sp,bs2) = L8.span isSpace bs1 |
36 | guard $ not (L8.null sp) | 47 | guard $ not (L8.null sp) |
37 | bs3 <- listToMaybe $ L8.words bs2 | 48 | bs3 <- listToMaybe $ L8.words bs2 |
49 | #if defined(VERSION_memory) | ||
50 | qq <- fmap L.fromStrict $ functorToMaybe $ convertFromBase Base64 $ L.toStrict bs3 | ||
51 | #elif defined(VERSION_dataenc) | ||
38 | qq <- L.pack `fmap` Base64.decode (L8.unpack bs3) | 52 | qq <- L.pack `fmap` Base64.decode (L8.unpack bs3) |
53 | #endif | ||
39 | decode_sshrsa qq | 54 | decode_sshrsa qq |
40 | where | 55 | where |
41 | decode_sshrsa :: L8.ByteString -> Maybe Key | 56 | decode_sshrsa :: L8.ByteString -> Maybe Key |