KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > novosec > pkix > asn1 > crmf > PBMParameter


1 // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
2
//
3
// Author: Maik Stohn
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
// software and associated documentation files (the "Software"), to deal in the Software
7
// without restriction, including without limitation the rights to use, copy, modify, merge,
8
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
// to whom the Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in all copies or
12
// substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19

20 package com.novosec.pkix.asn1.crmf;
21
22 import org.bouncycastle.asn1.ASN1EncodableVector;
23 import org.bouncycastle.asn1.ASN1Sequence;
24 import org.bouncycastle.asn1.ASN1TaggedObject;
25 import org.bouncycastle.asn1.DEREncodable;
26 import org.bouncycastle.asn1.DERInteger;
27 import org.bouncycastle.asn1.DERObject;
28 import org.bouncycastle.asn1.DEROctetString;
29 import org.bouncycastle.asn1.DERSequence;
30 import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
31
32 /**
33  * ASN.1 structure DER En/DeCoder.
34  *
35  * <pre>
36  * PBMParameter ::= SEQUENCE {
37  * salt OCTET STRING,
38  * owf AlgorithmIdentifier, -- AlgId for a One-Way Function (SHA-1 recommended)
39  * iterationCount INTEGER, -- number of times the OWF is applied
40  * mac AlgorithmIdentifier -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],or HMAC [RFC2104, RFC2202])
41  * }
42  *
43  * </pre>
44  */

45 public class PBMParameter implements DEREncodable
46 {
47     DEROctetString salt;
48     AlgorithmIdentifier owf;
49     DERInteger iterationCount;
50     AlgorithmIdentifier mac;
51
52     public static PBMParameter getInstance( ASN1TaggedObject obj, boolean explicit )
53     {
54         return getInstance(ASN1Sequence.getInstance(obj, explicit));
55     }
56
57     public static PBMParameter getInstance( Object JavaDoc obj )
58     {
59         if (obj instanceof PBMParameter)
60         {
61             return (PBMParameter)obj;
62         }
63         else if (obj instanceof ASN1Sequence)
64         {
65             return new PBMParameter((ASN1Sequence)obj);
66         }
67
68         throw new IllegalArgumentException JavaDoc("unknown object in factory");
69     }
70     
71     public PBMParameter( ASN1Sequence seq )
72     {
73       this.salt = (DEROctetString)seq.getObjectAt(0);
74       this.owf = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
75       this.iterationCount = DERInteger.getInstance(seq.getObjectAt(2));
76       this.mac = AlgorithmIdentifier.getInstance(seq.getObjectAt(3));
77     }
78
79     public PBMParameter( DEROctetString salt, AlgorithmIdentifier owf, DERInteger iterationCount, AlgorithmIdentifier mac )
80     {
81       this.salt = salt;
82       this.owf = owf;
83       this.iterationCount = iterationCount;
84       this.mac = mac;
85     }
86
87     public DEROctetString getSalt()
88     {
89         return salt;
90     }
91
92     public AlgorithmIdentifier getOwf()
93     {
94         return owf;
95     }
96
97     public DERInteger getIterationCount()
98     {
99         return iterationCount;
100     }
101
102     public AlgorithmIdentifier getMac()
103     {
104         return mac;
105     }
106
107     public DERObject getDERObject()
108     {
109         ASN1EncodableVector v = new ASN1EncodableVector();
110
111         v.add( salt );
112         v.add( owf );
113         v.add( iterationCount );
114         v.add( mac );
115
116         return new DERSequence(v);
117     }
118
119     public String JavaDoc toString()
120     {
121       return "PBMParameter: (salt = " + this.getSalt() + ", " +
122                             "owf = " + this.getOwf() + ", " +
123                             "iterationCount = " + this.getIterationCount() + ", " +
124                             "mac = " + this.getMac() + ")";
125     }
126 }
127
Popular Tags