mirrored from https://www.bouncycastle.org/repositories/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sanity checks for boolean flags - related to github #1575
- Loading branch information
Showing
5 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
pg/src/test/java/org/bouncycastle/openpgp/test/BytesBooleansTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.bouncycastle.util.utiltest; | ||
|
||
import junit.framework.TestCase; | ||
import org.bouncycastle.bcpg.sig.PrimaryUserID; | ||
|
||
public class BytesBooleansTest | ||
extends TestCase | ||
{ | ||
public void testParseFalse() | ||
{ | ||
PrimaryUserID primaryUserID = new PrimaryUserID(true, false); | ||
|
||
byte[] bFalse = primaryUserID.getData(); | ||
assertEquals(1, bFalse.length); | ||
assertEquals(0, bFalse[0]); | ||
assertFalse(primaryUserID.isPrimaryUserID()); | ||
} | ||
|
||
public void testParseTrue() | ||
{ | ||
PrimaryUserID primaryUserID = new PrimaryUserID(true, true); | ||
|
||
byte[] bTrue = primaryUserID.getData(); | ||
|
||
assertEquals(1, bTrue.length); | ||
assertEquals(1, bTrue[0]); | ||
assertTrue(primaryUserID.isPrimaryUserID()); | ||
} | ||
|
||
public void testParseTooShort() | ||
{ | ||
PrimaryUserID primaryUserID = new PrimaryUserID(true, false, new byte[0]); | ||
byte[] bTooShort = primaryUserID.getData(); | ||
try | ||
{ | ||
primaryUserID.isPrimaryUserID(); | ||
fail("Should throw."); | ||
} | ||
catch (IllegalStateException e) | ||
{ | ||
// expected. | ||
} | ||
} | ||
|
||
public void testParseTooLong() | ||
{ | ||
PrimaryUserID primaryUserID = new PrimaryUserID(true, false, new byte[42]); | ||
byte[] bTooLong = primaryUserID.getData(); | ||
|
||
try | ||
{ | ||
primaryUserID.isPrimaryUserID(); | ||
fail("Should throw."); | ||
} | ||
catch (IllegalStateException e) | ||
{ | ||
// expected. | ||
} | ||
} | ||
} |