Skip to content
Snippets Groups Projects
Commit 97537140 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

simplify Readable in some ways

* make it single-param instead of multi-param
* get rid of its functional dependency

The cost is the use of another type family.  Seems like a win to me.
parent 4a4aa0a6
No related branches found
No related tags found
1 merge request!7Turn WhichShare into an associated type family
Pipeline #4734 failed
{-# LANGUAGE TypeFamilies #-}
{- | A high-level interface to downloading share data as bytes from storage
servers.
-}
......@@ -41,7 +43,14 @@ type DownloadedShare = (ShareNum, LB.ByteString)
given servers, if possible.
-}
download ::
(MonadIO m, Verifiable verifyCap, Readable readCap verifyCap) =>
-- To download, we require a capability for which there is a Readable
-- instance because are also going to decrypt the ciphertext. A different
-- download interface that skips decryption could settle for a capability
-- with a Verifiable instance. We also require that the Verifier type for
-- the read capability has a Verifiable instance because Verifiable is
-- what gives us the ability to locate the shares. If we located
-- separately from decrypting this might be simpler.
(MonadIO m, Readable readCap, Verifiable v, Verifier readCap ~ v) =>
-- | Information about the servers from which to consider downloading shares
-- representing the application data.
Map.Map StorageServerID StorageServerAnnouncement ->
......@@ -150,7 +159,7 @@ locateShares servers lookupServer storageIndex required =
decode them and decrypt the contents of possible.
-}
decodeShares ::
(MonadIO m, Readable readCap verifyCap) =>
(MonadIO m, Readable readCap, Verifiable v, v ~ Verifier readCap) =>
-- | The read capability which allows the contents to be decrypted.
readCap ->
-- | The results of downloading the shares.
......
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TypeFamilies #-}
module Tahoe.Download.Internal.Capability where
......@@ -46,9 +45,15 @@ class Verifiable v where
LB.ByteString ->
Either (LB.ByteString, ByteOffset, String) (ShareT v)
class (Verifiable v) => Readable r v | r -> v where
{- | A capability which confers the ability to recover plaintext from
ciphertext.
-}
class Readable r where
-- | Represent the type of a Verifiable associated with the Readable.
type Verifier r
-- | Attentuate the capability.
getVerifiable :: r -> v
getVerifiable :: r -> Verifier r
-- | Interpret the required number of shares to recover the plaintext.
--
......@@ -57,7 +62,7 @@ class (Verifiable v) => Readable r v | r -> v where
-- shareToCipherText :: r -> [(Int, ShareT r)] -> LB.ByteString
--
-- cipherTextToPlainText :: r -> LB.ByteString -> LB.ByteString
decodeShare :: MonadIO m => r -> [(Int, ShareT v)] -> m (Either DownloadError LB.ByteString)
decodeShare :: MonadIO m => r -> [(Int, ShareT (Verifier r))] -> m (Either DownloadError LB.ByteString)
instance Verifiable CHK.Verifier where
type ShareT CHK.Verifier = Tahoe.CHK.Share.Share
......@@ -74,7 +79,9 @@ instance Verifiable CHK.Verifier where
recover the original plaintext. Additionally, it can be attentuated to a
Verifiable.
-}
instance Readable CHK.Reader CHK.Verifier where
instance Readable CHK.Reader where
type Verifier CHK.Reader = CHK.Verifier
getVerifiable = CHK.verifier
decodeShare r shareList = do
cipherText <- liftIO $ Tahoe.CHK.decode r shareList
......@@ -96,7 +103,8 @@ instance Verifiable SDMF.Verifier where
deserializeShare _ = fmap (\(_, _, c) -> c) . decodeOrFail
instance Readable SDMF.Reader SDMF.Verifier where
instance Readable SDMF.Reader where
type Verifier SDMF.Reader = SDMF.Verifier
getVerifiable = SDMF.readerVerifier
decodeShare r shareList = do
cipherText <- Right <$> liftIO (SDMF.decode r (first fromIntegral <$> shareList))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment