Base58Encoder.java
/*
* Copyright (C) 2019 sw4j.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sw4j.tool.barcode.random.encoder.impl;
import java.util.Locale;
import org.sw4j.tool.barcode.random.coder.Base58;
import org.sw4j.tool.barcode.random.encoder.ByteArrayEncoder;
/**
* <p>
* This class encodes a byte array as base58 string.
* </p>
* @author Uwe Plonus <u.plonus@gmail.com>
*/
public class Base58Encoder extends ByteArrayEncoder {
/**
* <p>
* The encoding name as constant.
* </p>
*/
public static final String TYPE = "base58";
/**
* <p>
* The default constructor.
* </p>
*/
public Base58Encoder() {
}
/**
* <p>
* Return {@code true} if the {@code encoding} is base58 (case insensitive).
* </p>
* @param encoding the encoding name to check.
* @return {@code true} if the name is base58.
*/
@Override
public boolean supports(final String encoding) {
return encoding != null && TYPE.equals(encoding.toLowerCase(Locale.ROOT));
}
/**
* <p>
* Return the byte array encoded as base58.
* </p>
* @param data the byte array to encode.
* @return the encoded data.
*/
@Override
public String encode(final byte[] data) {
return Base58.encode(data);
}
}