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

package com.google.crypto.tink.util;

import java.security.MessageDigest;
import com.google.crypto.tink.subtle.Random;
import com.google.crypto.tink.SecretKeyAccess;
import com.google.errorprone.annotations.Immutable;

@Immutable
public final class SecretBytes
{
    private final Bytes bytes;
    
    private SecretBytes(final Bytes bytes) {
        this.bytes = bytes;
    }
    
    public static SecretBytes copyFrom(final byte[] value, final SecretKeyAccess access) {
        if (access == null) {
            throw new NullPointerException("SecretKeyAccess required");
        }
        return new SecretBytes(Bytes.copyFrom(value));
    }
    
    public static SecretBytes randomBytes(final int length) {
        return new SecretBytes(Bytes.copyFrom(Random.randBytes(length)));
    }
    
    public byte[] toByteArray(final SecretKeyAccess access) {
        if (access == null) {
            throw new NullPointerException("SecretKeyAccess required");
        }
        return this.bytes.toByteArray();
    }
    
    public int size() {
        return this.bytes.size();
    }
    
    public boolean equalsSecretBytes(final SecretBytes other) {
        final byte[] myArray = this.bytes.toByteArray();
        final byte[] otherArray = other.bytes.toByteArray();
        return MessageDigest.isEqual(myArray, otherArray);
    }
}
