001/*
002 * Copyright 2018 Paul Schaub.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.pgpainless.algorithm;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.bouncycastle.bcpg.sig.KeyFlags;
022
023public enum KeyFlag {
024
025    CERTIFY_OTHER  (KeyFlags.CERTIFY_OTHER),
026    SIGN_DATA      (KeyFlags.SIGN_DATA),
027    ENCRYPT_COMMS  (KeyFlags.ENCRYPT_COMMS),
028    ENCRYPT_STORAGE(KeyFlags.ENCRYPT_STORAGE),
029    SPLIT          (KeyFlags.SPLIT),
030    AUTHENTICATION (KeyFlags.AUTHENTICATION),
031    SHARED         (KeyFlags.SHARED),
032    ;
033
034    private final int flag;
035
036    KeyFlag(int flag) {
037        this.flag = flag;
038    }
039
040    public int getFlag() {
041        return flag;
042    }
043
044    public static List<KeyFlag> fromInteger(int bitmask) {
045        List<KeyFlag> flags = new ArrayList<>();
046        for (KeyFlag f : KeyFlag.values()) {
047            if ((bitmask & f.flag) != 0) {
048                flags.add(f);
049            }
050        }
051        return flags;
052    }
053}