Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #31 from facebook/add_exception
Browse files Browse the repository at this point in the history
Improve some of the exception messages.
  • Loading branch information
siyengar committed Jun 19, 2014
2 parents 67da4cf + 84084bb commit e367516
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# relevant to BUCK
buck-out
/.buckconfig.local
.buckd
gen

# Editor generated files
Expand Down
4 changes: 3 additions & 1 deletion java/com/facebook/crypto/cipher/NativeGCMCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public void decryptFinal(byte[] expectedTag, int tagLen) throws NativeGCMCipherE
Assertions.checkState(mCurrentState == STATE.DECRYPT_INITIALIZED, CIPHER_NOT_INIT);
mCurrentState = STATE.DECRYPT_FINALIZED;
if (nativeDecryptFinal(expectedTag, tagLen) == nativeFailure()) {
throw new NativeGCMCipherException("decryptFinal");
throw new NativeGCMCipherException(
"The message could not be decrypted successfully." +
"It has either been tampered with or the wrong resource is being decrypted.");
}
}

Expand Down
4 changes: 4 additions & 0 deletions java/com/facebook/crypto/exception/KeyChainException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public class KeyChainException extends Exception {
public KeyChainException(String message) {
super(message);
}

public KeyChainException(String message, Throwable cause) {
super(message, cause);
}
}
6 changes: 3 additions & 3 deletions java/com/facebook/crypto/keychain/SecureRandomFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public synchronized void tryApplyFixes() throws KeyChainException {
} catch (Throwable t) {
// Practically, this should not crash.
// However we can't do much in this case if it does.
// This is a trade-off between security and usability which is intentional to prevent
// the client from crashing.
throw new KeyChainException("Random number generated");
// We would rather abort than using an insecure random number
// generator.
throw new KeyChainException("Random number generated", t);
}

mFixApplied = true;
Expand Down
2 changes: 2 additions & 0 deletions javatests/com/facebook/crypto/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ robolectric_test(
':crypto-test-helper',
'//:crypto',
'//third-party/junit:junit',
'//third-party/junit:hamcrest',
'//third-party/guava:guava',
'//third-party/robolectric2:robolectric2',
],
Expand All @@ -18,6 +19,7 @@ android_library(
srcs = glob(['**/*.java'], excludes = glob(['**/*Test.java'])),
deps = [
'//third-party/junit:junit',
'//third-party/junit:hamcrest',
'//third-party/robolectric2:robolectric2',
],
)
Expand Down
20 changes: 8 additions & 12 deletions third-party/junit/BUCK
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
java_library(
name = 'junit',
export_deps = True,
deps = [
':junit-jar',
':hamcrest-jar',
],
visibility = [ 'PUBLIC' ],
)

prebuilt_jar(
name = 'junit-jar',
name = 'junit',
binary_jar = 'junit-4.11.jar',
visibility = [
'//javatests/com/facebook/crypto:',
],
)

prebuilt_jar(
name = 'hamcrest-jar',
name = 'hamcrest',
binary_jar = 'hamcrest-core-1.3.jar',
visibility = [
'//javatests/com/facebook/crypto:',
],
)
14 changes: 3 additions & 11 deletions third-party/robolectric2/BUCK
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
java_library(
prebuilt_jar(
name = 'robolectric2',
export_deps = True,
deps = [
':robolectric2-jar',
],
binary_jar = 'robolectric-2.2-jar-with-dependencies.jar',
visibility = [
'PUBLIC',
'//javatests/com/facebook/crypto:',
],
)

prebuilt_jar(
name = 'robolectric2-jar',
binary_jar = 'robolectric-2.2-jar-with-dependencies.jar',
)

0 comments on commit e367516

Please sign in to comment.