From 47074e50b9761fa85d79a976fe9f5768c8e1be05 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 19 Jun 2018 17:13:57 +0200 Subject: [PATCH] Add method to get keyflags from integer --- .../crypto/pgpainless/algorithm/KeyFlag.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/de/vanitasvitae/crypto/pgpainless/algorithm/KeyFlag.java b/src/main/java/de/vanitasvitae/crypto/pgpainless/algorithm/KeyFlag.java index 9e626d49..6928eacb 100644 --- a/src/main/java/de/vanitasvitae/crypto/pgpainless/algorithm/KeyFlag.java +++ b/src/main/java/de/vanitasvitae/crypto/pgpainless/algorithm/KeyFlag.java @@ -15,6 +15,9 @@ */ package de.vanitasvitae.crypto.pgpainless.algorithm; +import java.util.ArrayList; +import java.util.List; + import org.bouncycastle.bcpg.sig.KeyFlags; public enum KeyFlag { @@ -37,4 +40,14 @@ public enum KeyFlag { public int getFlag() { return flag; } + + public static KeyFlag[] fromInteger(int bitmask) { + List flags = new ArrayList<>(); + for (KeyFlag f : KeyFlag.values()) { + if ((bitmask & f.flag) != 0) { + flags.add(f); + } + } + return flags.toArray(new KeyFlag[]{}); + } }