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

package org.bouncycastle.jcajce.provider.digest;

import java.security.DigestException;
import org.bouncycastle.crypto.Digest;
import java.security.MessageDigest;

public class BCMessageDigest extends MessageDigest
{
    protected Digest digest;
    protected int digestSize;
    
    protected BCMessageDigest(final Digest digest) {
        super(digest.getAlgorithmName());
        this.digest = digest;
        this.digestSize = digest.getDigestSize();
    }
    
    public void engineReset() {
        this.digest.reset();
    }
    
    public void engineUpdate(final byte b) {
        this.digest.update(b);
    }
    
    public void engineUpdate(final byte[] array, final int n, final int n2) {
        this.digest.update(array, n, n2);
    }
    
    public int engineGetDigestLength() {
        return this.digestSize;
    }
    
    public byte[] engineDigest() {
        final byte[] array = new byte[this.digestSize];
        this.digest.doFinal(array, 0);
        return array;
    }
    
    public int engineDigest(final byte[] array, final int n, final int n2) throws DigestException {
        if (n2 < this.digestSize) {
            throw new DigestException("partial digests not returned");
        }
        if (array.length - n < this.digestSize) {
            throw new DigestException("insufficient space in the output buffer to store the digest");
        }
        this.digest.doFinal(array, n);
        return this.digestSize;
    }
}
