GordianCorePBESpecBuilder.java

/*
 * GordianKnot: Security Suite
 * Copyright 2026. Tony Washer
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.  You may obtain a copy
 * of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package io.github.tonywasher.joceanus.gordianknot.impl.core.spec.cipher;

import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBESpec.GordianPBEArgon2Spec;
import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBESpec.GordianPBEDigestAndCountSpec;
import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBESpec.GordianPBESCryptSpec;
import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBESpecBuilder;
import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBEType;
import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpecBuilder;
import io.github.tonywasher.joceanus.gordianknot.impl.core.spec.cipher.GordianCorePBESpec.GordianCorePBEArgon2Spec;
import io.github.tonywasher.joceanus.gordianknot.impl.core.spec.cipher.GordianCorePBESpec.GordianCorePBEDigestAndCountSpec;
import io.github.tonywasher.joceanus.gordianknot.impl.core.spec.cipher.GordianCorePBESpec.GordianCorePBESCryptSpec;
import io.github.tonywasher.joceanus.gordianknot.impl.core.spec.digest.GordianCoreDigestSpecBuilder;

/**
 * PBE Specification Builder.
 */
public final class GordianCorePBESpecBuilder
        implements GordianPBESpecBuilder {
    /**
     * The digestSpec builder.
     */
    private final GordianDigestSpecBuilder theBuilder;

    /**
     * Private constructor.
     */
    private GordianCorePBESpecBuilder() {
        theBuilder = GordianCoreDigestSpecBuilder.newInstance();
    }

    /**
     * Obtain new instance.
     *
     * @return the new instance
     */
    public static GordianCorePBESpecBuilder newInstance() {
        return new GordianCorePBESpecBuilder();
    }

    @Override
    public GordianDigestSpecBuilder usingDigestSpecBuilder() {
        return theBuilder;
    }

    @Override
    public GordianPBEDigestAndCountSpec pbKDF2(final GordianDigestSpec pDigestSpec,
                                               final int pCount) {
        return new GordianCorePBEDigestAndCountSpec(GordianPBEType.PBKDF2, pDigestSpec, pCount);
    }

    @Override
    public GordianPBEDigestAndCountSpec pkcs12(final GordianDigestSpec pDigestSpec,
                                               final int pCount) {
        return new GordianCorePBEDigestAndCountSpec(GordianPBEType.PKCS12, pDigestSpec, pCount);
    }

    @Override
    public GordianPBESCryptSpec scrypt(final int pCost,
                                       final int pBlockSize,
                                       final int pParallel) {
        return new GordianCorePBESCryptSpec(pCost, pBlockSize, pParallel);
    }

    @Override
    public GordianPBEArgon2Spec argon2(final int pLanes,
                                       final int pMemory,
                                       final int pIterations) {
        return new GordianCorePBEArgon2Spec(pLanes, pMemory, pIterations);
    }
}