Skip to content

Commit e757540

Browse files
committed
Implement builder class for PreferredAEADCiphersuites
1 parent 896741c commit e757540

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pg/src/main/java/org/bouncycastle/bcpg/sig/PreferredAEADCiphersuites.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.bouncycastle.bcpg.SignatureSubpacketTags;
55
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
66

7+
import java.util.ArrayList;
8+
import java.util.List;
9+
710
public class PreferredAEADCiphersuites
811
extends PreferredAlgorithms
912
{
@@ -144,6 +147,51 @@ private static byte[] requireEven(byte[] encodedCombinations)
144147
return encodedCombinations;
145148
}
146149

150+
/**
151+
* Return a {@link Builder} for constructing a {@link PreferredAEADCiphersuites} packet.
152+
* @param isCritical true if the packet is considered critical.
153+
* @return builder
154+
*/
155+
public static Builder builder(boolean isCritical)
156+
{
157+
return new Builder(isCritical);
158+
}
159+
160+
public static final class Builder
161+
{
162+
163+
private final List<Combination> combinations = new ArrayList<>();
164+
private final boolean isCritical;
165+
166+
private Builder(boolean isCritical)
167+
{
168+
this.isCritical = isCritical;
169+
}
170+
171+
/**
172+
* Add a combination of cipher- and AEAD algorithm to the list of supported ciphersuites.
173+
* @see SymmetricKeyAlgorithmTags for cipher algorithms
174+
* @see AEADAlgorithmTags for AEAD algorithms
175+
* @param symmetricAlgorithmId symmetric cipher algorithm ID
176+
* @param aeadAlgorithmId AEAD algorithm ID
177+
* @return builder
178+
*/
179+
public Builder addCombination(int symmetricAlgorithmId, int aeadAlgorithmId)
180+
{
181+
combinations.add(new Combination(symmetricAlgorithmId, aeadAlgorithmId));
182+
return this;
183+
}
184+
185+
/**
186+
* Build a {@link PreferredAEADCiphersuites} from this builder.
187+
* @return finished packet
188+
*/
189+
public PreferredAEADCiphersuites build()
190+
{
191+
return new PreferredAEADCiphersuites(isCritical, combinations.toArray(new Combination[0]));
192+
}
193+
}
194+
147195
/**
148196
* Algorithm combination of a {@link SymmetricKeyAlgorithmTags} and a {@link AEADAlgorithmTags}.
149197
*/

0 commit comments

Comments
 (0)