001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2016 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; 015 016import java.util.Arrays; 017 018import edu.umd.cs.findbugs.annotations.Nullable; 019 020/** 021 * Enumeration of revocation reasons. 022 * 023 * @see <a href="https://tools.ietf.org/html/rfc5280#section-5.3.1">RFC 5280 Section 024 * 5.3.1</a> 025 */ 026public enum RevocationReason { 027 028 UNSPECIFIED(0), 029 KEY_COMPROMISE(1), 030 CA_COMPROMISE(2), 031 AFFILIATION_CHANGED(3), 032 SUPERSEDED(4), 033 CESSATION_OF_OPERATION(5), 034 CERTIFICATE_HOLD(6), 035 REMOVE_FROM_CRL(8), 036 PRIVILEGE_WITHDRAWN(9), 037 AA_COMPROMISE(10); 038 039 private final int reasonCode; 040 041 RevocationReason(int reasonCode) { 042 this.reasonCode = reasonCode; 043 } 044 045 /** 046 * Returns the reason code as defined in RFC 5280. 047 */ 048 public int getReasonCode() { 049 return reasonCode; 050 } 051 052 /** 053 * Returns the {@link RevocationReason} that matches the reason code. 054 * 055 * @param reasonCode 056 * Reason code as defined in RFC 5280 057 * @return Matching {@link RevocationReason}, or {@code null} if not known 058 */ 059 @Nullable 060 public static RevocationReason code(int reasonCode) { 061 return Arrays.stream(values()) 062 .filter(rr -> rr.reasonCode == reasonCode) 063 .findFirst() 064 .orElse(null); 065 } 066 067}