{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE ExistentialQuantification #-}
module Network.TLS.Compression
( CompressionC(..)
, Compression(..)
, CompressionID
, nullCompression
, NullCompression
, compressionID
, compressionDeflate
, compressionInflate
, compressionIntersectID
) where
import Data.Word
import Network.TLS.Types (CompressionID)
import Data.ByteString (ByteString)
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 c) = compressionCID c
compressionDeflate :: ByteString -> Compression -> (Compression, ByteString)
compressionDeflate bytes (Compression c) = first Compression $ compressionCDeflate c bytes
compressionInflate :: ByteString -> Compression -> (Compression, ByteString)
compressionInflate bytes (Compression c) = first Compression $ compressionCInflate c bytes
instance Show Compression where
show = show . compressionID
instance Eq Compression where
(==) c1 c2 = compressionID c1 == compressionID c2
compressionIntersectID :: [Compression] -> [Word8] -> [Compression]
compressionIntersectID l ids = filter (\c -> elem (compressionID c) ids) l
data NullCompression = NullCompression
instance CompressionC NullCompression where
compressionCID _ = 0
compressionCDeflate s b = (s, b)
compressionCInflate s b = (s, b)
nullCompression :: Compression
nullCompression = Compression NullCompression