001/**
002 *
003 * Copyright 2014-2017 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.sasl.core;
018
019import java.security.InvalidKeyException;
020
021import org.jivesoftware.smack.sasl.SASLMechanism;
022import org.jivesoftware.smack.util.MAC;
023
024public class SCRAMSHA1Mechanism extends ScramMechanism {
025
026    static final int PRIORITY = 110;
027
028    static {
029        SHA_1_SCRAM_HMAC = new ScramHmac() {
030            @Override
031            public String getHmacName() {
032                return "SHA-1";
033            }
034            @Override
035            public byte[] hmac(byte[] key, byte[] str) throws InvalidKeyException {
036                return MAC.hmacsha1(key, str);
037            }
038        };
039        NAME = new SCRAMSHA1Mechanism().getName();
040    }
041
042    public static final String NAME;
043
044    static final ScramHmac SHA_1_SCRAM_HMAC;
045
046    public SCRAMSHA1Mechanism() {
047        super(SHA_1_SCRAM_HMAC);
048    }
049
050    @Override
051    public int getPriority() {
052        return PRIORITY;
053    }
054
055    @Override
056    protected SASLMechanism newInstance() {
057        return new SCRAMSHA1Mechanism();
058    }
059
060}