Kotlin conversion: Dearmor

This commit is contained in:
Paul Schaub 2023-10-31 14:03:18 +01:00
parent 34e1d8992f
commit 39c222dfc8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 46 additions and 59 deletions

View file

@ -1,59 +0,0 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.operation;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import sop.Ready;
import sop.exception.SOPGPException;
import sop.util.UTF8Util;
public interface Dearmor {
/**
* Dearmor armored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
*
* @throws SOPGPException.BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
Ready data(InputStream data)
throws SOPGPException.BadData,
IOException;
/**
* Dearmor armored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
*
* @throws SOPGPException.BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
default Ready data(byte[] data)
throws SOPGPException.BadData,
IOException {
return data(new ByteArrayInputStream(data));
}
/**
* Dearmor amored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
*
* @throws SOPGPException.BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
default Ready data(String data)
throws SOPGPException.BadData,
IOException {
return data(data.getBytes(UTF8Util.UTF8));
}
}

View file

@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.operation
import java.io.IOException
import java.io.InputStream
import sop.Ready
import sop.exception.SOPGPException.BadData
import sop.util.UTF8Util
interface Dearmor {
/**
* Dearmor armored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
* @throws BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
@Throws(BadData::class, IOException::class) fun data(data: InputStream): Ready
/**
* Dearmor armored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
* @throws BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
@Throws(BadData::class, IOException::class)
fun data(data: ByteArray): Ready = data(data.inputStream())
/**
* Dearmor amored OpenPGP data.
*
* @param data armored OpenPGP data
* @return input stream of unarmored data
* @throws BadData in case of non-OpenPGP data
* @throws IOException in case of an IO error
*/
@Throws(BadData::class, IOException::class)
fun data(data: String): Ready = data(data.toByteArray(UTF8Util.UTF8))
}