Java 类org.bouncycastle.openpgp.PGPKeyRing 实例源码

项目:subshare    文件:BcWithLocalGnuPgPgp.java   
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;
}
项目:packagedrone    文件:PgpHelper.java   
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 );
}
项目:packagedrone    文件:PgpHelper.java   
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 );
}