<commit_before>package org.knowm.xchange.abucoins.service;

import java.io.IOException;
import java.util.Base64;
import javax.crypto.Mac;
import org.knowm.xchange.abucoins.Abucoins;
import org.knowm.xchange.abucoins.dto.AbucoinsServerTime;
import org.knowm.xchange.service.BaseParamsDigest;
import si.mazi.rescu.RestInvocation;

/** @author bryant_harris */
public class AbucoinsDigest extends BaseParamsDigest {
  static AbucoinsDigest instance;
  long timeDiffFromServer = 0;

  private AbucoinsDigest(Abucoins abucoins, String secretKeyBase64)
      throws IllegalArgumentException {
    super(
        secretKeyBase64 == null ? null : Base64.getDecoder().decode(secretKeyBase64), HMAC_SHA_256);

    try {
      AbucoinsServerTime serverTime = abucoins.getTime();

      long ourTime = System.currentTimeMillis() / 1000L;
      timeDiffFromServer = serverTime.getEpoch() - ourTime;
    } catch (IOException e) {
      throw new RuntimeException("Unable to determine server time");
    }
  }

  public static AbucoinsDigest createInstance(Abucoins abucoins, String secretKeyBase64) {
    if (instance == null)
      instance = secretKeyBase64 == null ? null : new AbucoinsDigest(abucoins, secretKeyBase64);
    return instance;
  }

  @Override
  public String digestParams(RestInvocation restInvocation) {
    String timestamp = restInvocation.getHttpHeadersFromParams().get("AC-ACCESS-TIMESTAMP");
    String method = restInvocation.getHttpMethod();
    String path = restInvocation.getPath();
    String queryParameters = restInvocation.getQueryString();
    String body = restInvocation.getRequestBody();
    body = body == null ? "" : body;

    String queryArgs = timestamp + method + path + (queryParameters + body);
    Mac shaMac = getMac();
    final byte[] macData = shaMac.doFinal(queryArgs.getBytes());
    return Base64.getEncoder().encodeToString(macData);
  }

  public String timestamp() {
    return String.valueOf((System.currentTimeMillis() / 1000) + timeDiffFromServer);
  }
}<commit_msg>[abucoins] fixed digest to allow multiple API keys to be used in a single jvm<commit_after>package org.knowm.xchange.abucoins.service;

import org.knowm.xchange.abucoins.Abucoins;
import org.knowm.xchange.abucoins.dto.AbucoinsServerTime;
import org.knowm.xchange.service.BaseParamsDigest;
import si.mazi.rescu.RestInvocation;

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

/** @author bryant_harris */
public class AbucoinsDigest extends BaseParamsDigest {
  private final long timeDiffFromServer;

  private AbucoinsDigest(Abucoins abucoins, String secretKeyBase64) throws IllegalArgumentException {
    super(secretKeyBase64 == null ? null : Base64.getDecoder().decode(secretKeyBase64), HMAC_SHA_256);

    try {
      AbucoinsServerTime serverTime = abucoins.getTime();

      long ourTime = System.currentTimeMillis() / 1000L;
      timeDiffFromServer = serverTime.getEpoch() - ourTime;
    } catch (IOException e) {
      throw new RuntimeException("Unable to determine server time");
    }
  }

  public static AbucoinsDigest createInstance(Abucoins abucoins, String secretKeyBase64) {
    return secretKeyBase64 == null ? null : new AbucoinsDigest(abucoins, secretKeyBase64);
  }

  @Override
  public String digestParams(RestInvocation restInvocation) {
    String timestamp = restInvocation.getHttpHeadersFromParams().get("AC-ACCESS-TIMESTAMP");
    String method = restInvocation.getHttpMethod();
    String path = restInvocation.getPath();
    String queryParameters = restInvocation.getQueryString();
    String body = restInvocation.getRequestBody();
    body = body == null ? "" : body;

    String queryArgs = timestamp + method + path + (queryParameters + body);
    Mac shaMac = getMac();
    final byte[] macData = shaMac.doFinal(queryArgs.getBytes());
    return Base64.getEncoder().encodeToString(macData);
  }

  public String timestamp() {
    return String.valueOf((System.currentTimeMillis() / 1000) + timeDiffFromServer);
  }
}
{'fraction_non_alphanumeric': 0.10007505629221916, 'fraction_numerical': 0.014761070803102327, 'mean_word_length': 4.560500695410292, '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': '5016266', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1210, 'n_words': 264}