IPv6Addr 0.6.3 → 0.7.0
raw patch · 6 files changed
+40/−19 lines, 6 filesdep +aesonPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson
API changes (from Hackage documentation)
- Text.IPv6Addr.Internal: expandTokens :: [IPv6AddrToken] -> [IPv6AddrToken]
- Text.IPv6Addr.Internal: fromDoubleColon :: [IPv6AddrToken] -> [IPv6AddrToken]
- Text.IPv6Addr.Internal: fromIPv6Addr :: IPv6Addr -> Text
- Text.IPv6Addr.Internal: ipv4AddrToIPv6AddrTokens :: IPv6AddrToken -> [IPv6AddrToken]
- Text.IPv6Addr.Internal: ipv6TokensToIPv6Addr :: [IPv6AddrToken] -> Maybe IPv6Addr
- Text.IPv6Addr.Internal: ipv6TokensToText :: [IPv6AddrToken] -> Text
- Text.IPv6Addr.Internal: isIPv6Addr :: [IPv6AddrToken] -> Bool
- Text.IPv6Addr.Internal: macAddr :: Parser (Maybe [IPv6AddrToken])
- Text.IPv6Addr.Internal: maybeIPv6AddrTokens :: Text -> Maybe [IPv6AddrToken]
- Text.IPv6Addr.Internal: maybeTokIPv6Addr :: Text -> Maybe [IPv6AddrToken]
- Text.IPv6Addr.Internal: maybeTokPureIPv6Addr :: Text -> Maybe [IPv6AddrToken]
- Text.IPv6Addr.Internal: networkInterfacesIPv6AddrList :: IO [(String, IPv6)]
- Text.IPv6Addr.Internal: toDoubleColon :: [IPv6AddrToken] -> [IPv6AddrToken]
+ Text.IPv6Addr: instance Data.Aeson.Types.FromJSON.FromJSON Text.IPv6Addr.Types.IPv6Addr
+ Text.IPv6Addr: instance Data.Aeson.Types.ToJSON.ToJSON Text.IPv6Addr.Types.IPv6Addr
Files
- IPv6Addr.cabal +13/−9
- LICENSE +1/−1
- Text/IPv6Addr.hs +11/−0
- Text/IPv6Addr/Manip.hs +12/−7
- Text/IPv6Addr/Types.hs +2/−2
- tests/Main.hs +1/−0
IPv6Addr.cabal view
@@ -1,5 +1,5 @@ name: IPv6Addr-version: 0.6.3+version: 0.7.0 synopsis: Library to deal with IPv6 address text representations. description: Library to deal with IPv6 address text representations, canonization and manipulations. homepage: https://github.com/MichelBoucey/IPv6Addr@@ -7,7 +7,7 @@ license-file: LICENSE author: Michel Boucey maintainer: michel.boucey@cybervisible.fr-copyright: (c) 2011-2016 - Michel Boucey+copyright: (c) 2011-2017 - Michel Boucey category: Network build-type: Simple extra-source-files: README.md@@ -18,14 +18,18 @@ Location: https://github.com/MichelBoucey/IPv6Addr.git library- exposed-modules: Text.IPv6Addr, Text.IPv6Addr.Types, Text.IPv6Addr.Manip, Text.IPv6Addr.Internal+ exposed-modules: Text.IPv6Addr+ , Text.IPv6Addr.Manip+ , Text.IPv6Addr.Types+ other-modules: Text.IPv6Addr.Internal other-extensions: OverloadedStrings- build-depends: base >=4.6 && <5- , text >=1.1 && <1.3- , iproute >=1.3 && <1.8- , network >=2.5 && <2.7- , random >=1.0 && <=1.1- , attoparsec >=0.12 && <0.14+ build-depends: base >=4.8 && < 5+ , text >=1.1 && < 1.3+ , iproute >=1.3 && < 1.8+ , network >=2.5 && < 2.7+ , random >=1.0 && <= 1.1+ , attoparsec >=0.12 && < 0.14+ , aeson >= 0.8.0.2 && < 1.2 , network-info >=0.2 && <=0.3 default-language: Haskell2010 GHC-Options: -Wall
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2011-2016, Michel Boucey+Copyright (c) 2011-2017, Michel Boucey All rights reserved. Redistribution and use in source and binary forms, with or without
Text/IPv6Addr.hs view
@@ -23,6 +23,7 @@ ) where +import Data.Aeson import Data.IP (IPv6) import Data.Maybe (fromJust, isNothing) import Data.Monoid ((<>))@@ -38,6 +39,16 @@ instance Eq IPv6Addr where (==) (IPv6Addr a) (IPv6Addr b) = show (maybePureIPv6Addr a) == show (maybePureIPv6Addr b)++instance ToJSON IPv6Addr where+ toJSON (IPv6Addr a) = String a++instance FromJSON IPv6Addr where+ parseJSON (String s) =+ case maybeIPv6Addr s of+ Just a -> pure a+ Nothing -> fail "Not An IPv6 Address"+ parseJSON _ = fail "JSON String Expected" -- | Returns 'Just' the text representation of a canonized -- 'IPv6Addr' in conformation with RFC 5952, or 'Nothing'.
Text/IPv6Addr/Manip.hs view
@@ -27,15 +27,17 @@ mapM getHex m >>= \g -> return $ SixteenBit $ T.dropWhile (=='0') $ T.pack g where getHex c- | c == '_' = intToDigit <$> randomRIO (0,15)- | otherwise = return c+ | c == '_' = getDigit+ | otherwise = pure c -- | Generates a random partial 'IPv6Addr' with n 'SixteenBit'. randPartialIPv6Addr :: Int -> IO [IPv6AddrToken]-randPartialIPv6Addr n- | n > 0 && n < 9 =- intersperse Colon <$> replicateM n (randIPv6AddrChunk "____")- | otherwise = return []+randPartialIPv6Addr n =+ if n > 0 && n < 9 + then+ intersperse Colon <$>+ replicateM n (SixteenBit <$> T.pack <$> replicateM 4 getDigit)+ else pure [] -- | Given a MAC address, returns 'Just' the corresponding 'IPv6AddrToken' list, or 'Nothing'. --@@ -75,6 +77,9 @@ (lookup s <$> networkInterfacesMacAddrList) where networkInterfacesMacAddrList = getNetworkInterfaces >>=- \n -> return $ map networkInterfacesMac n+ \n -> return (networkInterfacesMac <$> n) where networkInterfacesMac (NetworkInterface n _ _ m) = (n,m)++getDigit :: IO Char+getDigit = intToDigit <$> randomRIO (0,15)
Text/IPv6Addr/Types.hs view
@@ -8,10 +8,10 @@ show (IPv6Addr a) = T.unpack a data IPv6AddrToken- = SixteenBit !T.Text -- ^ A four hexadecimal digits group representing a 16-Bit chunk+ = SixteenBit !T.Text -- ^ A four hexadecimal digits group representing a 16-Bit chunk | AllZeros -- ^ An all zeros 16-Bit chunk | Colon -- ^ A separator between 16-Bit chunks | DoubleColon -- ^ A double-colon stands for a unique compression of many consecutive 16-Bit chunks- | IPv4Addr !T.Text -- ^ An embedded IPv4 address as representation of the last 32-Bit+ | IPv4Addr !T.Text -- ^ An embedded IPv4 address as representation of the last 32-Bit deriving (Eq, Show)
tests/Main.hs view
@@ -25,6 +25,7 @@ , (~?=) (maybeIPv6Addr "::1") (Just (IPv6Addr "::1")) , (~?=) (maybeIPv6Addr "::1:") Nothing , (~?=) (maybeIPv6Addr "0000:0000:0000:0000:0000:0000:0000:0001") (Just (IPv6Addr "::1"))+ , (~?=) (maybeIPv6Addr "0:0:0:0:0:0:0:1") (Just (IPv6Addr "::1")) , (~?=) (maybeIPv6Addr "a") Nothing , (~?=) (maybeIPv6Addr "ab") Nothing , (~?=) (maybeIPv6Addr "abc") Nothing