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

package org.bouncycastle.cms;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.asn1.cms.RecipientIdentifier;
import org.bouncycastle.asn1.cms.IssuerAndSerialNumber;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.cms.KEMRecipientInfo;

public class KEMRecipientInformation extends RecipientInformation
{
    private KEMRecipientInfo info;
    
    KEMRecipientInformation(final KEMRecipientInfo info, final AlgorithmIdentifier algorithmIdentifier, final CMSSecureReadable cmsSecureReadable) {
        super(info.getKem(), algorithmIdentifier, cmsSecureReadable);
        this.info = info;
        final RecipientIdentifier recipientIdentifier = info.getRecipientIdentifier();
        if (recipientIdentifier.isTagged()) {
            this.rid = new KEMRecipientId(ASN1OctetString.getInstance(recipientIdentifier.getId()).getOctets());
        }
        else {
            final IssuerAndSerialNumber instance = IssuerAndSerialNumber.getInstance(recipientIdentifier.getId());
            this.rid = new KEMRecipientId(instance.getName(), instance.getSerialNumber().getValue());
        }
    }
    
    public AlgorithmIdentifier getKdfAlgorithm() {
        return this.info.getKdf();
    }
    
    public byte[] getUkm() {
        return Arrays.clone(this.info.getUkm());
    }
    
    public byte[] getEncapsulation() {
        return Arrays.clone(this.info.getKemct().getOctets());
    }
    
    @Override
    protected RecipientOperator getRecipientOperator(final Recipient recipient) throws CMSException {
        return ((KEMRecipient)recipient).getRecipientOperator(new AlgorithmIdentifier(this.keyEncAlg.getAlgorithm(), this.info), this.messageAlgorithm, this.info.getEncryptedKey().getOctets());
    }
}
