Skip to content

Commit 05f9709

Browse files
committed
Implement PreferredKeyServer signature subpacket
1 parent b8e4716 commit 05f9709

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.bouncycastle.bcpg.sig.PolicyURI;
1717
import org.bouncycastle.bcpg.sig.PreferredAEADCiphersuites;
1818
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
19+
import org.bouncycastle.bcpg.sig.PreferredKeyServer;
1920
import org.bouncycastle.bcpg.sig.PrimaryUserID;
2021
import org.bouncycastle.bcpg.sig.RegularExpression;
2122
import org.bouncycastle.bcpg.sig.Revocable;
@@ -168,6 +169,8 @@ else if (l == 255)
168169
return new PreferredAlgorithms(type, isCritical, isLongLength, data);
169170
case PREFERRED_AEAD_ALGORITHMS:
170171
return new PreferredAEADCiphersuites(isCritical, isLongLength, data);
172+
case PREFERRED_KEY_SERV:
173+
return new PreferredKeyServer(isCritical, isLongLength, data);
171174
case KEY_FLAGS:
172175
return new KeyFlags(isCritical, isLongLength, data);
173176
case POLICY_URL:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.bouncycastle.bcpg.sig;
2+
3+
import org.bouncycastle.bcpg.SignatureSubpacket;
4+
import org.bouncycastle.bcpg.SignatureSubpacketTags;
5+
import org.bouncycastle.util.Arrays;
6+
import org.bouncycastle.util.Strings;
7+
8+
public class PreferredKeyServer
9+
extends SignatureSubpacket
10+
{
11+
public PreferredKeyServer(boolean critical, boolean isLongLength, byte[] data)
12+
{
13+
super(SignatureSubpacketTags.PREFERRED_KEY_SERV, critical, isLongLength, data);
14+
}
15+
16+
public PreferredKeyServer(boolean critical, String uri)
17+
{
18+
this(critical, false, Strings.toUTF8ByteArray(uri));
19+
}
20+
21+
public String getURI()
22+
{
23+
return Strings.fromUTF8ByteArray(data);
24+
}
25+
26+
public byte[] getRawURI()
27+
{
28+
return Arrays.clone(data);
29+
}
30+
}

pg/src/main/java/org/bouncycastle/openpgp/PGPSignatureSubpacketGenerator.java

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.bouncycastle.bcpg.sig.NotationData;
1919
import org.bouncycastle.bcpg.sig.PolicyURI;
2020
import org.bouncycastle.bcpg.sig.PreferredAlgorithms;
21+
import org.bouncycastle.bcpg.sig.PreferredKeyServer;
2122
import org.bouncycastle.bcpg.sig.PrimaryUserID;
2223
import org.bouncycastle.bcpg.sig.RegularExpression;
2324
import org.bouncycastle.bcpg.sig.Revocable;
@@ -202,6 +203,18 @@ public void setPreferredAEADAlgorithms(boolean isCritical, int[] algorithms)
202203
algorithms));
203204
}
204205

206+
/**
207+
* Specify the preferred key server for the signed user-id / key.
208+
* Note, that the key server might also be a http/ftp etc. URI pointing to the key itself.
209+
*
210+
* @param isCritical true if the subpacket should be treated as critical
211+
* @param uri key server URI
212+
*/
213+
public void setPreferredKeyServer(boolean isCritical, String uri)
214+
{
215+
packets.add(new PreferredKeyServer(isCritical, uri));
216+
}
217+
205218
public void addPolicyURI(boolean isCritical, String policyUri)
206219
{
207220
packets.add(new PolicyURI(isCritical, policyUri));

0 commit comments

Comments
 (0)