From d0481f76a38269500cd80dd1de02dbddb6c83cf8 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Mon, 14 May 2012 06:32:47 +0100 Subject: [PATCH] remove the need to have same length arguments in bytesEq. bail early in case strings have different size. --- Network/TLS/Util.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Network/TLS/Util.hs b/Network/TLS/Util.hs index b159e7f..8501419 100644 --- a/Network/TLS/Util.hs +++ b/Network/TLS/Util.hs @@ -59,6 +59,8 @@ False &&! False = False -- | verify that 2 bytestrings are equals. -- it's a non lazy version, that will compare every bytes. --- arguments need to be of same length +-- arguments with different length will bail out early bytesEq :: Bytes -> Bytes -> Bool -bytesEq b1 = and' . B.zipWith (==) b1 +bytesEq b1 b2 + | B.length b1 /= B.length b2 = False + | otherwise = and' $ B.zipWith (==) b1 b2