summaryrefslogtreecommitdiff
path: root/src/Crypto
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2017-10-16 23:15:09 +0000
committerJames Crayne <jim.crayne@gmail.com>2017-10-16 23:15:09 +0000
commitc75c9c8714b1e2f489ac5fe365ecda618c8da872 (patch)
tree17c87e1ce9b974b0526ef77e9d99a0ce235bda6b /src/Crypto
parentdf64a1baba58572fcc2aa82721851ee87f9e55b9 (diff)
k command
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