001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.transport.hmac;
027:
028: import com.sshtools.j2ssh.configuration.ConfigurationException;
029: import com.sshtools.j2ssh.configuration.ConfigurationLoader;
030: import com.sshtools.j2ssh.transport.AlgorithmNotSupportedException;
031:
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034:
035: import java.util.ArrayList;
036: import java.util.HashMap;
037: import java.util.Iterator;
038: import java.util.List;
039: import java.util.Map;
040:
041: /**
042: *
043: *
044: * @author $author$
045: * @version $Revision: 1.30 $
046: */
047: public class SshHmacFactory {
048: private static String defaultAlgorithm;
049: private static Map macs;
050: private static Log log = LogFactory.getLog(SshHmacFactory.class);
051:
052: static {
053: macs = new HashMap();
054:
055: log.info("Loading message authentication methods");
056:
057: macs.put("hmac-sha1", HmacSha.class);
058: macs.put("hmac-sha1-96", HmacSha96.class);
059: macs.put("hmac-md5", HmacMd5.class);
060: macs.put("hmac-md5-96", HmacMd596.class);
061:
062: defaultAlgorithm = "hmac-sha1";
063: }
064:
065: /**
066: * Creates a new SshHmacFactory object.
067: */
068: protected SshHmacFactory() {
069: }
070:
071: /**
072: *
073: */
074: public static void initialize() {
075: }
076:
077: /**
078: *
079: *
080: * @return
081: */
082: public final static String getDefaultHmac() {
083: return defaultAlgorithm;
084: }
085:
086: /**
087: *
088: *
089: * @return
090: */
091: public static List getSupportedMacs() {
092: return new ArrayList(macs.keySet());
093: }
094:
095: /**
096: *
097: *
098: * @param methodName
099: *
100: * @return
101: *
102: * @throws AlgorithmNotSupportedException
103: */
104: public static SshHmac newInstance(String methodName)
105: throws AlgorithmNotSupportedException {
106: try {
107: return (SshHmac) ((Class) macs.get(methodName))
108: .newInstance();
109: } catch (Exception e) {
110: throw new AlgorithmNotSupportedException(methodName
111: + " is not supported!");
112: }
113: }
114: }
|