mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 03:17:58 +01:00
Kotlin conversion: OpenPgpPacket
This commit is contained in:
parent
294c469a29
commit
eb07b94bcb
2 changed files with 46 additions and 71 deletions
|
@ -1,71 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.algorithm;
|
||||
|
||||
import org.bouncycastle.bcpg.PacketTags;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public enum OpenPgpPacket {
|
||||
PKESK(PacketTags.PUBLIC_KEY_ENC_SESSION),
|
||||
SIG(PacketTags.SIGNATURE),
|
||||
SKESK(PacketTags.SYMMETRIC_KEY_ENC_SESSION),
|
||||
OPS(PacketTags.ONE_PASS_SIGNATURE),
|
||||
SK(PacketTags.SECRET_KEY),
|
||||
PK(PacketTags.PUBLIC_KEY),
|
||||
SSK(PacketTags.SECRET_SUBKEY),
|
||||
COMP(PacketTags.COMPRESSED_DATA),
|
||||
SED(PacketTags.SYMMETRIC_KEY_ENC),
|
||||
MARKER(PacketTags.MARKER),
|
||||
LIT(PacketTags.LITERAL_DATA),
|
||||
TRUST(PacketTags.TRUST),
|
||||
UID(PacketTags.USER_ID),
|
||||
PSK(PacketTags.PUBLIC_SUBKEY),
|
||||
UATTR(PacketTags.USER_ATTRIBUTE),
|
||||
SEIPD(PacketTags.SYM_ENC_INTEGRITY_PRO),
|
||||
MDC(PacketTags.MOD_DETECTION_CODE),
|
||||
|
||||
EXP_1(PacketTags.EXPERIMENTAL_1),
|
||||
EXP_2(PacketTags.EXPERIMENTAL_2),
|
||||
EXP_3(PacketTags.EXPERIMENTAL_3),
|
||||
EXP_4(PacketTags.EXPERIMENTAL_4),
|
||||
;
|
||||
|
||||
static final Map<Integer, OpenPgpPacket> MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (OpenPgpPacket p : OpenPgpPacket.values()) {
|
||||
MAP.put(p.getTag(), p);
|
||||
}
|
||||
}
|
||||
|
||||
final int tag;
|
||||
|
||||
@Nullable
|
||||
public static OpenPgpPacket fromTag(int tag) {
|
||||
return MAP.get(tag);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static OpenPgpPacket requireFromTag(int tag) {
|
||||
OpenPgpPacket p = fromTag(tag);
|
||||
if (p == null) {
|
||||
throw new NoSuchElementException("No OpenPGP packet known for tag " + tag);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
OpenPgpPacket(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
int getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.algorithm
|
||||
|
||||
enum class OpenPgpPacket(val tag: Int) {
|
||||
PKESK(1),
|
||||
SIG(2),
|
||||
SKESK(3),
|
||||
OPS(4),
|
||||
SK(5),
|
||||
PK(6),
|
||||
SSK(7),
|
||||
COMP(8),
|
||||
SED(9),
|
||||
MARKER(10),
|
||||
LIT(11),
|
||||
TRUST(12),
|
||||
UID(13),
|
||||
PSK(14),
|
||||
UATTR(17),
|
||||
SEIPD(18),
|
||||
MDC(19),
|
||||
|
||||
EXP_1(60),
|
||||
EXP_2(61),
|
||||
EXP_3(62),
|
||||
EXP_4(63),
|
||||
;
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromTag(tag: Int): OpenPgpPacket? {
|
||||
return values().firstOrNull {
|
||||
it.tag == tag
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun requireFromTag(tag: Int): OpenPgpPacket {
|
||||
return fromTag(tag) ?:
|
||||
throw NoSuchElementException("No OpenPGP packet known for tag $tag")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue