private BcPgpKey enlistPublicKey(final Map<PgpKeyId, BcPgpKey> pgpKeyId2bcPgpKey, final Map<PgpKeyId, BcPgpKey> pgpKeyId2masterKey, BcPgpKey masterKey, final PGPKeyRing keyRing, final PGPPublicKey publicKey) { final PgpKeyId pgpKeyId = new PgpKeyId(publicKey.getKeyID()); BcPgpKey bcPgpKey = pgpKeyId2bcPgpKey.get(pgpKeyId); if (bcPgpKey == null) { bcPgpKey = new BcPgpKey(this, pgpKeyId); pgpKeyId2bcPgpKey.put(pgpKeyId, bcPgpKey); } if (keyRing instanceof PGPSecretKeyRing) bcPgpKey.setSecretKeyRing((PGPSecretKeyRing)keyRing); else if (keyRing instanceof PGPPublicKeyRing) bcPgpKey.setPublicKeyRing((PGPPublicKeyRing)keyRing); else throw new IllegalArgumentException("keyRing is neither an instance of PGPSecretKeyRing nor PGPPublicKeyRing!"); bcPgpKey.setPublicKey(publicKey); if (publicKey.isMasterKey()) { masterKey = bcPgpKey; pgpKeyId2masterKey.put(bcPgpKey.getPgpKeyId(), bcPgpKey); } else { if (masterKey == null) throw new IllegalStateException("First key is a non-master key!"); bcPgpKey.setMasterKey(masterKey); masterKey.getSubKeyIds().add(bcPgpKey.getPgpKeyId()); } return masterKey; }
public static Stream<PGPSecretKeyRing> streamSecretKeyring ( final InputStream input ) throws IOException, PGPException { final Stream<PGPKeyRing> s = streamKeyring ( input ); return s.filter ( k -> k instanceof PGPSecretKeyRing ).map ( o -> (PGPSecretKeyRing)o ); }
public static Stream<PGPKeyRing> streamKeyring ( final InputStream input ) throws IOException, PGPException { final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection ( PGPUtil.getDecoderStream ( input ) ); final Iterator<?> keyRingIter = keyrings.getKeyRings (); final Stream<?> s = StreamSupport.stream ( Spliterators.spliteratorUnknownSize ( keyRingIter, Spliterator.ORDERED ), false ); return s.map ( o -> (PGPKeyRing)o ); }