<commit_before>package org.coriander.oauth.core.cryptography.signing

import org.apache.commons.codec.binary.Base64.encodeBase64
import org.coriander.oauth.core.uri._
import org.coriander.oauth.core.CredentialSet
import org.coriander.oauth.core.cryptography.Sha1
import org.coriander.oauth.core.signing.Signature

class HmacSha1Signature(urlEncoder : UrlEncoder, credentials : CredentialSet) extends Signature {
    def this(
        urlEncoder  : UrlEncoder,
        credentials : CredentialSet,
        sha1   		: Sha1
    ) {
        this(urlEncoder, credentials)
        this.sha1 = sha1
    }

    def this(credentials : CredentialSet) = this(
		new OAuthUrlEncoder,
		credentials
	)

    def sign(baseString : String) = {
        validate
		
        getSignature(baseString);
    }

    private def getSignature(baseString : String) : String = {
		val signature = sha1.create(formatKey, baseString)
		new String(encodeBase64(signature))
    }

    // See: http://oauth.net/core/1.0, section 9.2
    private def formatKey : String = {
        %%(getConsumerSecret) + "&" + %%(getTokenSecret)<commit_msg>Added todo. Because we've changed the Signature abstraction, perhaps we no longer need the Sha1. If not then we need to convert tests from behaviour verification back to result verification.<commit_after>package org.coriander.oauth.core.cryptography.signing

import org.apache.commons.codec.binary.Base64.encodeBase64
import org.coriander.oauth.core.uri._
import org.coriander.oauth.core.CredentialSet
import org.coriander.oauth.core.cryptography.Sha1
import org.coriander.oauth.core.signing.Signature

// TODO: Do we need the sha1 abstraction any longer?
class HmacSha1Signature(urlEncoder : UrlEncoder, credentials : CredentialSet) extends Signature {
    def this(
        urlEncoder  : UrlEncoder,
        credentials : CredentialSet,
        sha1   		: Sha1
    ) {
        this(urlEncoder, credentials)
        this.sha1 = sha1
    }

    def this(credentials : CredentialSet) = this(
		new OAuthUrlEncoder,
		credentials
	)

    def sign(baseString : String) = {
        validate
		
        getSignature(baseString);
    }

    private def getSignature(baseString : String) : String = {
		val signature = sha1.create(formatKey, baseString)
		new String(encodeBase64(signature))
    }

    // See: http://oauth.net/core/1.0, section 9.2
    private def formatKey : String = {
        %%(getConsumerSecret) + "&" + %%(getTokenSecret)
{'fraction_non_alphanumeric': 0.09607522485690924, 'fraction_numerical': 0.014717906786590351, 'mean_word_length': 3.315696649029982, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4822039', 'n_tokens_mistral': 797, 'n_tokens_neox': 747, 'n_words': 165}