1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 06:12:06 +01:00

Merge branch 'master' of github.com:vanitasvitae/pgpainless

This commit is contained in:
Paul Schaub 2018-07-02 20:09:58 +02:00
commit 3295b31516
3 changed files with 0 additions and 191 deletions

View file

@ -1,59 +0,0 @@
/*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.pgpainless;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
public abstract class KeyFilter {
public Set<Long> filter(Set<Long> initialIdSet, PGPPublicKeyRingCollection collection) {
Set<PGPPublicKeyRing> rings = new HashSet<>();
for (Iterator<PGPPublicKeyRing> i = collection.getKeyRings(); i.hasNext();) {
rings.add(i.next());
}
return filter(initialIdSet, rings, false);
}
public Set<Long> filter(Set<Long> initialIdSet, Set<PGPPublicKeyRing> rings, boolean boolToAvoidSameMethodErasure) {
Set<PGPPublicKey> keys = new HashSet<>();
for (PGPPublicKeyRing ring : rings) {
for (Iterator<PGPPublicKey> i = ring.getPublicKeys(); i.hasNext();) {
keys.add(i.next());
}
}
return filter(initialIdSet, keys);
}
public Set<Long> filter(Set<Long> initialIdSet, Set<PGPPublicKey> keys) {
Set<Long> filteredIds = new HashSet<>();
for (Long id : initialIdSet) {
for (PGPPublicKey key : keys) {
if (key.getKeyID() == id && filter(key)) {
filteredIds.add(id);
}
}
}
return filteredIds;
}
public abstract boolean filter(PGPPublicKey key);
}

View file

@ -1,55 +0,0 @@
/*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.pgpainless;
import java.util.Arrays;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKey;
public class PGPv4Fingerprint {
private final byte[] fingerprintBytes;
public PGPv4Fingerprint(PGPPublicKey publicKey) {
if (publicKey.getVersion() != 4) {
throw new IllegalArgumentException("PublicKey is not a OpenPGP v4 Public Key.");
}
this.fingerprintBytes = publicKey.getFingerprint();
}
public PGPv4Fingerprint(PGPSecretKey secretKey) {
this(secretKey.getPublicKey());
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (!(o instanceof PGPv4Fingerprint)) {
return false;
}
return Arrays.equals(fingerprintBytes, ((PGPv4Fingerprint) o).fingerprintBytes);
}
@Override
public int hashCode() {
return Arrays.hashCode(fingerprintBytes);
}
}

View file

@ -1,77 +0,0 @@
/*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.pgpainless;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public interface PainlessStream {
boolean isClosed();
class In extends InputStream implements PainlessStream {
private final InputStream inputStream;
private boolean isClosed = false;
public In(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public int read() throws IOException {
return inputStream.read();
}
@Override
public void close() throws IOException {
inputStream.close();
isClosed = true;
}
@Override
public boolean isClosed() {
return isClosed;
}
}
class Out extends OutputStream implements PainlessStream {
private final OutputStream outputStream;
private boolean isClosed = false;
public Out(OutputStream outputStream) {
this.outputStream = outputStream;
}
@Override
public boolean isClosed() {
return isClosed;
}
@Override
public void write(int i) throws IOException {
outputStream.write(i);
}
@Override
public void close() throws IOException {
outputStream.close();
this.isClosed = true;
}
}
}