package org.bouncycastle.asn1.pkcs;

import java.math.BigInteger;
import java.util.Enumeration;

import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;

public class PBKDF2Params
    extends ASN1Object
{
    ASN1OctetString     octStr;
    DERInteger          iterationCount;
    DERInteger          keyLength;

    public static PBKDF2Params getInstance(
        Object  obj)
    {
        if (obj instanceof PBKDF2Params)
        {
            return (PBKDF2Params)obj;
        }

        if (obj instanceof ASN1Sequence)
        {
            return new PBKDF2Params((ASN1Sequence)obj);
        }

        throw new IllegalArgumentException("unknown object in factory: " + obj.getClass().getName());
    }
    
    public PBKDF2Params(
        byte[]  salt,
        int     iterationCount)
    {
        this.octStr = new DEROctetString(salt);
        this.iterationCount = new DERInteger(iterationCount);
    }
    
    public PBKDF2Params(
        ASN1Sequence  seq)
    {
        Enumeration e = seq.getObjects();

        octStr = (ASN1OctetString)e.nextElement();
        iterationCount = (DERInteger)e.nextElement();

        if (e.hasMoreElements())
        {
            keyLength = (DERInteger)e.nextElement();
        }
        else
        {
            keyLength = null;
        }
    }

    public byte[] getSalt()
    {
        return octStr.getOctets();
    }

    public BigInteger getIterationCount()
    {
        return iterationCount.getValue();
    }

    public BigInteger getKeyLength()
    {
        if (keyLength != null)
        {
            return keyLength.getValue();
        }

        return null;
    }

    public ASN1Primitive toASN1Primitive()
    {
        ASN1EncodableVector  v = new ASN1EncodableVector();

        v.add(octStr);
        v.add(iterationCount);

        if (keyLength != null)
        {
            v.add(keyLength);
        }

        return new DERSequence(v);
    }
}

@@ -494,24 +494,32 @@
 bject%0A%7B%0A    
+private 
 ASN1OctetStr
@@ -522,20 +522,16 @@
 tString 
-    
 octStr;%0A
@@ -530,24 +530,32 @@
 octStr;%0A    
+private 
 DERInteger  
@@ -554,28 +554,24 @@
 nteger      
-    
 iterationCou
@@ -578,16 +578,24 @@
 nt;%0A    
+private 
 DERInteg
@@ -598,28 +598,24 @@
 nteger      
-    
 keyLength;%0A%0A
@@ -1209,36 +1209,237 @@
 onCount);%0A    %7D%0A
+%0A
     
+public PBKDF2Params(%0A        byte%5B%5D  salt,%0A        int     iterationCount,%0A        int     keyLength)%0A    %7B%0A    %09this(salt, iterationCount);%0A%0A        this.keyLength = new DERInteger(keyLength);%0A    %7D%0A
 %0A    public PBKD

Add missing constructor option