001package com.nimbusds.srp6;
002
003
004/**
005 * Secure Remote Password (SRP-6a) exception.
006 *
007 * @author Vladimir Dzhuvinov
008 */
009public class SRP6Exception extends Exception {
010
011
012        private static final long serialVersionUID = 4640494990301260666L;
013
014
015        /**
016         * SRP-6a exception causes.
017         */
018        public static enum CauseType {
019        
020        
021                /**
022                 * Invalid public client or server value ('A' or 'B').
023                 */
024                BAD_PUBLIC_VALUE,
025                
026                
027                /**
028                 * Invalid credentials (password).
029                 */
030                BAD_CREDENTIALS,
031                
032                
033                /**
034                 * SRP-6a authentication session timeout.
035                 */
036                TIMEOUT
037        }
038        
039        
040        /**
041         * The cause type.
042         */
043        private CauseType cause;
044
045
046        /**
047         * Creates a new Secure Remote Password (SRP-6a) exception with the 
048         * specified message.
049         *
050         * @param message The exception message.
051         * @param cause   The exception cause type. Must not be {@code null}.
052         */
053        public SRP6Exception(final String message, final CauseType cause) {
054        
055                super(message);
056                
057                if (cause == null)
058                        throw new IllegalArgumentException("The cause type must not be null");
059                
060                this.cause = cause;
061        }
062        
063        
064        /**
065         * Gets the cause type for this exception.
066         *
067         * @return The exception cause type.
068         */
069        public CauseType getCauseType() {
070        
071                return cause;
072        }
073}