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

package com.google.crypto.tink;

import com.google.crypto.tink.proto.EncryptedKeyset;
import com.google.protobuf.ExtensionRegistryLite;
import com.google.crypto.tink.proto.Keyset;
import com.google.errorprone.annotations.InlineMe;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.File;
import java.io.ByteArrayInputStream;
import java.io.InputStream;

public final class BinaryKeysetReader implements KeysetReader
{
    private final InputStream inputStream;
    
    public static KeysetReader withInputStream(final InputStream stream) {
        return new BinaryKeysetReader(stream);
    }
    
    public static KeysetReader withBytes(final byte[] bytes) {
        return new BinaryKeysetReader(new ByteArrayInputStream(bytes));
    }
    
    @Deprecated
    @InlineMe(replacement = "BinaryKeysetReader.withInputStream(new FileInputStream(file))", imports = { "com.google.crypto.tink.BinaryKeysetReader", "java.io.FileInputStream" })
    public static KeysetReader withFile(final File file) throws IOException {
        return withInputStream(new FileInputStream(file));
    }
    
    private BinaryKeysetReader(final InputStream stream) {
        this.inputStream = stream;
    }
    
    @Override
    public Keyset read() throws IOException {
        try {
            return Keyset.parseFrom(this.inputStream, ExtensionRegistryLite.getEmptyRegistry());
        }
        finally {
            this.inputStream.close();
        }
    }
    
    @Override
    public EncryptedKeyset readEncrypted() throws IOException {
        try {
            return EncryptedKeyset.parseFrom(this.inputStream, ExtensionRegistryLite.getEmptyRegistry());
        }
        finally {
            this.inputStream.close();
        }
    }
}
