diff --git a/src/Tahoe/SDMF/Internal/Share.hs b/src/Tahoe/SDMF/Internal/Share.hs index e01b8b4e4b874ec6a581e92e62ee49fed16bd1f9..f62cc963fac86811140183207f01c1c11bffa58d 100644 --- a/src/Tahoe/SDMF/Internal/Share.hs +++ b/src/Tahoe/SDMF/Internal/Share.hs @@ -144,23 +144,18 @@ instance Binary Share where encryptedPrivateKeyOffset <- getWord64be eofOffset <- getWord64be - pos <- bytesRead - shareVerificationKey <- Keys.Verification <$> isolate (fromIntegral signatureOffset - fromIntegral pos) getSubjectPublicKeyInfo - - pos <- bytesRead - shareSignature <- getByteString (fromIntegral hashChainOffset - fromIntegral pos) - - pos <- bytesRead - shareHashChain <- isolate (fromIntegral blockHashTreeOffset - fromIntegral pos) get - - pos <- bytesRead - shareBlockHashTree <- isolate (fromIntegral shareDataOffset - fromIntegral pos) get - - pos <- bytesRead - shareData <- getLazyByteString (fromIntegral encryptedPrivateKeyOffset - fromIntegral pos) - - pos <- bytesRead - shareEncryptedPrivateKey <- getByteString (fromIntegral eofOffset - fromIntegral pos) + -- This offset is not the encoded share but it's defined as being + -- right where we've read to. Give it a name that follows the + -- pattern. + shareVerificationOffset <- bytesRead + + -- Read in the values between all those offsets. + shareVerificationKey <- Keys.Verification <$> isolate (fromIntegral signatureOffset - fromIntegral shareVerificationOffset) getSubjectPublicKeyInfo + shareSignature <- getByteString (fromIntegral hashChainOffset - fromIntegral signatureOffset) + shareHashChain <- isolate (fromIntegral blockHashTreeOffset - fromIntegral hashChainOffset) get + shareBlockHashTree <- isolate (fromIntegral shareDataOffset - fromIntegral blockHashTreeOffset) get + shareData <- getLazyByteString (fromIntegral encryptedPrivateKeyOffset - fromIntegral shareDataOffset) + shareEncryptedPrivateKey <- getByteString (fromIntegral eofOffset - fromIntegral encryptedPrivateKeyOffset) empty <- isEmpty unless empty (fail "Expected end of input but there are more bytes")