001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package org.pgpainless.util;
006
007import java.io.IOException;
008import java.io.InputStream;
009
010import org.bouncycastle.bcpg.ArmoredInputStream;
011
012public final class ArmoredInputStreamFactory {
013
014    private ArmoredInputStreamFactory() {
015
016    }
017
018    public static ArmoredInputStream get(InputStream inputStream) throws IOException {
019        if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
020            return (ArmoredInputStream) inputStream;
021        }
022        if (inputStream instanceof ArmoredInputStream) {
023            return new CRCingArmoredInputStreamWrapper((ArmoredInputStream) inputStream);
024        }
025
026        ArmoredInputStream armorIn = new ArmoredInputStream(inputStream);
027        return new CRCingArmoredInputStreamWrapper(armorIn);
028    }
029}