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.
#1743 Add LibrePGP PreferredEncryptionModes signature subpacket
- Loading branch information
Showing
10 changed files
with
307 additions
and
10 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
23 changes: 23 additions & 0 deletions
23
pg/src/main/java/org/bouncycastle/bcpg/sig/LibrePGPPreferredEncryptionModes.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,23 @@ | ||
package org.bouncycastle.bcpg.sig; | ||
|
||
import org.bouncycastle.bcpg.SignatureSubpacketTags; | ||
|
||
/** | ||
* This is a deprecated LibrePGP signature subpacket with encryption mode numbers to indicate which modes | ||
* the key holder prefers to use with OCB Encrypted Data Packets ({@link org.bouncycastle.bcpg.AEADEncDataPacket}). | ||
* Implementations SHOULD ignore this subpacket and assume {@link org.bouncycastle.bcpg.AEADAlgorithmTags#OCB}. | ||
*/ | ||
public class LibrePGPPreferredEncryptionModes | ||
extends PreferredAlgorithms | ||
{ | ||
|
||
public LibrePGPPreferredEncryptionModes(boolean isCritical, int[] encryptionModes) | ||
{ | ||
this(isCritical, false, intToByteArray(encryptionModes)); | ||
} | ||
|
||
public LibrePGPPreferredEncryptionModes(boolean critical, boolean isLongLength, byte[] data) | ||
{ | ||
super(SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES, critical, isLongLength, data); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
pg/src/test/java/org/bouncycastle/bcpg/test/SignatureSubpacketsTest.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,54 @@ | ||
package org.bouncycastle.bcpg.test; | ||
|
||
import org.bouncycastle.bcpg.AEADAlgorithmTags; | ||
import org.bouncycastle.bcpg.SignatureSubpacketTags; | ||
import org.bouncycastle.bcpg.sig.LibrePGPPreferredEncryptionModes; | ||
import org.bouncycastle.util.Arrays; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
public class SignatureSubpacketsTest | ||
extends AbstractPacketTest | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return "SignatureSubpacketsTest"; | ||
} | ||
|
||
@Override | ||
public void performTest() | ||
throws Exception | ||
{ | ||
testLibrePGPPreferredEncryptionModesSubpacket(); | ||
} | ||
|
||
private void testLibrePGPPreferredEncryptionModesSubpacket() | ||
throws IOException | ||
{ | ||
int[] algorithms = new int[] {AEADAlgorithmTags.EAX, AEADAlgorithmTags.OCB}; | ||
LibrePGPPreferredEncryptionModes encModes = new LibrePGPPreferredEncryptionModes( | ||
false, algorithms); | ||
|
||
isTrue("Encryption Modes encoding mismatch", | ||
Arrays.areEqual(algorithms, encModes.getPreferences())); | ||
isFalse("Mismatch in critical flag", encModes.isCritical()); | ||
|
||
// encode to byte array and check correctness | ||
ByteArrayOutputStream bOut = new ByteArrayOutputStream(); | ||
encModes.encode(bOut); | ||
|
||
isEncodingEqual("Packet encoding mismatch", new byte[]{ | ||
3, // length | ||
SignatureSubpacketTags.LIBREPGP_PREFERRED_ENCRYPTION_MODES, | ||
AEADAlgorithmTags.EAX, | ||
AEADAlgorithmTags.OCB | ||
}, bOut.toByteArray()); | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
runTest(new SignatureSubpacketsTest()); | ||
} | ||
} |
Oops, something went wrong.