diff --git a/src/Tahoe/Download.hs b/src/Tahoe/Download.hs index 99865903fb0af0c81dedf40dbca160b05bc95c0c..79f3bb66c90f84b8eb9ef57827f63df1277689b8 100644 --- a/src/Tahoe/Download.hs +++ b/src/Tahoe/Download.hs @@ -1,3 +1,5 @@ +{-# 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. diff --git a/src/Tahoe/Download/Internal/Capability.hs b/src/Tahoe/Download/Internal/Capability.hs index 84c575fb84992c19b0d6544deec378127d0427e2..540027a53ef8d00aeab942b0c47b4137c34d90dd 100644 --- a/src/Tahoe/Download/Internal/Capability.hs +++ b/src/Tahoe/Download/Internal/Capability.hs @@ -1,4 +1,3 @@ -{-# 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))