Skip to content

Commit

Permalink
Enhance logging for decryption.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-s-morgan committed Aug 3, 2023
1 parent b53bf9c commit 51a6e92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public void AddSpoiledBallot(CiphertextBallot ballot)
{
if (!_tally.HasBallot(ballot.ObjectId))
{
throw new ArgumentException("Tally does not contain ballot");
throw new ArgumentException($"Tally does not contain ballot {ballot.ObjectId}");
}

if (!ballot.IsSpoiled)
{
throw new ArgumentException("Cannot add unspoiled ballot");
throw new ArgumentException($"Cannot add unspoiled ballot {ballot.ObjectId} {ballot.State}");
}

if (!_spoiledBallots.ContainsKey(ballot.ObjectId))
Expand All @@ -146,18 +146,18 @@ public void AddSpoiledBallot(CiphertextBallot ballot)
{
if (!_tally.HasBallot(ballot.ObjectId))
{
throw new ArgumentException("Tally does not contain ballot");
throw new ArgumentException($"Tally {_tally.TallyId} does not contain ballot {ballot.ObjectId}");
}

if (ballot.IsSpoiled)
{
throw new ArgumentException("Cannot decrypt spoiled ballot");
throw new ArgumentException($"Cannot decrypt spoiled ballot {ballot.ObjectId}");
}

if (!ballotShare.IsValid(
ballot, guardian, _tally.Context.CryptoExtendedBaseHash))
{
throw new ArgumentException("Invalid ballot share");
throw new ArgumentException($"Invalid ballot share {ballotShare.TallyId}-{ballotShare.GuardianId}");
}

AddGuardian(guardian);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ List<CiphertextBallot> ballots
SubmitShare(shares.TallyShare);
if (ballots.Count > 0)
{
SubmitShares(shares.BallotShares.Values.Select(i => new BallotShare(i)).ToList(),
SubmitShares(
shares.BallotShares.Values.Select(i => new BallotShare(i)).ToList(),
ballots.Select(i => new CiphertextBallot(i)).ToList());
}
}
Expand Down Expand Up @@ -303,12 +304,12 @@ private void EnsureCiphertextDecryptionTally(TallyShare share)
{
if (!Tallies.ContainsKey(share.TallyId))
{
throw new ArgumentException("Tally does not exist");
throw new ArgumentException($"Tally does not exist {share.TallyId}");
}

if (!Guardians.ContainsKey(share.GuardianId))
{
throw new ArgumentException("Guardian does not exist");
throw new ArgumentException($"Guardian does not exist {share.GuardianId}");
}

if (!TallyDecryptions.ContainsKey(share.TallyId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,17 @@ private async Task Upload()
ResultsText = $"{AppResources.SuccessText} {totalCount} {AppResources.Success2Text}";
ShowPanel = BallotUploadPanel.Results;

var record = new CiphertextTallyRecord()
if ( totalSpoiled + totalChallenged + totalImported > 0 )
{
ElectionId = ElectionId,
UploadId = upload.UploadId!,
IsExportable = false,
CiphertextTallyData = ciphertextTally.ToJson()
};
_ = await _ciphertextTallyService.SaveAsync(record);
var record = new CiphertextTallyRecord()
{
ElectionId = ElectionId,
UploadId = upload.UploadId!,
IsExportable = false,
CiphertextTallyData = ciphertextTally.ToJson()
};
_ = await _ciphertextTallyService.SaveAsync(record);
}
}
catch (Exception)
{
Expand Down

0 comments on commit 51a6e92

Please sign in to comment.