diff options
-rw-r--r-- | Tox.hs | 2 | ||||
-rw-r--r-- | src/Text/XXD.hs | 26 |
2 files changed, 27 insertions, 1 deletions
@@ -91,7 +91,7 @@ import qualified DHTHandlers as DHT | |||
91 | import qualified OnionTransport as Onion | 91 | import qualified OnionTransport as Onion |
92 | import qualified OnionHandlers as Onion | 92 | import qualified OnionHandlers as Onion |
93 | import CryptoTransport (NetCrypto) | 93 | import CryptoTransport (NetCrypto) |
94 | import XXD | 94 | import Text.XXD |
95 | 95 | ||
96 | newCrypto :: IO TransportCrypto | 96 | newCrypto :: IO TransportCrypto |
97 | newCrypto = do | 97 | newCrypto = do |
diff --git a/src/Text/XXD.hs b/src/Text/XXD.hs new file mode 100644 index 00000000..d835b238 --- /dev/null +++ b/src/Text/XXD.hs | |||
@@ -0,0 +1,26 @@ | |||
1 | module Text.XXD where | ||
2 | |||
3 | import qualified Data.ByteString.Base16 as Base16 | ||
4 | import Data.ByteString (ByteString) | ||
5 | import qualified Data.ByteString as B | ||
6 | import Data.Word | ||
7 | import Data.Bits | ||
8 | import Data.Char | ||
9 | import Text.Printf | ||
10 | |||
11 | nibble :: Word8 -> Char | ||
12 | nibble b = intToDigit (fromIntegral (b .&. 0x0F)) | ||
13 | |||
14 | xxd :: Int -> ByteString -> [String] | ||
15 | xxd offset bs | B.null bs = [] | ||
16 | xxd offset bs = printf "%03x: %s" offset ds : xxd (offset + B.length xs) bs' | ||
17 | where | ||
18 | ds = unwords $ map (\byte -> [nibble (byte `shiftR` 4), nibble byte]) | ||
19 | $ B.unpack xs | ||
20 | (xs,bs') = B.splitAt 16 bs | ||
21 | |||
22 | {- | ||
23 | main = do | ||
24 | bs <- B.getContents | ||
25 | mapM_ putStrLn $ xxd 0 bs | ||
26 | -} | ||