<commit_before>package com.subgraph.orchid.data;

import java.util.Arrays;
import java.util.List;

import com.subgraph.orchid.TorException;
import com.subgraph.orchid.crypto.TorMessageDigest;
import com.subgraph.orchid.encoders.Hex;

/**
 * This class represents both digests and fingerprints that appear in directory
 * documents.  The names fingerprint and digest are used interchangeably in 
 * the specification but generally a fingerprint is a message digest (ie: SHA1)
 * over the DER ASN.1 encoding of a public key.  A digest is usually
 * a message digest over a set of fields in a directory document.
 * 
 * Digests always appear as a 40 character hex string:
 * 
 * 0EA20CAA3CE696E561BC08B15E00106700E8F682
 *
 * Fingerprints may either appear as a single hex string as above or sometimes in
 * a more easily human-parsed spaced format:
 * 
 * 1E0F 5874 2268 E82F C600 D81D 9064 07C5 7CC2 C3A7
 *
 */
public class HexDigest {
	public static HexDigest createFromStringList(List<String> strings) {
		StringBuilder builder = new StringBuilder();
		for(String chunk: strings) 
			builder.append(chunk);
		return createFromString(builder.toString());
	}

	public static HexDigest createFromString(String fingerprint) {
		final String[] parts = fingerprint.split(" ");
		if(parts.length > 1)
			return createFromStringList(Arrays.asList(parts));
		final byte[] digestData = Hex.decode(fingerprint);
		return new HexDigest(digestData);
	}

	public static HexDigest createFromDigestBytes(byte[] data) {
		return new HexDigest(data);
	}
	
	public static HexDigest createDigestForData(byte[] data) {<commit_msg>added method to create instance from base32 encoded string<commit_after>package com.subgraph.orchid.data;

import java.util.Arrays;
import java.util.List;

import com.subgraph.orchid.TorException;
import com.subgraph.orchid.crypto.TorMessageDigest;
import com.subgraph.orchid.encoders.Hex;

/**
 * This class represents both digests and fingerprints that appear in directory
 * documents.  The names fingerprint and digest are used interchangeably in 
 * the specification but generally a fingerprint is a message digest (ie: SHA1)
 * over the DER ASN.1 encoding of a public key.  A digest is usually
 * a message digest over a set of fields in a directory document.
 * 
 * Digests always appear as a 40 character hex string:
 * 
 * 0EA20CAA3CE696E561BC08B15E00106700E8F682
 *
 * Fingerprints may either appear as a single hex string as above or sometimes in
 * a more easily human-parsed spaced format:
 * 
 * 1E0F 5874 2268 E82F C600 D81D 9064 07C5 7CC2 C3A7
 *
 */
public class HexDigest {
	public static HexDigest createFromStringList(List<String> strings) {
		StringBuilder builder = new StringBuilder();
		for(String chunk: strings) 
			builder.append(chunk);
		return createFromString(builder.toString());
	}

	public static HexDigest createFromBase32String(String b32) {
		return new HexDigest(Base32.base32Decode(b32));
	}

	public static HexDigest createFromString(String fingerprint) {
		final String[] parts = fingerprint.split(" ");
		if(parts.length > 1)
			return createFromStringList(Arrays.asList(parts));
		final byte[] digestData = Hex.decode(fingerprint);
		return new HexDigest(digestData);
	}

	public static HexDigest createFromDigestBytes(byte[] data) {
		return new HexDigest(data);
	}
	
	public static HexDigest createDigestForData(byte[] data) {
{'fraction_non_alphanumeric': 0.07862843629914278, 'fraction_numerical': 0.03842743127401715, 'mean_word_length': 4.7846153846153845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949969', 'n_tokens_mistral': 1161, 'n_tokens_neox': 994, 'n_words': 338}