packages feed

IPv6Addr 1.0.1 → 1.0.2

raw patch · 3 files changed

+24/−25 lines, 3 filesdep ~aesonPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aeson

API changes (from Hackage documentation)

+ Text.IPv6Addr: AllZeros :: IPv6AddrToken
+ Text.IPv6Addr: Colon :: IPv6AddrToken
+ Text.IPv6Addr: DoubleColon :: IPv6AddrToken
+ Text.IPv6Addr: IPv4Addr :: !Text -> IPv6AddrToken
+ Text.IPv6Addr: SixteenBit :: !Text -> IPv6AddrToken
+ Text.IPv6Addr: data IPv6AddrToken

Files

IPv6Addr.cabal view
@@ -1,5 +1,5 @@ name:                IPv6Addr-version:             1.0.1+version:             1.0.2 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-2017 - Michel Boucey+copyright:           (c) 2011-2018 - Michel Boucey category:            Network build-type:          Simple extra-source-files:  README.md@@ -26,7 +26,7 @@                   , network      >=2.5 && < 2.7                   , random       >=1.0 && <= 1.1                   , attoparsec   >=0.12 && < 0.14-                  , aeson        >= 0.8.0.2 && < 1.3+                  , aeson        >= 0.8.0.2 && < 1.4                   , network-info >=0.2 && <=0.3   default-language: Haskell2010   GHC-Options:      -Wall
Text/IPv6Addr.hs view
@@ -20,6 +20,7 @@     , randIPv6AddrWithPrefix      -- * Manipulations+    , IPv6AddrToken (..)     , randIPv6AddrChunk     , randPartialIPv6Addr     , macAddrToIPv6AddrTokens@@ -48,14 +49,6 @@ instance Show IPv6Addr where   show (IPv6Addr a) = T.unpack a -data IPv6AddrToken-  = 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-  deriving (Eq, Show)- instance Eq IPv6Addr where   (==) (IPv6Addr a) (IPv6Addr b) =     show (maybePureIPv6Addr a) == show (maybePureIPv6Addr b)@@ -70,6 +63,14 @@       Nothing -> fail "Not An IPv6 Address"   parseJSON _          = fail "JSON String Expected" +data IPv6AddrToken+  = 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+  deriving (Eq, Show)+ -- | Returns 'Just' the text representation of a canonized -- 'IPv6Addr' in conformation with RFC 5952, or 'Nothing'. --@@ -174,14 +175,14 @@                          , pure [DoubleColon]                          , randPartialIPv6Addr r'                          ]-      return $ ipv6TokensToIPv6Addr tks+      return (ipv6TokensToIPv6Addr tks)     else       case maybeIPv6AddrTokens (fromJust p) of         Just tks -> do           ntks <- do let ctks = countChunks tks                      case (snd ctks :: Int) of-                        0 -> return $ 8 - fst ctks-                        1 -> return $ 6 - fst ctks+                        0 -> return (8 - fst ctks)+                        1 -> return (6 - fst ctks)                         _ -> return 0           guard (ntks > 0)           rtks <- randPartialIPv6Addr ntks@@ -240,10 +241,7 @@ macAddrToIPv6AddrTokens :: T.Text -> Maybe [IPv6AddrToken] macAddrToIPv6AddrTokens t =   case parse macAddr t of-    Done a b ->-      if a == T.empty-        then intersperse Colon <$> b-        else Nothing+    Done a b -> guard (a == T.empty) >> intersperse Colon <$> b     _        -> Nothing  --@@ -362,7 +360,7 @@   case maybeIPv6AddrTokens t of     Just ltks -> do       guard (isIPv6Addr ltks)-      Just $ (ipv4AddrReplacement . toDoubleColon . fromDoubleColon) ltks+      return (ipv4AddrReplacement . toDoubleColon . fromDoubleColon $ ltks)     Nothing   -> Nothing   where     ipv4AddrReplacement ltks =@@ -376,7 +374,7 @@ maybeTokPureIPv6Addr t = do   ltks <- maybeIPv6AddrTokens t   guard (isIPv6Addr ltks)-  return $ (toDoubleColon . ipv4AddrReplacement . fromDoubleColon) ltks+  return (toDoubleColon . ipv4AddrReplacement . fromDoubleColon $ ltks)   where     ipv4AddrReplacement ltks' =       init ltks' ++ ipv4AddrToIPv6AddrTokens (last ltks')@@ -385,7 +383,7 @@ maybeIPv6AddrTokens :: T.Text -> Maybe [IPv6AddrToken] maybeIPv6AddrTokens s =   case readText s of-    Done r l  -> if r==T.empty then Just l else Nothing+    Done r l  -> guard (r == T.empty) >> Just l     Fail {}   -> Nothing     Partial _ -> Nothing   where@@ -447,7 +445,7 @@ expandTokens =   map expandToken   where-    expandToken (SixteenBit s) = SixteenBit $ T.justifyRight 4 '0' s+    expandToken (SixteenBit s) = SixteenBit (T.justifyRight 4 '0' s)     expandToken AllZeros       = SixteenBit "0000"     expandToken t              = t @@ -499,7 +497,7 @@         groupZerosRuns = group . filter (/= Colon)  ipv6TokensToIPv6Addr :: [IPv6AddrToken] -> Maybe IPv6Addr-ipv6TokensToIPv6Addr l = Just $ IPv6Addr $ ipv6TokensToText l+ipv6TokensToIPv6Addr l = Just (IPv6Addr $ ipv6TokensToText l)  networkInterfacesIPv6AddrList :: IO [(String,Network.Info.IPv6)] networkInterfacesIPv6AddrList =@@ -538,12 +536,12 @@   guard (n3 /= T.empty)   n4 <- manyDigits   guard (n4 /= T.empty)-  return $ IPv4Addr $ T.intercalate "." [n1,n2,n3,n4]+  return (IPv4Addr $ T.intercalate "." [n1,n2,n3,n4])   where     manyDigits = do       ds <- takeWhile1 isDigit       case R.decimal ds :: Either String (Integer, T.Text) of-        Right (n,_) -> return $ if n < 256 then T.pack $ show n else T.empty+        Right (n,_) -> return (if n < 256 then T.pack $ show n else T.empty)         Left  _     -> return T.empty  doubleColon :: Parser IPv6AddrToken
tests/Main.hs view
@@ -103,4 +103,5 @@   , (~?=) (toIP6ARPA (IPv6Addr "4321:0:1:2:3:4:567:89ab")) "b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.IP6.ARPA."   , (~?=) (toUNC (IPv6Addr "2001:0DB8:002a:1005:230:48ff:FE73:989d")) "2001-db8-2a-1005-230-48ff-fe73-989d.ipv6-literal.net"   , (~?=) (toUNC (IPv6Addr "2001:0db8:85a3:0000:0000:8a2e:0370:7334")) "2001-db8-85a3--8a2e-370-7334.ipv6-literal.net"+  , (~?=) (macAddrToIPv6AddrTokens "fa:1d:58:cc:95:16") (Just [SixteenBit "fa1d", Colon, SixteenBit "58cc", Colon, SixteenBit "9516"])   ]