mirrored from https://www.bouncycastle.org/repositories/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unpacking time (unsigned int) from octets for large values
- Loading branch information
1 parent
7352222
commit 95ca87a
Showing
3 changed files
with
43 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
pg/src/test/java/org/bouncycastle/bcpg/test/UtilsTest.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,40 @@ | ||
package org.bouncycastle.bcpg.test; | ||
|
||
import org.bouncycastle.bcpg.sig.KeyExpirationTime; | ||
import org.bouncycastle.util.test.SimpleTest; | ||
|
||
public class UtilsTest | ||
extends SimpleTest | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return "UtilsTest"; | ||
} | ||
|
||
@Override | ||
public void performTest() | ||
throws Exception | ||
{ | ||
testRoundtrippingLargeUnsignedInt(); | ||
} | ||
|
||
private void testRoundtrippingLargeUnsignedInt() | ||
{ | ||
// Integer.MAX_VALUE < large < 0xffffffff | ||
long large = 2523592696L; // fits a 32-bit *unsigned* int, but overflows signed int | ||
// KeyExpirationTime packs the time into 4 octets | ||
KeyExpirationTime kexp = new KeyExpirationTime(false, large); | ||
// getTime() parses the time from 4 octets | ||
isEquals("Roundtripped unsigned int mismatches before packet parser pass", large, kexp.getTime()); | ||
|
||
// To be safe, do an additional packet encode/decode roundtrip | ||
KeyExpirationTime pKexp = new KeyExpirationTime(kexp.isCritical(), kexp.isLongLength(), kexp.getData()); | ||
isEquals("Roundtripped unsigned int mismatches after packet parser pass", large, pKexp.getTime()); | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
runTest(new UtilsTest()); | ||
} | ||
} |