Skip to content

Commit

Permalink
Fixed code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Sep 29, 2017
1 parent 5e0d157 commit c4ebb26
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/main/java/jpass/crypt/Aes256.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private byte[] rotate(byte[] value) {

/**
* Expands the key. The incoming key is {@code KEY_SIZE} {@code byte}s long. It will be expanded
* to a length of {@code EXPANDED_KEY_SIZE} {@code byte}s. The expdanded key will be stored in
* to a length of {@code EXPANDED_KEY_SIZE} {@code byte}s. The expanded key will be stored in
* {@link Aes256#_expandedKey}.
* <p>
* The encryption and decryption will use the expanded key.
Expand Down Expand Up @@ -276,16 +276,16 @@ private void addRoundKey(int index) {
}

/**
* The polynom represented by {@code b} will be multiplied by its free variable. This
* multiplication takes place in a finite field. The resulting polynom can still be represented
* The polynomial represented by {@code b} will be multiplied by its free variable. This
* multiplication takes place in a finite field. The resulting polynomial can still be represented
* in one {@code byte}.
* <p>
* The bits {@code 0} to {@code 7} are the coefficients of the powers {@code x} to {@code x**8}.
* </p>
*
* @param b origin polynom
* @param b origin polynomial
*
* @return multiplied polynom
* @return multiplied polynomial
*/
private int times2(int b) {
int result = b << 1;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/jpass/crypt/Cbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public class Cbc {
/**
* cipher
*/
private Aes256 _cipher;
private final Aes256 _cipher;

/**
* last calculated block
*/
private byte[] _current;
private final byte[] _current;

/**
* temporary block. It will only be used for decryption.
Expand All @@ -65,7 +65,7 @@ public class Cbc {
/**
* temporary block.
*/
private byte[] _tmp;
private final byte[] _tmp;

/**
* buffer of the last output block. It will only be used for decryption.
Expand All @@ -80,14 +80,14 @@ public class Cbc {
/**
* temporary buffer to accumulate whole blocks of data
*/
private byte[] _overflow;
private final byte[] _overflow;

/**
* How many {@code byte}s of {@link Cbc#_overflow} are used?
*/
private int _overflowUsed;

private OutputStream _output;
private final OutputStream _output;

/**
* Creates the temporary buffers.
Expand Down Expand Up @@ -129,7 +129,7 @@ private void encryptBlock(byte[] inBuffer, byte[] outBuffer) {
* @param inBuffer storage of the encrypted block
* @param outBuffer storage of the decrypted block
*/
private void decryptBlock(byte[] inBuffer, byte[] outBuffer) {
private void decryptBlock(byte[] inBuffer) {
System.arraycopy(inBuffer, 0, this._buffer, 0, BLOCK_SIZE);
this._cipher.decrypt(this._buffer, 0, this._tmp, 0);
for (int i = 0; i < BLOCK_SIZE; ++i) {
Expand Down Expand Up @@ -205,7 +205,7 @@ public void decrypt(byte[] data, int length) throws IOException {
if (this._outBufferUsed) {
this._output.write(this._outBuffer);
}
decryptBlock(this._overflow, this._outBuffer);
decryptBlock(this._overflow);
this._outBufferUsed = true;
this._overflowUsed = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jpass/crypt/io/CryptInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public class CryptInputStream extends InputStream {
/**
* Underlying stream that provides the encrypted data.
*/
private InputStream _parent;
private final InputStream _parent;

/**
* Cipher.
*/
private Cbc _cipher;
private final Cbc _cipher;

private ByteArrayOutputStream _decrypted;
private final ByteArrayOutputStream _decrypted;

/**
* Buffer of unencrypted data. If the buffer is completely returned, another chunk of data will
Expand All @@ -78,7 +78,7 @@ public class CryptInputStream extends InputStream {
/**
* Buffer for storing the encrypted data.
*/
private byte[] _fetchBuffer = new byte[FETCH_BUFFER_SIZE];
private final byte[] _fetchBuffer = new byte[FETCH_BUFFER_SIZE];

/**
* Signals, if the last encrypted data was read. If we run out of buffers, the stream is at its
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jpass/crypt/io/CryptOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public class CryptOutputStream extends OutputStream {
/**
* Cipher.
*/
private Cbc _cipher;
private final Cbc _cipher;

/**
* Buffer for sending single {@code byte}s.
*/
private byte[] _buffer = new byte[1];
private final byte[] _buffer = new byte[1];

/**
* Initializes the cipher with the given key and initial values.
Expand Down Expand Up @@ -101,7 +101,7 @@ public void write(int b) throws IOException {
/**
* Encrypts a {@code byte} array.
*
* @param b {@code byte} array te be encrypted
* @param b {@code byte} array to be encrypted
* @throws IOException if encrypted data can't be written to the underlying stream
*/
@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/jpass/ui/GeneratePasswordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class GeneratePasswordDialog extends JDialog implements ActionListe
/**
* Options for password generation.
*/
private static final String[][] passwordOptions = {
private static final String[][] PASSWORD_OPTIONS = {
{"Upper case letters (A-Z)", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
{"Lower case letters (a-z)", "abcdefghijklmnopqrstuvwxyz"},
{"Numbers (0-9)", "0123456789"}
Expand All @@ -97,7 +97,7 @@ public final class GeneratePasswordDialog extends JDialog implements ActionListe

private String generatedPassword;

private Random random = CryptUtils.newRandomNumberGenerator();
private final Random random = CryptUtils.newRandomNumberGenerator();

/**
* Constructor of GeneratePasswordDialog.
Expand Down Expand Up @@ -151,9 +151,9 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
this.charactersPanel = new JPanel();
this.charactersPanel.setBorder(new TitledBorder("Settings"));
this.charactersPanel.add(this.lengthPanel);
this.checkBoxes = new JCheckBox[passwordOptions.length];
for (int i = 0; i < passwordOptions.length; i++) {
this.checkBoxes[i] = new JCheckBox(passwordOptions[i][0], true);
this.checkBoxes = new JCheckBox[PASSWORD_OPTIONS.length];
for (int i = 0; i < PASSWORD_OPTIONS.length; i++) {
this.checkBoxes[i] = new JCheckBox(PASSWORD_OPTIONS[i][0], true);
this.charactersPanel.add(this.checkBoxes[i]);
}
this.customSymbolsCheck = new JCheckBox("Custom symbols");
Expand Down Expand Up @@ -220,9 +220,9 @@ public void actionPerformed(ActionEvent e) {
this.customSymbolsField.setEditable(((JCheckBox) e.getSource()).isSelected());
} else if ("generate_button".equals(command)) {
String characterSet = "";
for (int i = 0; i < passwordOptions.length; i++) {
for (int i = 0; i < PASSWORD_OPTIONS.length; i++) {
if (this.checkBoxes[i].isSelected()) {
characterSet += passwordOptions[i][1];
characterSet += PASSWORD_OPTIONS[i][1];
}
}

Expand Down

0 comments on commit c4ebb26

Please sign in to comment.