remove few more unpacking/packing
This commit is contained in:
parent
8f91009884
commit
b71ea6729c
2 changed files with 6 additions and 8 deletions
|
@ -148,8 +148,8 @@ decryptContent hdr e@(EncryptedData b) = do
|
|||
then decryptContentReally hdr e
|
||||
else return b
|
||||
|
||||
takelast :: Int -> [a] -> [a]
|
||||
takelast i b = drop (length b - i) b
|
||||
takelast :: Int -> Bytes -> Bytes
|
||||
takelast i b = B.drop (B.length b - i) b
|
||||
|
||||
decryptData :: EncryptedData -> TLSRead ByteString
|
||||
decryptData (EncryptedData econtent) = do
|
||||
|
@ -170,7 +170,7 @@ decryptData (EncryptedData econtent) = do
|
|||
CipherNoneF -> fail "none decrypt"
|
||||
CipherBlockF _ decryptF -> do
|
||||
{- update IV -}
|
||||
let newiv = B.pack $ takelast padding_size $ B.unpack econtent
|
||||
let newiv = takelast padding_size econtent
|
||||
putTLSState $ st { stRxCryptState = Just $ cst { cstIV = newiv } }
|
||||
return $ decryptF writekey iv econtent
|
||||
CipherStreamF initF _ decryptF -> do
|
||||
|
|
|
@ -15,11 +15,9 @@ module Network.TLS.Sending (
|
|||
) where
|
||||
|
||||
import Control.Monad.State
|
||||
--import Data.Binary.Put (runPut, putWord16be)
|
||||
import Data.Maybe
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.ByteString as B
|
||||
|
||||
import Network.TLS.Wire
|
||||
|
@ -110,8 +108,8 @@ encryptContent (hdr@(Header pt ver _), content) = do
|
|||
let hdrnew = Header pt ver (fromIntegral $ B.length encrypted_msg)
|
||||
return (hdrnew, encrypted_msg)
|
||||
|
||||
takelast :: Int -> [a] -> [a]
|
||||
takelast i b = drop (length b - i) b
|
||||
takelast :: Int -> Bytes -> Bytes
|
||||
takelast i b = B.drop (B.length b - i) b
|
||||
|
||||
encryptData :: MonadTLSState m => ByteString -> m ByteString
|
||||
encryptData content = do
|
||||
|
@ -140,7 +138,7 @@ encryptData content = do
|
|||
CipherNoneF -> fail "none encrypt"
|
||||
CipherBlockF encrypt _ -> do
|
||||
let e = encrypt writekey iv (B.concat [ content, padding ])
|
||||
let newiv = B.pack $ takelast (fromIntegral padding_size) $ B.unpack e
|
||||
let newiv = takelast (fromIntegral padding_size) e
|
||||
putTLSState $ st { stTxCryptState = Just $ cst { cstIV = newiv } }
|
||||
return e
|
||||
CipherStreamF initF encryptF _ -> do
|
||||
|
|
Loading…
Reference in a new issue