001/*
002 * Copyright 2019, Digi International Inc.
003 *
004 * This Source Code Form is subject to the terms of the Mozilla Public
005 * License, v. 2.0. If a copy of the MPL was not distributed with this
006 * file, you can obtain one at http://mozilla.org/MPL/2.0/.
007 *
008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
015 */
016package com.digi.xbee.api.models;
017
018import java.util.HashMap;
019
020/**
021 * Enumerates the available steps of the SRP authentication.
022 *
023 * @since 1.3.0
024 */
025public enum SrpStep {
026
027        // Enumeration types.
028        STEP_1(0x01, "Step 1: client presents A value"),
029        STEP_2(0x02, "Step 2: server presents B and salt"),
030        STEP_3(0x03, "Step 3: client presents M1 session key validation value"),
031        STEP_4(0x04, "Step 4: server presents M2 session key validation value and two 12-byte nonces"),
032        UNKNOWN(-1, "Unknown");
033
034        // Variables.
035        private int id;
036
037        private String description;
038
039        private static HashMap<Integer, SrpStep> lookupTable = new HashMap<>();
040
041        static {
042                for (SrpStep step : values())
043                        lookupTable.put(step.getID(), step);
044        }
045
046        /**
047         * Class constructor. Instantiates a new {@code SrpStep} entry with
048         * the given parameters.
049         *
050         * @param id {@code SrpStep} ID code.
051         * @param description {@code SrpStep} description.
052         */
053        SrpStep(int id, String description) {
054                this.id = id;
055                this.description = description;
056        }
057        
058        /**
059         * Retrieves the {@code SrpStep} ID code.
060         * 
061         * @return {@code SrpStep} ID code.
062         */
063        public int getID() {
064                return id;
065        }
066        
067        /**
068         * Retrieves the {@code SrpStep} description.
069         * 
070         * @return {@code SrpStep} description.
071         */
072        public String getDescription() {
073                return description;
074        }
075        
076        /**
077         * Retrieves the {@code SrpStep} for the given ID code.
078         * 
079         * @param id ID code to retrieve the {@code SrpStep}.
080         * 
081         * @return The {@code SrpStep} associated with the given ID code,
082         *         {@code UNKNOWN} if there is not any SRP step associated
083         *         to the provided ID.
084         */
085        public static SrpStep get(int id) {
086                if (lookupTable.get(id) != null)
087                        return lookupTable.get(id);
088                return UNKNOWN;
089        }
090}