001package org.apache.commons.ssl.org.bouncycastle.asn1.cmp; 002 003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer; 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1OctetString; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 009import org.apache.commons.ssl.org.bouncycastle.asn1.DEROctetString; 010import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 011import org.apache.commons.ssl.org.bouncycastle.asn1.x509.AlgorithmIdentifier; 012 013public class PBMParameter 014 extends ASN1Object 015{ 016 private ASN1OctetString salt; 017 private AlgorithmIdentifier owf; 018 private ASN1Integer iterationCount; 019 private AlgorithmIdentifier mac; 020 021 private PBMParameter(ASN1Sequence seq) 022 { 023 salt = ASN1OctetString.getInstance(seq.getObjectAt(0)); 024 owf = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 025 iterationCount = ASN1Integer.getInstance(seq.getObjectAt(2)); 026 mac = AlgorithmIdentifier.getInstance(seq.getObjectAt(3)); 027 } 028 029 public static PBMParameter getInstance(Object o) 030 { 031 if (o instanceof PBMParameter) 032 { 033 return (PBMParameter)o; 034 } 035 036 if (o != null) 037 { 038 return new PBMParameter(ASN1Sequence.getInstance(o)); 039 } 040 041 return null; 042 } 043 044 public PBMParameter( 045 byte[] salt, 046 AlgorithmIdentifier owf, 047 int iterationCount, 048 AlgorithmIdentifier mac) 049 { 050 this(new DEROctetString(salt), owf, 051 new ASN1Integer(iterationCount), mac); 052 } 053 054 public PBMParameter( 055 ASN1OctetString salt, 056 AlgorithmIdentifier owf, 057 ASN1Integer iterationCount, 058 AlgorithmIdentifier mac) 059 { 060 this.salt = salt; 061 this.owf = owf; 062 this.iterationCount = iterationCount; 063 this.mac = mac; 064 } 065 066 public ASN1OctetString getSalt() 067 { 068 return salt; 069 } 070 071 public AlgorithmIdentifier getOwf() 072 { 073 return owf; 074 } 075 076 public ASN1Integer getIterationCount() 077 { 078 return iterationCount; 079 } 080 081 public AlgorithmIdentifier getMac() 082 { 083 return mac; 084 } 085 086 /** 087 * <pre> 088 * PBMParameter ::= SEQUENCE { 089 * salt OCTET STRING, 090 * -- note: implementations MAY wish to limit acceptable sizes 091 * -- of this string to values appropriate for their environment 092 * -- in order to reduce the risk of denial-of-service attacks 093 * owf AlgorithmIdentifier, 094 * -- AlgId for a One-Way Function (SHA-1 recommended) 095 * iterationCount INTEGER, 096 * -- number of times the OWF is applied 097 * -- note: implementations MAY wish to limit acceptable sizes 098 * -- of this integer to values appropriate for their environment 099 * -- in order to reduce the risk of denial-of-service attacks 100 * mac AlgorithmIdentifier 101 * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11], 102 * } -- or HMAC [RFC2104, RFC2202]) 103 * </pre> 104 * @return a basic ASN.1 object representation. 105 */ 106 public ASN1Primitive toASN1Primitive() 107 { 108 ASN1EncodableVector v = new ASN1EncodableVector(); 109 110 v.add(salt); 111 v.add(owf); 112 v.add(iterationCount); 113 v.add(mac); 114 115 return new DERSequence(v); 116 } 117}