Skip to content

Commit

Permalink
add addSubkeyBindingCertification method to PGPPublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Valodim committed Aug 23, 2014
1 parent 338cff3 commit 526d233
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pg/src/main/java/org/spongycastle/openpgp/PGPPublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.spongycastle.bcpg.ElGamalPublicBCPGKey;
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
import org.spongycastle.bcpg.PublicKeyPacket;
import org.spongycastle.bcpg.PublicSubkeyPacket;
import org.spongycastle.bcpg.RSAPublicBCPGKey;
import org.spongycastle.bcpg.TrustPacket;
import org.spongycastle.bcpg.UserAttributePacket;
Expand Down Expand Up @@ -898,6 +899,35 @@ private static PGPPublicKey removeCert(
return returnKey;
}

/**
* Add a subkey binding certification, changing the key type from master to subkey.
*
* @param key the key the revocation is to be added to.
* @param certification the key signature to be added.
* @return the new changed public key object.
*/
public static PGPPublicKey addSubkeyBindingCertification(
PGPPublicKey key,
PGPSignature certification)
{
// make sure no subSigs are previously present
if (!key.isMasterKey())
{
throw new IllegalArgumentException("key is already a subkey!");
}

PGPPublicKey returnKey = new PGPPublicKey(key);

// change the packet type from key to subkey
returnKey.publicPk = new PublicSubkeyPacket(
returnKey.publicPk.getAlgorithm(), returnKey.publicPk.getTime(), returnKey.publicPk.getKey());

returnKey.subSigs = new ArrayList();
returnKey.subSigs.add(certification);
return returnKey;
}


/**
* Add a revocation or some other key certification to a key.
*
Expand Down

0 comments on commit 526d233

Please sign in to comment.