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

Get rid of the repeated bytesRead requests

We use `isolate` so we know exactly how far we've advanced, we can trivially
compute the correct position.
parent 743a2ee4
No related branches found
No related tags found
1 merge request!7Implement enough encryption and encoding to be able to read plaintext from Tahoe-LAFS-generated SDMF shares
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment