{-# 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) = a -> CompressionID
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) = (a -> Compression) -> (a, ByteString) -> (Compression, ByteString)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first a -> Compression
forall a. CompressionC a => a -> Compression
Compression ((a, ByteString) -> (Compression, ByteString))
-> (a, ByteString) -> (Compression, ByteString)
forall a b. (a -> b) -> a -> b
$ a -> ByteString -> (a, ByteString)
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) = (a -> Compression) -> (a, ByteString) -> (Compression, ByteString)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first a -> Compression
forall a. CompressionC a => a -> Compression
Compression ((a, ByteString) -> (Compression, ByteString))
-> (a, ByteString) -> (Compression, ByteString)
forall a b. (a -> b) -> a -> b
$ a -> ByteString -> (a, ByteString)
forall a. CompressionC a => a -> ByteString -> (a, ByteString)
compressionCInflate a
c ByteString
bytes
instance Show Compression where
show :: Compression -> String
show = CompressionID -> String
forall a. Show a => a -> String
show (CompressionID -> String)
-> (Compression -> CompressionID) -> Compression -> String
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 CompressionID -> CompressionID -> Bool
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 = (Compression -> Bool) -> [Compression] -> [Compression]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Compression
c -> Compression -> CompressionID
compressionID Compression
c CompressionID -> [CompressionID] -> Bool
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 = NullCompression -> Compression
forall a. CompressionC a => a -> Compression
Compression NullCompression
NullCompression