Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/dorny/paths-filter-3
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMaier-IRT committed Jan 30, 2024
2 parents b2dae6b + faaceeb commit e19f8d5
Show file tree
Hide file tree
Showing 31 changed files with 24,719 additions and 21,462 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM mcr.microsoft.com/devcontainers/cpp:ubuntu22.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

ENV PROCESSOR=x64

RUN
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive && \
apt-get install \
build-essential iwyu llvm clang-14 cmake lcov cppcheck clang-format clang-tidy \
ninja-build valgrind unzip dotnet-sdk-7.0 wget \
-y
RUN mkdir cmake && wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.2/CPM.cmake
RUN dotnet tool restore

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"
43 changes: 28 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-dockerfile
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "Existing Dockerfile",
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../Dockerfile"
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "make environment"
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "make fetch-sample-data environment-ui",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.makefile-tools",
"ms-dotnettools.csdevkit",
"ms-dotnettools.dotnet-maui",
"ms-vscode.cpptools",
"yzhang.markdown-all-in-one",
"cake-build.cake-vscode",
"ms-vscode.cmake-tools",
"twxs.cmake"
]
}
}
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
59 changes: 59 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
49 changes: 49 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto eol=lf

# Explicitly declare text files we want to always be normalized and converted
# to native line endings on checkout.
*.cs text diff=csharp

*.cpp text diff=cpp
*.h text diff=cpp
*.hpp text diff=cpp
*.c text diff=cpp

*.txt text
Makefile text
*.json text
*.plist text

*.xaml text eol=crlf

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf merge=binary
*.csproj text eol=lf merge=binary
# Denote all files that are truly binary and should not be modified.
*.png binary
*.svg binary
*.jpg binary
*.jpeg binary
*.ttf binary

*.resx text eol=crlf
*.md text

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ifeq ($(OPERATING_SYSTEM),Darwin)
brew install cmake
brew install cppcheck
brew install clang-format
brew install include-what-you-use
# brew install include-what-you-use
brew install llvm
brew install ninja
test -f /usr/local/bin/clang-tidy || sudo ln -sf "$(shell brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
Expand Down Expand Up @@ -153,13 +153,21 @@ ifeq ($(OPERATING_SYSTEM),Windows)
git
endif

devcontainer: fetch-sample-data environment-ui
dotnet tool restore

environment-ui:
ifeq ($(OPERATING_SYSTEM),Windows)
dotnet workload install maui
dotnet workload restore ./src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj && dotnet restore ./src/electionguard-ui/ElectionGuard.UI.sln
else
endif
ifeq ($(OPERATING_SYSTEM),Darwin)
sudo dotnet workload install maui
sudo dotnet workload restore ./src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj && dotnet restore ./src/electionguard-ui/ElectionGuard.UI.sln
endif
ifeq ($(OPERATING_SYSTEM),Linux)
sudo dotnet workload install maui-windows
sudo dotnet workload restore ./src/electionguard-ui/ElectionGuard.UI/ElectionGuard.UI.csproj && dotnet restore ./src/electionguard-ui/ElectionGuard.UI.sln
endif
dotnet tool restore
npm i -g appcenter-cli
Expand Down
6 changes: 3 additions & 3 deletions apps/electionguard-cli/Generate/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ private async Task ExecuteInternal(GenerateOptions options)

var plaintextPath = Path.Combine(options.WorkingDir, "plaintext");
var encryptedPath = Path.Combine(options.WorkingDir, "encrypted_ballots");

var index = 0;
foreach (var ballot in plaintextBallots)
{
var ciphertext = encryptionMediator.Encrypt(ballot, false);
var ciphertext = encryptionMediator.Encrypt(ballot, options.BallotValidate);
if (Random.Shared.NextSingle() > options.SpoiledPercent / 100.0)
{
ciphertext.Cast();
Expand Down Expand Up @@ -71,7 +71,7 @@ private async Task ExecuteInternal(GenerateOptions options)
{
File.WriteAllText(Path.Combine(plaintextPath, $"{ballotCode}.json"), data);
}
Console.WriteLine($"Generated Ballot {ballotCode}.json");
Console.WriteLine($"Generated Ballot {index++} {ballotCode}.json");
ciphertext.Dispose();
}
var tallyJson = JsonConvert.SerializeObject(tally);
Expand Down
3 changes: 3 additions & 0 deletions apps/electionguard-cli/Generate/GenerateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ internal class GenerateOptions
[Option('c', "count", Required = false, HelpText = "Number of ballots to generate and encrypt. Defaults to 100.")]
public int BallotCount { get; set; } = 100;

[Option('v', "validate", Required = false, HelpText = "Validate the ballots when generating. Defaults to false.")]
public bool BallotValidate { get; set; } = false;

public void Validate()
{
ValidateDirectories();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ElectionGuard.Ballot;
using System.Text;
using ElectionGuard.Ballot;
using ElectionGuard.ElectionSetup.Extensions;

namespace ElectionGuard.Decryption.Tally;
Expand Down Expand Up @@ -82,7 +83,23 @@ public void Accumulate(CiphertextBallotContest contest)

if (!Selections.Keys.All(contestSelectionIds.Contains))
{
throw new ArgumentException("Selections do not match contest");
StringBuilder sb = new StringBuilder();
sb.AppendLine("selections keys");
foreach (var item in Selections.Keys)
{
sb.AppendLine(item);
}
sb.AppendLine("contest.Selections");
foreach (var item in contest.Selections)
{
sb.AppendLine(item.ObjectId + " " + item.IsPlaceholder);
}
sb.AppendLine("contestSelectionIds");
foreach (var item in contestSelectionIds)
{
sb.AppendLine(item);
}
throw new ArgumentException("Selections do not match contest " + sb.ToString());
}
foreach (var selection in ballotSelections)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public CiphertextTallySelection(ICiphertextSelection other)
public ElGamalCiphertext Accumulate(ICiphertextSelection selection)
{
return selection.ObjectId != ObjectId || selection.DescriptionHash != DescriptionHash
? throw new ArgumentException("Selection does not match")
? throw new ArgumentException($"Selection does not match tally: {ObjectId} {DescriptionHash} selection: {selection.ObjectId} {selection.DescriptionHash}")
: Accumulate(selection.Ciphertext);
}

Expand Down
Loading

0 comments on commit e19f8d5

Please sign in to comment.