@@ -82,6 +82,9 @@ private void performTests(APIProvider apiProvider)
82
82
testGenerateClassicKeyBaseCase (apiProvider );
83
83
testGenerateProtectedTypicalKey (apiProvider );
84
84
85
+ testGenerateEd25519x25519Key (apiProvider );
86
+ testGenerateEd448x448Key (apiProvider );
87
+
85
88
testEnforcesPrimaryOrSubkeyType (apiProvider );
86
89
}
87
90
@@ -236,6 +239,100 @@ private void testGenerateProtectedTypicalKey(APIProvider apiProvider)
236
239
}
237
240
}
238
241
242
+ private void testGenerateEd25519x25519Key (APIProvider apiProvider )
243
+ throws PGPException
244
+ {
245
+ Date currentTime = currentTimeRounded ();
246
+ String userId = "Foo <bar@baz>" ;
247
+ OpenPGPV6KeyGenerator generator = apiProvider .getKeyGenerator (currentTime );
248
+
249
+ PGPSecretKeyRing secretKey = generator .ed25519x25519Key (userId , null );
250
+
251
+ Iterator <PGPSecretKey > iterator = secretKey .getSecretKeys ();
252
+ PGPSecretKey primaryKey = iterator .next ();
253
+ PGPSecretKey signingSubkey = iterator .next ();
254
+ PGPSecretKey encryptionSubkey = iterator .next ();
255
+ isFalse ("Unexpected key" , iterator .hasNext ());
256
+
257
+ isEquals (PublicKeyAlgorithmTags .Ed25519 , primaryKey .getPublicKey ().getAlgorithm ());
258
+ Iterator <PGPSignature > keySignatures = primaryKey .getPublicKey ().getKeySignatures ();
259
+ PGPSignature directKeySignature = keySignatures .next ();
260
+ isFalse (keySignatures .hasNext ());
261
+ PGPSignatureSubpacketVector hashedSubpackets = directKeySignature .getHashedSubPackets ();
262
+ isEquals (KeyFlags .CERTIFY_OTHER , hashedSubpackets .getKeyFlags ());
263
+
264
+ Iterator <String > userIds = primaryKey .getUserIDs ();
265
+ isEquals (userId , userIds .next ());
266
+ isFalse (userIds .hasNext ());
267
+ Iterator <PGPSignature > userIdSignatures = primaryKey .getPublicKey ().getSignaturesForID (userId );
268
+ PGPSignature userIdSig = userIdSignatures .next ();
269
+ isFalse (userIdSignatures .hasNext ());
270
+ isEquals (PGPSignature .POSITIVE_CERTIFICATION , userIdSig .getSignatureType ());
271
+
272
+ isEquals (PublicKeyAlgorithmTags .Ed25519 , signingSubkey .getPublicKey ().getAlgorithm ());
273
+ Iterator <PGPSignature > signingSubkeySigs = signingSubkey .getPublicKey ().getKeySignatures ();
274
+ PGPSignature signingSubkeySig = signingSubkeySigs .next ();
275
+ isFalse (signingSubkeySigs .hasNext ());
276
+ isEquals (PGPSignature .SUBKEY_BINDING , signingSubkeySig .getSignatureType ());
277
+ hashedSubpackets = signingSubkeySig .getHashedSubPackets ();
278
+ isEquals (KeyFlags .SIGN_DATA , hashedSubpackets .getKeyFlags ());
279
+
280
+ isEquals (PublicKeyAlgorithmTags .X25519 , encryptionSubkey .getPublicKey ().getAlgorithm ());
281
+ Iterator <PGPSignature > encryptionSubkeySigs = encryptionSubkey .getPublicKey ().getKeySignatures ();
282
+ PGPSignature encryptionSubkeySig = encryptionSubkeySigs .next ();
283
+ isFalse (encryptionSubkeySigs .hasNext ());
284
+ isEquals (PGPSignature .SUBKEY_BINDING , encryptionSubkeySig .getSignatureType ());
285
+ hashedSubpackets = encryptionSubkeySig .getHashedSubPackets ();
286
+ isEquals (KeyFlags .ENCRYPT_COMMS | KeyFlags .ENCRYPT_STORAGE , hashedSubpackets .getKeyFlags ());
287
+ }
288
+
289
+ private void testGenerateEd448x448Key (APIProvider apiProvider )
290
+ throws PGPException
291
+ {
292
+ Date currentTime = currentTimeRounded ();
293
+ String userId = "Foo <bar@baz>" ;
294
+ OpenPGPV6KeyGenerator generator = apiProvider .getKeyGenerator (currentTime );
295
+
296
+ PGPSecretKeyRing secretKey = generator .ed448x448Key (userId , null );
297
+
298
+ Iterator <PGPSecretKey > iterator = secretKey .getSecretKeys ();
299
+ PGPSecretKey primaryKey = iterator .next ();
300
+ PGPSecretKey signingSubkey = iterator .next ();
301
+ PGPSecretKey encryptionSubkey = iterator .next ();
302
+ isFalse ("Unexpected key" , iterator .hasNext ());
303
+
304
+ isEquals (PublicKeyAlgorithmTags .Ed448 , primaryKey .getPublicKey ().getAlgorithm ());
305
+ Iterator <PGPSignature > keySignatures = primaryKey .getPublicKey ().getKeySignatures ();
306
+ PGPSignature directKeySignature = keySignatures .next ();
307
+ isFalse (keySignatures .hasNext ());
308
+ PGPSignatureSubpacketVector hashedSubpackets = directKeySignature .getHashedSubPackets ();
309
+ isEquals (KeyFlags .CERTIFY_OTHER , hashedSubpackets .getKeyFlags ());
310
+
311
+ Iterator <String > userIds = primaryKey .getUserIDs ();
312
+ isEquals (userId , userIds .next ());
313
+ isFalse (userIds .hasNext ());
314
+ Iterator <PGPSignature > userIdSignatures = primaryKey .getPublicKey ().getSignaturesForID (userId );
315
+ PGPSignature userIdSig = userIdSignatures .next ();
316
+ isFalse (userIdSignatures .hasNext ());
317
+ isEquals (PGPSignature .POSITIVE_CERTIFICATION , userIdSig .getSignatureType ());
318
+
319
+ isEquals (PublicKeyAlgorithmTags .Ed448 , signingSubkey .getPublicKey ().getAlgorithm ());
320
+ Iterator <PGPSignature > signingSubkeySigs = signingSubkey .getPublicKey ().getKeySignatures ();
321
+ PGPSignature signingSubkeySig = signingSubkeySigs .next ();
322
+ isFalse (signingSubkeySigs .hasNext ());
323
+ isEquals (PGPSignature .SUBKEY_BINDING , signingSubkeySig .getSignatureType ());
324
+ hashedSubpackets = signingSubkeySig .getHashedSubPackets ();
325
+ isEquals (KeyFlags .SIGN_DATA , hashedSubpackets .getKeyFlags ());
326
+
327
+ isEquals (PublicKeyAlgorithmTags .X448 , encryptionSubkey .getPublicKey ().getAlgorithm ());
328
+ Iterator <PGPSignature > encryptionSubkeySigs = encryptionSubkey .getPublicKey ().getKeySignatures ();
329
+ PGPSignature encryptionSubkeySig = encryptionSubkeySigs .next ();
330
+ isFalse (encryptionSubkeySigs .hasNext ());
331
+ isEquals (PGPSignature .SUBKEY_BINDING , encryptionSubkeySig .getSignatureType ());
332
+ hashedSubpackets = encryptionSubkeySig .getHashedSubPackets ();
333
+ isEquals (KeyFlags .ENCRYPT_COMMS | KeyFlags .ENCRYPT_STORAGE , hashedSubpackets .getKeyFlags ());
334
+ }
335
+
239
336
private void testGenerateCustomKey (APIProvider apiProvider )
240
337
throws PGPException
241
338
{
0 commit comments