{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE ExistentialQuantification #-}
module Network.TLS.Compression
( CompressionC(..)
, Compression(..)
, CompressionID
, nullCompression
, NullCompression
, compressionID
, compressionDeflate
, compressionInflate
, compressionIntersectID
) where
import Network.TLS.Types (CompressionID)
import Network.TLS.Imports
import Control.Arrow (first)
class CompressionC a where
compressionCID :: a -> CompressionID
compressionCDeflate :: a -> ByteString -> (a, ByteString)
compressionCInflate :: a -> ByteString -> (a, ByteString)
data Compression = forall a . CompressionC a => Compression a
compressionID :: Compression -> CompressionID
compressionID :: Compression -> CompressionID
compressionID (Compression a
c) = forall a. CompressionC a => a -> CompressionID
compressionCID a
c
compressionDeflate :: ByteString -> Compression -> (Compression, ByteString)
compressionDeflate :: ByteString -> Compression -> (Compression, ByteString)
compressionDeflate ByteString
bytes (Compression a
c) = forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall a. CompressionC a => a -> Compression
Compression forall a b. (a -> b) -> a -> b
$ forall a. CompressionC a => a -> ByteString -> (a, ByteString)
compressionCDeflate a
c ByteString
bytes
compressionInflate :: ByteString -> Compression -> (Compression, ByteString)
compressionInflate :: ByteString -> Compression -> (Compression, ByteString)
compressionInflate ByteString
bytes (Compression a
c) = forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first forall a. CompressionC a => a -> Compression
Compression forall a b. (a -> b) -> a -> b
$ forall a. CompressionC a => a -> ByteString -> (a, ByteString)
compressionCInflate a
c ByteString
bytes
instance Show Compression where
show :: Compression -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compression -> CompressionID
compressionID
instance Eq Compression where
== :: Compression -> Compression -> Bool
(==) Compression
c1 Compression
c2 = Compression -> CompressionID
compressionID Compression
c1 forall a. Eq a => a -> a -> Bool
== Compression -> CompressionID
compressionID Compression
c2
compressionIntersectID :: [Compression] -> [Word8] -> [Compression]
compressionIntersectID :: [Compression] -> [CompressionID] -> [Compression]
compressionIntersectID [Compression]
l [CompressionID]
ids = forall a. (a -> Bool) -> [a] -> [a]
filter (\Compression
c -> Compression -> CompressionID
compressionID Compression
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CompressionID]
ids) [Compression]
l
data NullCompression = NullCompression
instance CompressionC NullCompression where
compressionCID :: NullCompression -> CompressionID
compressionCID NullCompression
_ = CompressionID
0
compressionCDeflate :: NullCompression -> ByteString -> (NullCompression, ByteString)
compressionCDeflate NullCompression
s ByteString
b = (NullCompression
s, ByteString
b)
compressionCInflate :: NullCompression -> ByteString -> (NullCompression, ByteString)
compressionCInflate NullCompression
s ByteString
b = (NullCompression
s, ByteString
b)
nullCompression :: Compression
nullCompression :: Compression
nullCompression = forall a. CompressionC a => a -> Compression
Compression NullCompression
NullCompression