01: /*
02: * @(#)CryptoException.java 1.7 02/07/24 @(#)
03: *
04: * Copyright (c) 2000-2002 Sun Microsystems, Inc. All rights reserved.
05: * PROPRIETARY/CONFIDENTIAL
06: * Use is subject to license terms.
07: */
08:
09: package com.sun.portal.ksecurity;
10:
11: /**
12: * Implements CryptoException which is thrown when a cryptographic
13: * method encounters an error.
14: */
15: public class CryptoException extends Exception {
16: /** Indicates illegal use of a method. */
17: public static final short ILLEGAL_USE = 1;
18: /** Indicates a method was passed illegal parameter values. */
19: public static final short ILLEGAL_VALUE = 2;
20: /**
21: * Indicates an object has not been properly initilaized for the
22: * requested operation.
23: */
24: public static final short INVALID_INIT = 3;
25: /** Indicates that a requested algorithm or key type is not supported. */
26: public static final short NO_SUCH_ALGORITHM = 4;
27: /** Indicates that is key object has not been properly initialized. */
28: public static final short UNINITIALIZED_KEY = 5;
29: /** Indicates that encrypted message was illegal encoded. */
30: public static final short ILLEGAL_ENCODING = 6;
31: /** Reason code for this crytographic exception. */
32: private short why;
33:
34: /**
35: * Constructs a CryptoException with the specified reason code.
36: * @param reason reason code
37: */
38: public CryptoException(short reason) {
39: why = reason;
40: }
41:
42: /**
43: * Throws a CryptoException with the specified reason code.
44: * @param reason reason code
45: * @exception CryptoException with the specified reason code
46: */
47: public static void throwIt(short reason) throws CryptoException {
48: throw new CryptoException(reason);
49: }
50:
51: /**
52: * Returns a human readable string describing the CryptoException.
53: * @return string representation of the CryptoException
54: */
55: public String toString() {
56: String tmp = "com.sun.portal.ksecurity.CryptoException (";
57: switch (why) {
58: case ILLEGAL_USE:
59: tmp += "Illegal use";
60: break;
61: case ILLEGAL_VALUE:
62: tmp += "Illegal value";
63: break;
64: case INVALID_INIT:
65: tmp += "Invalid initialization";
66: break;
67: case NO_SUCH_ALGORITHM:
68: tmp += "No such algorithm";
69: break;
70: case UNINITIALIZED_KEY:
71: tmp += "Uninitialized key";
72: break;
73: case ILLEGAL_ENCODING:
74: tmp += "Encrypted message illegally encoded";
75: break;
76: }
77: return (tmp + ")");
78: }
79: }
|