01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.math.BigInteger;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1OctetString;
08: import org.bouncycastle.asn1.ASN1Sequence;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11: import org.bouncycastle.asn1.DEROctetString;
12: import org.bouncycastle.asn1.DERSequence;
13: import org.bouncycastle.asn1.x509.DigestInfo;
14:
15: public class MacData extends ASN1Encodable {
16: DigestInfo digInfo;
17: byte[] salt;
18: BigInteger iterationCount;
19:
20: public static MacData getInstance(Object obj) {
21: if (obj instanceof MacData) {
22: return (MacData) obj;
23: } else if (obj instanceof ASN1Sequence) {
24: return new MacData((ASN1Sequence) obj);
25: }
26:
27: throw new IllegalArgumentException("unknown object in factory");
28: }
29:
30: public MacData(ASN1Sequence seq) {
31: this .digInfo = DigestInfo.getInstance(seq.getObjectAt(0));
32:
33: this .salt = ((ASN1OctetString) seq.getObjectAt(1)).getOctets();
34:
35: if (seq.size() == 3) {
36: this .iterationCount = ((DERInteger) seq.getObjectAt(2))
37: .getValue();
38: } else {
39: this .iterationCount = BigInteger.valueOf(1);
40: }
41: }
42:
43: public MacData(DigestInfo digInfo, byte[] salt, int iterationCount) {
44: this .digInfo = digInfo;
45: this .salt = salt;
46: this .iterationCount = BigInteger.valueOf(iterationCount);
47: }
48:
49: public DigestInfo getMac() {
50: return digInfo;
51: }
52:
53: public byte[] getSalt() {
54: return salt;
55: }
56:
57: public BigInteger getIterationCount() {
58: return iterationCount;
59: }
60:
61: public DERObject toASN1Object() {
62: ASN1EncodableVector v = new ASN1EncodableVector();
63:
64: v.add(digInfo);
65: v.add(new DEROctetString(salt));
66: v.add(new DERInteger(iterationCount));
67:
68: return new DERSequence(v);
69: }
70: }
|