use byteable to get a -> Bytestring function.
This commit is contained in:
parent
84864e9b6f
commit
cacab68840
4 changed files with 11 additions and 9 deletions
|
@ -25,18 +25,20 @@ import Network.TLS.Handshake.State
|
|||
import Network.TLS.Cipher
|
||||
import Network.TLS.Util
|
||||
|
||||
import Data.Byteable
|
||||
|
||||
returnEither :: Either TLSError a -> TLSSt a
|
||||
returnEither (Left err) = throwError err
|
||||
returnEither (Right a) = return a
|
||||
|
||||
processPacket :: Context -> Record Plaintext -> IO (Either TLSError Packet)
|
||||
|
||||
processPacket _ (Record ProtocolType_AppData _ fragment) = return $ Right $ AppData $ fragmentGetBytes fragment
|
||||
processPacket _ (Record ProtocolType_AppData _ fragment) = return $ Right $ AppData $ toBytes fragment
|
||||
|
||||
processPacket _ (Record ProtocolType_Alert _ fragment) = return (Alert `fmapEither` (decodeAlerts $ fragmentGetBytes fragment))
|
||||
processPacket _ (Record ProtocolType_Alert _ fragment) = return (Alert `fmapEither` (decodeAlerts $ toBytes fragment))
|
||||
|
||||
processPacket ctx (Record ProtocolType_ChangeCipherSpec _ fragment) =
|
||||
case decodeChangeCipherSpec $ fragmentGetBytes fragment of
|
||||
case decodeChangeCipherSpec $ toBytes fragment of
|
||||
Left err -> return $ Left err
|
||||
Right _ -> do switchRxEncryption ctx
|
||||
return $ Right ChangeCipherSpec
|
||||
|
@ -50,7 +52,7 @@ processPacket ctx (Record ProtocolType_Handshake ver fragment) = do
|
|||
, cParamsKeyXchgType = keyxchg
|
||||
, cParamsSupportNPN = npn
|
||||
}
|
||||
handshakes <- returnEither (decodeHandshakes $ fragmentGetBytes fragment)
|
||||
handshakes <- returnEither (decodeHandshakes $ toBytes fragment)
|
||||
hss <- forM handshakes $ \(ty, content) -> do
|
||||
case decodeHandshake currentparams ty content of
|
||||
Left err -> throwError err
|
||||
|
@ -58,7 +60,7 @@ processPacket ctx (Record ProtocolType_Handshake ver fragment) = do
|
|||
return $ Handshake hss
|
||||
|
||||
processPacket _ (Record ProtocolType_DeprecatedHandshake _ fragment) =
|
||||
case decodeDeprecatedHandshake $ fragmentGetBytes fragment of
|
||||
case decodeDeprecatedHandshake $ toBytes fragment of
|
||||
Left err -> return $ Left err
|
||||
Right hs -> return $ Right $ Handshake [hs]
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ module Network.TLS.Record
|
|||
( Record(..)
|
||||
-- * Fragment manipulation types
|
||||
, Fragment
|
||||
, fragmentGetBytes
|
||||
, fragmentPlaintext
|
||||
, fragmentCiphertext
|
||||
, recordToRaw
|
||||
|
|
|
@ -22,7 +22,6 @@ module Network.TLS.Record.Types
|
|||
, Fragment
|
||||
, fragmentPlaintext
|
||||
, fragmentCiphertext
|
||||
, fragmentGetBytes
|
||||
, Plaintext
|
||||
, Compressed
|
||||
, Ciphertext
|
||||
|
@ -41,6 +40,7 @@ module Network.TLS.Record.Types
|
|||
import Network.TLS.Struct
|
||||
import Network.TLS.Record.State
|
||||
import qualified Data.ByteString as B
|
||||
import Data.Byteable
|
||||
import Control.Applicative ((<$>))
|
||||
|
||||
-- | Represent a TLS record.
|
||||
|
@ -58,8 +58,8 @@ fragmentPlaintext bytes = Fragment bytes
|
|||
fragmentCiphertext :: Bytes -> Fragment Ciphertext
|
||||
fragmentCiphertext bytes = Fragment bytes
|
||||
|
||||
fragmentGetBytes :: Fragment a -> Bytes
|
||||
fragmentGetBytes (Fragment bytes) = bytes
|
||||
instance Byteable (Fragment a) where
|
||||
toBytes (Fragment b) = b
|
||||
|
||||
onRecordFragment :: Record a -> (Fragment a -> RecordM (Fragment b)) -> RecordM (Record b)
|
||||
onRecordFragment (Record pt ver frag) f = Record pt ver <$> f frag
|
||||
|
|
|
@ -35,6 +35,7 @@ Library
|
|||
, mtl
|
||||
, cereal >= 0.3
|
||||
, bytestring
|
||||
, byteable
|
||||
, network
|
||||
, data-default-class
|
||||
-- crypto related
|
||||
|
|
Loading…
Reference in a new issue