001/*
002 * acme4j - Java ACME client
003 *
004 * Copyright (C) 2015 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;
017import java.util.Locale;
018
019/**
020 * An enumeration of status codes of challenges and authorizations.
021 */
022public enum Status {
023
024    /**
025     * The server has created the resource, and is waiting for the client to process it.
026     */
027    PENDING,
028
029    /**
030     * The {@link Order} is ready to be finalized. Invoke {@link Order#execute(byte[])}.
031     */
032    READY,
033
034    /**
035     * The server is processing the resource. The client should invoke
036     * {@link AcmeJsonResource#update()} and re-check the status.
037     */
038    PROCESSING,
039
040    /**
041     * The resource is valid and can be used as intended.
042     */
043    VALID,
044
045    /**
046     * An error or authorization/validation failure has occured. The client should check
047     * for error messages.
048     */
049    INVALID,
050
051    /**
052     * The {@link Authorization} has been revoked by the server.
053     */
054    REVOKED,
055
056    /**
057     * The {@link Account} or {@link Authorization} has been deactivated by the client.
058     */
059    DEACTIVATED,
060
061    /**
062     * The {@link Authorization} is expired.
063     */
064    EXPIRED,
065
066    /**
067     * An auto-renewing {@link Order} is canceled.
068     *
069     * @since 2.3
070     */
071    CANCELED,
072
073    /**
074     * The server did not provide a status, or the provided status is not a specified ACME
075     * status.
076     */
077    UNKNOWN;
078
079    /**
080     * Parses the string and returns a corresponding Status object.
081     *
082     * @param str
083     *            String to parse
084     * @return {@link Status} matching the string, or {@link Status#UNKNOWN} if there was
085     *         no match
086     */
087    public static Status parse(String str) {
088        var check = str.toUpperCase(Locale.ENGLISH);
089        return Arrays.stream(values())
090                .filter(s -> s.name().equals(check))
091                .findFirst()
092                .orElse(Status.UNKNOWN);
093    }
094
095}