From 87777784c1303ffff77ffe4f23cf2c2788dd23a1 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Sun, 3 May 2015 14:47:16 +0100 Subject: [PATCH] [QA] fix issues from HSE so that it parse files --- Crypto/PubKey/Curve25519.hs | 2 +- Crypto/PubKey/Ed25519.hs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Crypto/PubKey/Curve25519.hs b/Crypto/PubKey/Curve25519.hs index d95d07a..973c030 100644 --- a/Crypto/PubKey/Curve25519.hs +++ b/Crypto/PubKey/Curve25519.hs @@ -57,7 +57,7 @@ secretKey bs withByteArray bs $ \inp -> do valid <- isValidPtr inp if valid - then Right . SecretKey <$> B.copy bs (\_ -> return ()) + then (Right . SecretKey) <$> B.copy bs (\_ -> return ()) else return $ Left "invalid secret key" | otherwise = Left "secret key invalid size" where diff --git a/Crypto/PubKey/Ed25519.hs b/Crypto/PubKey/Ed25519.hs index a358103..a648678 100644 --- a/Crypto/PubKey/Ed25519.hs +++ b/Crypto/PubKey/Ed25519.hs @@ -58,16 +58,15 @@ publicKey bs -- | Try to build a secret key from a bytearray secretKey :: ByteArrayAccess ba => ba -> CryptoFailable SecretKey secretKey bs - | B.length bs == secretKeySize = unsafeDoIO $ do - withByteArray bs $ \inp -> do + | B.length bs == secretKeySize = unsafeDoIO $ withByteArray bs initialize + | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid + where + initialize inp = do valid <- isValidPtr inp if valid - then CryptoPassed . SecretKey <$> B.copy bs (\_ -> return ()) + then (CryptoPassed . SecretKey) <$> B.copy bs (\_ -> return ()) else return $ CryptoFailed CryptoError_SecretKeyStructureInvalid - | otherwise = CryptoFailed CryptoError_SecretKeyStructureInvalid - where - isValidPtr :: Ptr Word8 -> IO Bool - isValidPtr _ = do + isValidPtr _ = return True {-# NOINLINE secretKey #-} @@ -83,7 +82,7 @@ signature bs toPublic :: SecretKey -> PublicKey toPublic (SecretKey sec) = PublicKey <$> B.allocAndFreeze publicKeySize $ \result -> - withByteArray sec $ \psec -> + withByteArray sec $ \psec -> ccryptonite_ed25519_publickey psec result {-# NOINLINE toPublic #-}