All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.trend.cloudone.amaas.AMaasBaseReader Maven / Gradle / Ivy

There is a newer version: 1.4.4
Show newest version
package com.trend.cloudone.amaas;

/*
 * The abstract base class implements the hash methods of the AMaasReader interface.
 */
public abstract class AMaasBaseReader implements AMaasReader {
    private byte[] sha1;
    private byte[] sha256;

    /*
     * Method to convert a bytes array to Hex string.
     * @param bytes the given byte array to convert.
     * @return the converted hex string.
     */
    private static String bytesToHex(final byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }

    @Override
    public final String getHash(final HashType htype) {
        switch (htype) {
            case HASH_SHA1:
                return "sha1:" + bytesToHex(this.sha1);
            case HASH_SHA256:
                return "sha256:" + bytesToHex(this.sha256);
            default:
                return null;
        }
    }

    /*
     * Method to set the reader with a hash of the given type.
     * @param htype the type of the hash value.
     * @param hash the value of the hash to set.
     */
    protected final void setHash(final HashType htype, final byte[] hash) {
        switch (htype) {
            case HASH_SHA1:
                this.sha1 = hash;
            case HASH_SHA256:
                this.sha256 = hash;
            default:
                break;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy