package io.paradoxical.cassieq.model.auth;

import com.godaddy.logging.Logger;

import javax.crypto.Mac;
import java.util.Base64;

import static com.godaddy.logging.LoggerFactory.getLogger;

/**
 * Signs paramters
 */
public abstract class SignatureGenerator {

    public String computeSignature(final Mac hmac) {
        final Logger logger = getLogger(SignatureGenerator.class);

        final String stringToSign = getStringToSign();

        final Base64.Encoder signatureEncoder = Base64.getUrlEncoder().withoutPadding();

        logger.with("signed-string", stringToSign).debug("Computing signature of string");

        final byte[] bytes = hmac.doFinal(stringToSign.getBytes());

        return signatureEncoder.encodeToString(bytes);
    }

    public abstract String getStringToSign();
}

@@ -71,16 +71,58 @@
 .Logger;
+%0Aimport com.google.common.io.BaseEncoding;
 %0A%0Aimport
@@ -237,23 +237,49 @@
 %0A * 
-Signs paramters
+Computes a signature of a string to sign.
 %0A */
@@ -323,16 +323,115 @@
 ator %7B%0A%0A
+    private static final BaseEncoding signatureEncoding = BaseEncoding.base64Url().omitPadding();%0A%0A
     publ
@@ -603,98 +603,8 @@
 );%0A%0A
-        final Base64.Encoder signatureEncoder = Base64.getUrlEncoder().withoutPadding();%0A%0A
     
@@ -793,25 +793,18 @@
 ncod
-er
+ing
 .encode
-ToString
 (byt

use guava encoding