// Path: src/main/java/io/github/novacrypto/base58/CapacityCalculator.java
// static int maximumBase58StringLength(final int byteLength) {
//     return (int) Math.ceil(byteLength * storageRatio);
// }


import static io.github.novacrypto.base58.CapacityCalculator.maximumBase58StringLength;
import java.util.Arrays;
/*
 *  Base58 library, a Java implementation of Base58 encode/decode
 *  Copyright (C) 2017-2019 Alan Evans, NovaCrypto
 *
 *  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 <https://www.gnu.org/licenses/>.
 *
 *  Original source: https://github.com/NovaCrypto/Base58
 *  You can contact the authors via github issues.
 */

package io.github.novacrypto.base58;



final class Base58EncoderDecoder implements GeneralEncoderDecoder {

    private static final char[] DIGITS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();
    private static final int[] VALUES = initValues(DIGITS);

    private final WorkingBuffer workingBuffer;
    private final StringBuilderEncodeTarget target = new StringBuilderEncodeTarget();

    Base58EncoderDecoder(final WorkingBuffer workingBuffer) {
        this.workingBuffer = workingBuffer;
    }

    @Override
    public String encode(final byte[] bytes) {
        target.clear();
        encode(bytes, target, target);
        return target.toString();
    }

    @Override
    public void encode(final byte[] bytes, final EncodeTargetFromCapacity target) {
// Path: src/main/java/io/github/novacrypto/base58/CapacityCalculator.java
// static int maximumBase58StringLength(final int byteLength) {
//     return (int) Math.ceil(byteLength * storageRatio);
// }


// Path: src/main/java/io/github/novacrypto/base58/Base58EncoderDecoder.java
import static io.github.novacrypto.base58.CapacityCalculator.maximumBase58StringLength;
import java.util.Arrays;

/*
 *  Base58 library, a Java implementation of Base58 encode/decode
 *  Copyright (C) 2017-2019 Alan Evans, NovaCrypto
 *
 *  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 <https://www.gnu.org/licenses/>.
 *
 *  Original source: https://github.com/NovaCrypto/Base58
 *  You can contact the authors via github issues.
 */

package io.github.novacrypto.base58;



final class Base58EncoderDecoder implements GeneralEncoderDecoder {

    private static final char[] DIGITS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();
    private static final int[] VALUES = initValues(DIGITS);

    private final WorkingBuffer workingBuffer;
    private final StringBuilderEncodeTarget target = new StringBuilderEncodeTarget();

    Base58EncoderDecoder(final WorkingBuffer workingBuffer) {
        this.workingBuffer = workingBuffer;
    }

    @Override
    public String encode(final byte[] bytes) {
        target.clear();
        encode(bytes, target, target);
        return target.toString();
    }

    @Override
    public void encode(final byte[] bytes, final EncodeTargetFromCapacity target) {
        final int characters = maximumBase58StringLength(bytes.length);