<commit_before>/* @formatter:off */
/******************************************************************************
 * ELEC5616
 * Computer and Network Security, The University of Sydney
 * Copyright (C) 2002-2004, <NAME>, <NAME> and <NAME>
 *
 * PACKAGE:         StealthNet
 * FILENAME:        DecryptedPacket.java
 * AUTHORS:         <NAME>, <NAME>, <NAME> and <NAME>
 * DESCRIPTION:     Implementation of a StealthNet packet. This class represents
 * 					decrypted packet contents. This class is more closely based
 * 					on the original 'Packet' class than the EncryptedPacket
 * 					class.
 *
 *****************************************************************************/
/* @formatter:on */

package StealthNet;

/* Import Libraries ******************************************************** */

import java.io.UnsupportedEncodingException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.management.InvalidAttributeValueException;

import StealthNet.Security.Encryption;
import StealthNet.Security.MessageAuthenticationCode;
import StealthNet.Security.NonceGenerator;

/* StealthNet.DecryptedPacket Class Definition ***************************** */

/**
 * A class to store the decrypted data passed between StealthNet {@link Client}
 * s. A StealthNet "packet" consists of three parts: <ul> <li>command</li>
 * <li>data</li> <li>nonce</li> </ul>
 * 
 * A nonce is generated by a pseudo-random random generator. The nonce is used
 * to prevent replay attacks, because once the packet is read at the receiving
 * end of the communications, the nonce is "consumed" and cannot be used again
 * for future communications. The DecryptedPacket class <em>will</em> allow
 * packets to be created without a nonce (if a null {@link NonceGenerator}
 * instance is passed to the function). A higher layer should check whether or
 * not this should be allowed.
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class DecryptedPacket {
	/** The <ode>NULL</code> command is commonly used for acknowledgement. */
	public static final byte CMD_NULL = 0x00;
	public static final byte CMD_LOGIN = 0x01;
	public static final byte CMD_LOGOUT = 0x02;
	public static final byte CMD_MSG = 0x03;
	public static final byte CMD_CHAT = 0x04;
	public static final byte CMD_FTP = 0x05;
	public static final byte CMD_LIST = 0x06;
	public static final byte CMD_CREATESECRET = 0x07;
	public static final byte CMD_SECRETLIST = 0x08;
	public static final byte CMD_GETSECRET = 0x09;
	
	/**
	 * The <code>GETPUBLICKEY</code> command is used to request the public key
	 * of a user from the server.
	 */
	public static final byte CMD_GETPUBLICKEY = 0x0A;
	
	/*
	 * Security-specific commands - these should never be returned to a client<commit_msg>Added some packets to handle payment functionality.<commit_after>/* @formatter:off */
/******************************************************************************
 * ELEC5616
 * Computer and Network Security, The University of Sydney
 * Copyright (C) 2002-2004, <NAME>, <NAME> and <NAME>
 *
 * PACKAGE:         StealthNet
 * FILENAME:        DecryptedPacket.java
 * AUTHORS:         <NAME>, <NAME>, <NAME> and <NAME>
 * DESCRIPTION:     Implementation of a StealthNet packet. This class represents
 * 					decrypted packet contents. This class is more closely based
 * 					on the original 'Packet' class than the EncryptedPacket
 * 					class.
 *
 *****************************************************************************/
/* @formatter:on */

package StealthNet;

/* Import Libraries ******************************************************** */

import java.io.UnsupportedEncodingException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.management.InvalidAttributeValueException;

import StealthNet.Security.Encryption;
import StealthNet.Security.MessageAuthenticationCode;
import StealthNet.Security.NonceGenerator;

/* StealthNet.DecryptedPacket Class Definition ***************************** */

/**
 * A class to store the decrypted data passed between StealthNet {@link Client}
 * s. A StealthNet "packet" consists of three parts: <ul> <li>command</li>
 * <li>data</li> <li>nonce</li> </ul>
 * 
 * A nonce is generated by a pseudo-random random generator. The nonce is used
 * to prevent replay attacks, because once the packet is read at the receiving
 * end of the communications, the nonce is "consumed" and cannot be used again
 * for future communications. The DecryptedPacket class <em>will</em> allow
 * packets to be created without a nonce (if a null {@link NonceGenerator}
 * instance is passed to the function). A higher layer should check whether or
 * not this should be allowed.
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class DecryptedPacket {
	/** The <ode>NULL</code> command is commonly used for acknowledgement. */
	public static final byte CMD_NULL = 0x00;
	public static final byte CMD_LOGIN = 0x01;
	public static final byte CMD_LOGOUT = 0x02;
	public static final byte CMD_MSG = 0x03;
	public static final byte CMD_CHAT = 0x04;
	public static final byte CMD_FTP = 0x05;
	public static final byte CMD_LIST = 0x06;
	public static final byte CMD_CREATESECRET = 0x07;
	public static final byte CMD_SECRETLIST = 0x08;
	public static final byte CMD_GETSECRET = 0x09;
	
	/**
	 * The <code>GETPUBLICKEY</code> command is used to request the public key
	 * of a user from the server.
	 */
	public static final byte CMD_GETPUBLICKEY = 0x0A;
	
	/*
	 * Payment-specific commands
	 */
	
	/**
	 * The {@link Client} sends a <code>CMD_PAYMENT</code> packet to the
	 * {@link Server} to provide payment for a secret.
	 */
	public static final byte CMD_PAYMENT = 0x40;
	
	/**
	 * The {@link Server} sends a <code>CMD_REQUESTPAYMENT</code> packet to the
	 * {@link Client} to request additional payment for a secret.
	 */
	public static final byte CMD_REQUESTPAYMENT = 0x41;
	
	/**
	 * The {@link Client} sends a <code>CMD_SIGNPAYMENT</code> packet to the
	 * {@link Bank} to request that the bank sign a hash chain.
	 */
	public static final byte CMD_SIGNPAYMENT = 0x42;
	
	/**
	 * The {@link Client} sends a <code>CMD_GETBALANCE</code> packet to either
	 * the {@link Bank} or the {@link Server} to request the client's account
	 * balance.
	 */
	public static final byte CMD_GETBALANCE = 0x43;
	
	/*
	 * Security-specific commands - these should never be returned to a client
{'fraction_non_alphanumeric': 0.15703749231714811, 'fraction_numerical': 0.015365703749231715, 'mean_word_length': 4.30480847595762, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595219', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1781, 'n_words': 690}