001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2021 Richard "Shred" K├Ârber
005 *   http://acme4j.shredzone.org
006 *
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013 */
014package org.shredzone.acme4j.smime.csr;
015
016import org.bouncycastle.asn1.x509.KeyUsage;
017
018/**
019 * An enumeration of key usage types for S/MIME certificates.
020 *
021 * @since 2.12
022 */
023public enum KeyUsageType {
024
025    /**
026     * S/MIME certificate can be used only for signing.
027     */
028    SIGNING_ONLY(KeyUsage.digitalSignature),
029
030    /**
031     * S/MIME certificate can be used only for encryption.
032     */
033    ENCRYPTION_ONLY(KeyUsage.keyEncipherment),
034
035    /**
036     * S/MIME certificate can be used for both signing and encryption.
037     */
038    SIGNING_AND_ENCRYPTION(KeyUsage.digitalSignature | KeyUsage.keyEncipherment);
039
040    private final int keyUsage;
041
042    KeyUsageType(int keyUsage) {
043        this.keyUsage = keyUsage;
044    }
045
046    /**
047     * Returns the key usage bits to be used in the key usage extension of a CSR.
048     */
049    public int getKeyUsageBits() {
050        return keyUsage;
051    }
052
053}