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

package com.google.crypto.tink;

import java.util.Iterator;
import com.google.crypto.tink.proto.KeyData;
import java.io.IOException;
import com.google.protobuf.InvalidProtocolBufferException;
import java.security.GeneralSecurityException;
import com.google.crypto.tink.proto.Keyset;
import com.google.protobuf.ExtensionRegistryLite;

@Deprecated
public final class NoSecretKeysetHandle
{
    @Deprecated
    public static final KeysetHandle parseFrom(final byte[] serialized) throws GeneralSecurityException {
        try {
            final Keyset keyset = Keyset.parseFrom(serialized, ExtensionRegistryLite.getEmptyRegistry());
            validate(keyset);
            return KeysetHandle.fromKeyset(keyset);
        }
        catch (final InvalidProtocolBufferException e) {
            throw new GeneralSecurityException("invalid keyset");
        }
    }
    
    public static final KeysetHandle read(final KeysetReader reader) throws GeneralSecurityException, IOException {
        final Keyset keyset = reader.read();
        validate(keyset);
        return KeysetHandle.fromKeyset(keyset);
    }
    
    private static void validate(final Keyset keyset) throws GeneralSecurityException {
        for (final Keyset.Key key : keyset.getKeyList()) {
            if (key.getKeyData().getKeyMaterialType() == KeyData.KeyMaterialType.UNKNOWN_KEYMATERIAL || key.getKeyData().getKeyMaterialType() == KeyData.KeyMaterialType.SYMMETRIC || key.getKeyData().getKeyMaterialType() == KeyData.KeyMaterialType.ASYMMETRIC_PRIVATE) {
                throw new GeneralSecurityException("keyset contains secret key material");
            }
        }
    }
    
    private NoSecretKeysetHandle() {
    }
}
