summaryrefslogtreecommitdiff
path: root/src/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Tox.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs
index b84e5df6..d6f63f18 100644
--- a/src/Crypto/Tox.hs
+++ b/src/Crypto/Tox.hs
@@ -13,6 +13,7 @@ module Crypto.Tox
13 , getPublicKey 13 , getPublicKey
14 , putPublicKey 14 , putPublicKey
15 , SecretKey 15 , SecretKey
16 , generateSecretKey
16 , toPublic 17 , toPublic
17 , SymmetricKey(..) 18 , SymmetricKey(..)
18 , TransportCrypto(..) 19 , TransportCrypto(..)
@@ -359,7 +360,7 @@ getPublicKey = throwCryptoError . publicKey <$> S.getBytes 32
359putPublicKey :: PublicKey -> S.Put 360putPublicKey :: PublicKey -> S.Put
360putPublicKey bs = S.putByteString $ BA.convert bs 361putPublicKey bs = S.putByteString $ BA.convert bs
361 362
362encodeSecret :: BA.ByteArrayAccess bin => bin -> Maybe C8.ByteString 363encodeSecret :: SecretKey -> Maybe C8.ByteString
363encodeSecret k = do 364encodeSecret k = do
364 (a,bs) <- BA.uncons (BA.convert k) 365 (a,bs) <- BA.uncons (BA.convert k)
365 (cs,c) <- unsnoc bs 366 (cs,c) <- unsnoc bs
@@ -369,7 +370,7 @@ encodeSecret k = do
369 (ys,ds) = BA.splitAt 40 xs 370 (ys,ds) = BA.splitAt 40 xs
370 return $ BA.index ds 0 `BA.cons` ys `BA.snoc` BA.index ds 1 371 return $ BA.index ds 0 `BA.cons` ys `BA.snoc` BA.index ds 1
371 372
372decodeSecret :: C8.ByteString -> Maybe C8.ByteString 373decodeSecret :: C8.ByteString -> Maybe SecretKey
373decodeSecret k64 = do 374decodeSecret k64 = do
374 (ds0,ysds1) <- BA.uncons k64 375 (ds0,ysds1) <- BA.uncons k64
375 (ys,ds1) <- unsnoc ysds1 376 (ys,ds1) <- unsnoc ysds1
@@ -379,4 +380,7 @@ decodeSecret k64 = do
379 (cs,a') <- unsnoc csa 380 (cs,a') <- unsnoc csa
380 let a = shiftL (a' .&. 0x7c) 1 381 let a = shiftL (a' .&. 0x7c) 1
381 c = shiftR c' 4 .|. (shiftL a' 4 .&. 0x30) .|. 0x40 382 c = shiftR c' 4 .|. (shiftL a' 4 .&. 0x30) .|. 0x40
382 return $ a `BA.cons` (cs `BA.snoc` c) 383 let r = a `BA.cons` (cs `BA.snoc` c)
384 case secretKey r of
385 CryptoPassed x -> Just x
386 _ -> Nothing