<commit_before>/*============================================================================*\
 | Copyright (C) 2015 <NAME>                                         |
 |                                                                            |
 | Licensed under the Apache License, Version 2.0 (the "License"); you may    |
 | not use this file except in compliance with the License. You may obtain a  |
 | copy of the License at                                                     |
 |                                                                            |
 |     http://www.apache.org/licenses/LICENSE-2.0                             |
 |                                                                            |
 | Unless required by applicable law or agreed to in writing, software        |
 | distributed under the License is distributed on an "AS IS" BASIS,          |
 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   |
 | See the License for the specific language governing permissions and        |
 | limitations under the License.                                             |
\*============================================================================*/

package me.edwards.des.block;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import me.edwards.des.Node;
import me.edwards.des.net.packet.PacketInv;
import me.edwards.des.util.ByteUtil;
import me.edwards.des.util.HashUtil;

// -----------------------------------------------------------------------------
/**
 * Data structure to store and maintain a single cast Ballot for a single entity
 * (user). Ballots are created in an Election Application when a user votes.<br>
 * <br>
 * The Ballot contains the {@link Vote Votes} chosen by the user in addition to
 * the user's unique UUID (created by the Election Authority). To prevent
 * changes from being made to the Ballot, its hash is signed using the ECDSA
 * private key generated by the Election Application. After the Ballot is
 * signed, the private key is destroyed and the public key is sent to the
 * Election Authority, marking the Ballot as cast. When the Node
 * {@link me.edwards.des.Node#parse(byte[], me.edwards.des.net.Connection)
 * receives} a Ballot, the signature is authenticated with the Ballot's hash to
 * ensure that the Ballot was not changed en-route to the Node.<br>
 * <br>
 * Created on: Nov 1, 2015 at 11:30:16 PM
 * 
 * @author <NAME>
 */
public class Ballot
{
    // ~ Static/Instance variables .............................................

    // -------------------------------------------------------------------------
    /**
     * This class' Ballot version
     */
    private static final byte VERSION = 1;

    
    // -------------------------------------------------------------------------
    private byte              version;
    private String            id;
    private byte[]            votes;
    private String            signature;    // 32 bytes

    private String            signatureRoot;
    private String            root;
    private byte[]            bytes;


    // ~ Constructors ..........................................................

    // -------------------------------------------------------------------------
    /**
     * Creates new Ballot from a UUID, Signatures, and list of votes. This
     * constructor is mainly used for demonstration or testing purposes because
     * Election Applications create new Ballots. {@link Node Nodes} and
     * {@link Block Blocks} only create Ballots from
     * {@link Ballot#Ballot(byte[]) binary data}.
     * 
     * @param id
     *            UUID of Ballot signer (User who cast this Ballot)<commit_msg>Updated UUID Length comment<commit_after>/*============================================================================*\
 | Copyright (C) 2015 <NAME>                                         |
 |                                                                            |
 | Licensed under the Apache License, Version 2.0 (the "License"); you may    |
 | not use this file except in compliance with the License. You may obtain a  |
 | copy of the License at                                                     |
 |                                                                            |
 |     http://www.apache.org/licenses/LICENSE-2.0                             |
 |                                                                            |
 | Unless required by applicable law or agreed to in writing, software        |
 | distributed under the License is distributed on an "AS IS" BASIS,          |
 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   |
 | See the License for the specific language governing permissions and        |
 | limitations under the License.                                             |
\*============================================================================*/

package me.edwards.des.block;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import me.edwards.des.Node;
import me.edwards.des.net.packet.PacketInv;
import me.edwards.des.util.ByteUtil;
import me.edwards.des.util.HashUtil;

// -----------------------------------------------------------------------------
/**
 * Data structure to store and maintain a single cast Ballot for a single entity
 * (user). Ballots are created in an Election Application when a user votes.<br>
 * <br>
 * The Ballot contains the {@link Vote Votes} chosen by the user in addition to
 * the user's unique UUID (created by the Election Authority). To prevent
 * changes from being made to the Ballot, its hash is signed using the ECDSA
 * private key generated by the Election Application. After the Ballot is
 * signed, the private key is destroyed and the public key is sent to the
 * Election Authority, marking the Ballot as cast. When the Node
 * {@link me.edwards.des.Node#parse(byte[], me.edwards.des.net.Connection)
 * receives} a Ballot, the signature is authenticated with the Ballot's hash to
 * ensure that the Ballot was not changed en-route to the Node.<br>
 * <br>
 * Created on: Nov 1, 2015 at 11:30:16 PM
 * 
 * @author <NAME>
 */
public class Ballot
{
    // ~ Static/Instance variables .............................................

    // -------------------------------------------------------------------------
    /**
     * This class' Ballot version
     */
    private static final byte VERSION = 1;

    
    // -------------------------------------------------------------------------
    private byte              version;
    private String            id;           // 8 bytes
    private byte[]            votes;
    private String            signature;    // 32 bytes

    private String            signatureRoot;
    private String            root;
    private byte[]            bytes;


    // ~ Constructors ..........................................................

    // -------------------------------------------------------------------------
    /**
     * Creates new Ballot from a UUID, Signatures, and list of votes. This
     * constructor is mainly used for demonstration or testing purposes because
     * Election Applications create new Ballots. {@link Node Nodes} and
     * {@link Block Blocks} only create Ballots from
     * {@link Ballot#Ballot(byte[]) binary data}.
     * 
     * @param id
     *            UUID of Ballot signer (User who cast this Ballot)
{'fraction_non_alphanumeric': 0.21262279639348675, 'fraction_numerical': 0.006055712555510699, 'mean_word_length': 1.388942462230794, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5034035', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1505, 'n_words': 658}