Example usage for org.bouncycastle.bcpg ArmoredInputStream getArmorHeaderLine

List of usage examples for org.bouncycastle.bcpg ArmoredInputStream getArmorHeaderLine

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg ArmoredInputStream getArmorHeaderLine.

Prototype

public String getArmorHeaderLine() 

Source Link

Document

Return the armor header line (if there is one)

Usage

From source file:org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation.java

License:Open Source License

@NonNull
private DecryptVerifyResult executeInternal(PgpDecryptVerifyInputParcel input, CryptoInputParcel cryptoInput,
        InputData inputData, OutputStream outputStream) {
    try {/*from  ww w.  j ava 2 s .c  om*/
        if (input.getDetachedSignature() != null) {
            Log.d(Constants.TAG, "Detached signature present, verifying with this signature only");

            return verifyDetachedSignature(input, inputData, outputStream, 0);
        } else {
            // automatically works with PGP ascii armor and PGP binary
            InputStream inputStream = PGPUtil.getDecoderStream(inputData.getInputStream());

            if (inputStream instanceof ArmoredInputStream) {
                ArmoredInputStream aIn = (ArmoredInputStream) inputStream;
                // it is ascii armored
                Log.d(Constants.TAG, "ASCII Armor Header Line: " + aIn.getArmorHeaderLine());

                if (aIn.isClearText()) {
                    // a cleartext signature, verify it with the other method
                    return verifyCleartextSignature(input, aIn, outputStream, 0);
                } else {
                    // else: ascii armored encryption! go on...
                    return decryptVerify(input, cryptoInput, inputData, inputStream, outputStream, 0);
                }
            } else {
                return decryptVerify(input, cryptoInput, inputData, inputStream, outputStream, 0);
            }
        }
    } catch (PGPException e) {
        Log.d(Constants.TAG, "PGPException", e);
        OperationLog log = new OperationLog();
        log.add(LogType.MSG_DC_ERROR_PGP_EXCEPTION, 1);
        return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
    } catch (DecoderException | ArrayIndexOutOfBoundsException e) {
        // these can happen if assumptions in JcaPGPObjectFactory.nextObject() aren't
        // fulfilled, so we need to catch them here to handle this gracefully
        Log.d(Constants.TAG, "data error", e);
        OperationLog log = new OperationLog();
        log.add(LogType.MSG_DC_ERROR_IO, 1);
        return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
    } catch (IOException e) {
        Log.d(Constants.TAG, "IOException", e);
        OperationLog log = new OperationLog();
        log.add(LogType.MSG_DC_ERROR_IO, 1);
        return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
    }
}