mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Refactor CleartextSignatureProcessor to allow reuse in DetachInbandSignatureAndMessage
This commit is contained in:
parent
40dfa6528a
commit
772f69788b
14 changed files with 498 additions and 203 deletions
|
@ -32,7 +32,6 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.exception.NotYetImplementedException;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
|
@ -50,21 +49,13 @@ public class DecryptImpl implements Decrypt {
|
|||
|
||||
@Override
|
||||
public DecryptImpl verifyNotBefore(Date timestamp) throws SOPGPException.UnsupportedOption {
|
||||
try {
|
||||
consumerOptions.verifyNotBefore(timestamp);
|
||||
} catch (NotYetImplementedException e) {
|
||||
throw new SOPGPException.UnsupportedOption();
|
||||
}
|
||||
consumerOptions.verifyNotBefore(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DecryptImpl verifyNotAfter(Date timestamp) throws SOPGPException.UnsupportedOption {
|
||||
try {
|
||||
consumerOptions.verifyNotAfter(timestamp);
|
||||
} catch (NotYetImplementedException e) {
|
||||
throw new SOPGPException.UnsupportedOption();
|
||||
}
|
||||
consumerOptions.verifyNotAfter(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright 2021 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.sop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||
import org.pgpainless.signature.cleartext_signatures.ClearsignedMessageUtil;
|
||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||
import sop.ReadyWithResult;
|
||||
import sop.Signatures;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.operation.DetachInbandSignatureAndMessage;
|
||||
|
||||
public class DetachInbandSignatureAndMessageImpl implements DetachInbandSignatureAndMessage {
|
||||
|
||||
private boolean armor = true;
|
||||
|
||||
@Override
|
||||
public DetachInbandSignatureAndMessage noArmor() {
|
||||
this.armor = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadyWithResult<Signatures> message(InputStream messageInputStream) {
|
||||
|
||||
return new ReadyWithResult<Signatures>() {
|
||||
@Override
|
||||
public Signatures writeTo(OutputStream messageOutputStream) throws SOPGPException.NoSignature {
|
||||
|
||||
return new Signatures() {
|
||||
@Override
|
||||
public void writeTo(OutputStream signatureOutputStream) throws IOException {
|
||||
PGPSignatureList signatures = ClearsignedMessageUtil.detachSignaturesFromInbandClearsignedMessage(messageInputStream, messageOutputStream);
|
||||
if (armor) {
|
||||
ArmoredOutputStream armorOut = ArmoredOutputStreamFactory.get(signatureOutputStream);
|
||||
for (PGPSignature signature : signatures) {
|
||||
signature.encode(armorOut);
|
||||
}
|
||||
armorOut.close();
|
||||
} else {
|
||||
for (PGPSignature signature : signatures) {
|
||||
signature.encode(signatureOutputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import sop.SOP;
|
|||
import sop.operation.Armor;
|
||||
import sop.operation.Dearmor;
|
||||
import sop.operation.Decrypt;
|
||||
import sop.operation.DetachInbandSignatureAndMessage;
|
||||
import sop.operation.Encrypt;
|
||||
import sop.operation.ExtractCert;
|
||||
import sop.operation.GenerateKey;
|
||||
|
@ -72,4 +73,9 @@ public class SOPImpl implements SOP {
|
|||
public Dearmor dearmor() {
|
||||
return new DearmorImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DetachInbandSignatureAndMessage detachInbandSignatureAndMessage() {
|
||||
return new DetachInbandSignatureAndMessageImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.pgpainless.PGPainless;
|
|||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||
import org.pgpainless.exception.NotYetImplementedException;
|
||||
import org.pgpainless.key.SubkeyIdentifier;
|
||||
import sop.Verification;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -41,21 +40,13 @@ public class VerifyImpl implements Verify {
|
|||
|
||||
@Override
|
||||
public Verify notBefore(Date timestamp) throws SOPGPException.UnsupportedOption {
|
||||
try {
|
||||
options.verifyNotBefore(timestamp);
|
||||
} catch (NotYetImplementedException e) {
|
||||
throw new SOPGPException.UnsupportedOption();
|
||||
}
|
||||
options.verifyNotBefore(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Verify notAfter(Date timestamp) throws SOPGPException.UnsupportedOption {
|
||||
try {
|
||||
options.verifyNotAfter(timestamp);
|
||||
} catch (NotYetImplementedException e) {
|
||||
throw new SOPGPException.UnsupportedOption();
|
||||
}
|
||||
options.verifyNotAfter(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue