01: package org.bouncycastle.asn1.x509.qualified;
02:
03: import java.math.BigInteger;
04: import java.util.Enumeration;
05:
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.ASN1EncodableVector;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11: import org.bouncycastle.asn1.DERSequence;
12:
13: /**
14: * The MonetaryValue object.
15: * <pre>
16: * MonetaryValue ::= SEQUENCE {
17: * currency Iso4217CurrencyCode,
18: * amount INTEGER,
19: * exponent INTEGER }
20: * -- value = amount * 10^exponent
21: * </pre>
22: */
23: public class MonetaryValue extends ASN1Encodable {
24: Iso4217CurrencyCode currency;
25: DERInteger amount;
26: DERInteger exponent;
27:
28: public static MonetaryValue getInstance(Object obj) {
29: if (obj == null || obj instanceof MonetaryValue) {
30: return (MonetaryValue) obj;
31: }
32:
33: if (obj instanceof ASN1Sequence) {
34: return new MonetaryValue(ASN1Sequence.getInstance(obj));
35: }
36:
37: throw new IllegalArgumentException(
38: "unknown object in getInstance");
39: }
40:
41: public MonetaryValue(ASN1Sequence seq) {
42: Enumeration e = seq.getObjects();
43: // currency
44: currency = Iso4217CurrencyCode.getInstance(e.nextElement());
45: // hashAlgorithm
46: amount = DERInteger.getInstance(e.nextElement());
47: // exponent
48: exponent = DERInteger.getInstance(e.nextElement());
49: }
50:
51: public MonetaryValue(Iso4217CurrencyCode currency, int amount,
52: int exponent) {
53: this .currency = currency;
54: this .amount = new DERInteger(amount);
55: this .exponent = new DERInteger(exponent);
56: }
57:
58: public Iso4217CurrencyCode getCurrency() {
59: return currency;
60: }
61:
62: public BigInteger getAmount() {
63: return amount.getValue();
64: }
65:
66: public BigInteger getExponent() {
67: return exponent.getValue();
68: }
69:
70: public DERObject toASN1Object() {
71: ASN1EncodableVector seq = new ASN1EncodableVector();
72: seq.add(currency);
73: seq.add(amount);
74: seq.add(exponent);
75:
76: return new DERSequence(seq);
77: }
78: }
|