diff options
Diffstat (limited to 'Shard.hs')
-rw-r--r-- | Shard.hs | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -26,6 +26,9 @@ data ShardIdents = ShardIdents , identsBruteForceCalc :: CostCalc BruteForceOp UnknownName } +instance HasCreationCost ShardIdents where + getCreationCost = identsCreationCost + instance Bruteforceable ShardIdents UnknownName where getBruteCostCalc = identsBruteForceCalc @@ -59,9 +62,13 @@ genShards (EncryptedSecretKey esk _) tunables = do return $ map (\(n, share) -> Shard n (StorableObject $ encodeShare share)) (zip [1..] shares) --- Throws AssertionFailed if the number of shares is too small. -combineShards :: Tunables -> [Shard] -> EncryptedSecretKey -combineShards tunables = mk . SS.decode . map decodeshard +combineShards :: Tunables -> [Shard] -> Either String EncryptedSecretKey +combineShards tunables shards + | null shards = + Left "No shards could be downloaded. Perhaps you entered the wrong name or password?" + | length shards < minimum (map neededObjects (shardParams tunables)) = + Left "Not enough are shards currently available to reconstruct your data." + | otherwise = Right $ mk $ SS.decode $ map decodeshard shards where mk b = EncryptedSecretKey (BL.toStrict b) unknownCostCalc decodeshard (Shard sharenum so) = decodeShare sharenum sharesneeded $ |