mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Fixed return value of process().
This commit is contained in:
@@ -26,14 +26,14 @@ interface AuthenticatedCipher {
|
|||||||
* including the MAC.
|
* including the MAC.
|
||||||
* @param inputOff the offset into the input array where the data to be
|
* @param inputOff the offset into the input array where the data to be
|
||||||
* processed starts.
|
* processed starts.
|
||||||
* @param len the number of bytes to be processed. If decrypting, includes
|
* @param len the length of the input. If decrypting, includes the MAC
|
||||||
* the MAC length.
|
* length.
|
||||||
* @param output the output buffer the processed bytes go into. If
|
* @param output the output byte array. If encrypting, the ciphertext
|
||||||
* encrypting, the ciphertext including the MAC. If
|
* including the MAC. If decrypting, the plaintext.
|
||||||
* decrypting, the plaintext.
|
* @param outputOff the offset into the output byte array where the
|
||||||
* @param outputOff the offset into the output byte array the processed
|
* processed data starts.
|
||||||
* data starts at.
|
* @return the length of the output. If encrypting, includes the MAC
|
||||||
* @return the number of bytes processed.
|
* length.
|
||||||
* @throws GeneralSecurityException on invalid input.
|
* @throws GeneralSecurityException on invalid input.
|
||||||
*/
|
*/
|
||||||
int process(byte[] input, int inputOff, int len, byte[] output,
|
int process(byte[] input, int inputOff, int len, byte[] output,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class XSalsa20Poly1305AuthenticatedCipher
|
|||||||
poly1305.doFinal(output, outputOff);
|
poly1305.doFinal(output, outputOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
return processed;
|
return encrypting ? processed + MAC_LENGTH : processed;
|
||||||
} catch (DataLengthException e) {
|
} catch (DataLengthException e) {
|
||||||
throw new GeneralSecurityException(e.getMessage());
|
throw new GeneralSecurityException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class XSalsa20Poly1305AuthenticatedCipherTest extends BriarTestCase {
|
public class XSalsa20Poly1305AuthenticatedCipherTest extends BriarTestCase {
|
||||||
|
|
||||||
@@ -51,7 +52,8 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BriarTestCase {
|
|||||||
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
||||||
cipher.init(true, k, TEST_IV);
|
cipher.init(true, k, TEST_IV);
|
||||||
byte[] output = new byte[TEST_CIPHERTEXT.length];
|
byte[] output = new byte[TEST_CIPHERTEXT.length];
|
||||||
cipher.process(TEST_PLAINTEXT, 0, TEST_PLAINTEXT.length, output, 0);
|
assertEquals(TEST_CIPHERTEXT.length, cipher.process(TEST_PLAINTEXT, 0,
|
||||||
|
TEST_PLAINTEXT.length, output, 0));
|
||||||
assertArrayEquals(TEST_CIPHERTEXT, output);
|
assertArrayEquals(TEST_CIPHERTEXT, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +63,8 @@ public class XSalsa20Poly1305AuthenticatedCipherTest extends BriarTestCase {
|
|||||||
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher();
|
||||||
cipher.init(false, k, TEST_IV);
|
cipher.init(false, k, TEST_IV);
|
||||||
byte[] output = new byte[TEST_PLAINTEXT.length];
|
byte[] output = new byte[TEST_PLAINTEXT.length];
|
||||||
cipher.process(TEST_CIPHERTEXT, 0, TEST_CIPHERTEXT.length, output, 0);
|
assertEquals(TEST_PLAINTEXT.length, cipher.process(TEST_CIPHERTEXT, 0,
|
||||||
|
TEST_CIPHERTEXT.length, output, 0));
|
||||||
assertArrayEquals(TEST_PLAINTEXT, output);
|
assertArrayEquals(TEST_PLAINTEXT, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user