mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-29 10:32:08 +01:00
Kotlin conversion: Dearmor
This commit is contained in:
parent
34e1d8992f
commit
39c222dfc8
2 changed files with 46 additions and 59 deletions
|
@ -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));
|
||||
}
|
||||
}
|
46
sop-java/src/main/kotlin/sop/operation/Dearmor.kt
Normal file
46
sop-java/src/main/kotlin/sop/operation/Dearmor.kt
Normal 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))
|
||||
}
|
Loading…
Reference in a new issue