// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.crypto;

import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.crypto.impl.HMAC;
import com.nimbusds.jose.util.Base64URL;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.jwk.OctetSequenceKey;
import javax.crypto.SecretKey;
import com.nimbusds.jose.util.StandardCharset;
import com.nimbusds.jose.KeyLengthException;
import com.nimbusds.jose.shaded.jcip.ThreadSafe;
import com.nimbusds.jose.JWSSigner;
import com.nimbusds.jose.crypto.impl.MACProvider;

@ThreadSafe
public class MACSigner extends MACProvider implements JWSSigner
{
    public MACSigner(final byte[] secret) throws KeyLengthException {
        super(secret);
    }
    
    public MACSigner(final String secretString) throws KeyLengthException {
        this(secretString.getBytes(StandardCharset.UTF_8));
    }
    
    public MACSigner(final SecretKey secretKey) throws KeyLengthException {
        super(secretKey);
    }
    
    public MACSigner(final OctetSequenceKey jwk) throws KeyLengthException {
        this(jwk.toByteArray());
    }
    
    @Override
    public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException {
        this.ensureSecretLengthSatisfiesAlgorithm(header.getAlgorithm());
        final String jcaAlg = MACProvider.getJCAAlgorithmName(header.getAlgorithm());
        final byte[] hmac = HMAC.compute(jcaAlg, this.getSecretKey(), signingInput, this.getJCAContext().getProvider());
        return Base64URL.encode(hmac);
    }
}
