// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.jcajce.spec;

import org.bouncycastle.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.security.auth.Destroyable;
import java.security.spec.AlgorithmParameterSpec;

public class HybridValueParameterSpec implements AlgorithmParameterSpec, Destroyable
{
    private final AtomicBoolean hasBeenDestroyed;
    private final boolean doPrepend;
    private volatile byte[] t;
    private volatile AlgorithmParameterSpec baseSpec;
    
    public HybridValueParameterSpec(final byte[] array, final AlgorithmParameterSpec algorithmParameterSpec) {
        this(array, false, algorithmParameterSpec);
    }
    
    public HybridValueParameterSpec(final byte[] t, final boolean doPrepend, final AlgorithmParameterSpec baseSpec) {
        this.hasBeenDestroyed = new AtomicBoolean(false);
        this.t = t;
        this.baseSpec = baseSpec;
        this.doPrepend = doPrepend;
    }
    
    public boolean isPrependedT() {
        return this.doPrepend;
    }
    
    public byte[] getT() {
        final byte[] t = this.t;
        this.checkDestroyed();
        return t;
    }
    
    public AlgorithmParameterSpec getBaseParameterSpec() {
        final AlgorithmParameterSpec baseSpec = this.baseSpec;
        this.checkDestroyed();
        return baseSpec;
    }
    
    @Override
    public boolean isDestroyed() {
        return this.hasBeenDestroyed.get();
    }
    
    @Override
    public void destroy() {
        if (!this.hasBeenDestroyed.getAndSet(true)) {
            Arrays.clear(this.t);
            this.t = null;
            this.baseSpec = null;
        }
    }
    
    private void checkDestroyed() {
        if (this.isDestroyed()) {
            throw new IllegalStateException("spec has been destroyed");
        }
    }
}
