01: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
02: //
03: // Author: Maik Stohn
04: //
05: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
06: // software and associated documentation files (the "Software"), to deal in the Software
07: // without restriction, including without limitation the rights to use, copy, modify, merge,
08: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
09: // 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.cmp;
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.DERObject;
27: import org.bouncycastle.asn1.DERSequence;
28: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
29:
30: /**
31: * ASN.1 structure DER En/DeCoder.
32: *
33: * <pre>
34: * DHBMParameter ::= SEQUENCE {
35: * owf AlgorithmIdentifier, -- AlgId for a One-Way Function (SHA-1 recommended)
36: * mac AlgorithmIdentifier -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11], or HMAC [RFC2104, RFC2202])
37: * }
38: *
39: * </pre>
40: */
41: public class DHBMParameter implements DEREncodable {
42: AlgorithmIdentifier owf;
43: AlgorithmIdentifier mac;
44:
45: public static DHBMParameter getInstance(ASN1TaggedObject obj,
46: boolean explicit) {
47: return getInstance(ASN1Sequence.getInstance(obj, explicit));
48: }
49:
50: public static DHBMParameter getInstance(Object obj) {
51: if (obj instanceof DHBMParameter) {
52: return (DHBMParameter) obj;
53: } else if (obj instanceof ASN1Sequence) {
54: return new DHBMParameter((ASN1Sequence) obj);
55: }
56:
57: throw new IllegalArgumentException("unknown object in factory");
58: }
59:
60: public DHBMParameter(ASN1Sequence seq) {
61: this .owf = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
62: this .mac = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
63: }
64:
65: public DHBMParameter(AlgorithmIdentifier owf,
66: AlgorithmIdentifier mac) {
67: this .owf = owf;
68: this .mac = mac;
69: }
70:
71: public AlgorithmIdentifier getOwf() {
72: return owf;
73: }
74:
75: public AlgorithmIdentifier getMac() {
76: return mac;
77: }
78:
79: public DERObject getDERObject() {
80: ASN1EncodableVector v = new ASN1EncodableVector();
81:
82: v.add(owf);
83: v.add(mac);
84:
85: return new DERSequence(v);
86: }
87:
88: public String toString() {
89: return "DHBMParameter: (owf = " + this .getOwf() + ", mac = "
90: + this .getMac() + ")";
91: }
92: }
|