001: package org.bouncycastle.asn1.isismtt.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.DERInteger;
007: import org.bouncycastle.asn1.DERObject;
008: import org.bouncycastle.asn1.DERPrintableString;
009: import org.bouncycastle.asn1.DERSequence;
010:
011: import java.math.BigInteger;
012: import java.util.Enumeration;
013:
014: /**
015: * Monetary limit for transactions. The QcEuMonetaryLimit QC statement MUST be
016: * used in new certificates in place of the extension/attribute MonetaryLimit
017: * since January 1, 2004. For the sake of backward compatibility with
018: * certificates already in use, components SHOULD support MonetaryLimit (as well
019: * as QcEuLimitValue).
020: * <p/>
021: * Indicates a monetary limit within which the certificate holder is authorized
022: * to act. (This value DOES NOT express a limit on the liability of the
023: * certification authority).
024: * <p/>
025: * <pre>
026: * MonetaryLimitSyntax ::= SEQUENCE
027: * {
028: * currency PrintableString (SIZE(3)),
029: * amount INTEGER,
030: * exponent INTEGER
031: * }
032: * </pre>
033: * <p/>
034: * currency must be the ISO code.
035: * <p/>
036: * value = amount�10*exponent
037: */
038: public class MonetaryLimit extends ASN1Encodable {
039: DERPrintableString currency;
040: DERInteger amount;
041: DERInteger exponent;
042:
043: public static MonetaryLimit getInstance(Object obj) {
044: if (obj == null || obj instanceof MonetaryLimit) {
045: return (MonetaryLimit) obj;
046: }
047:
048: if (obj instanceof ASN1Sequence) {
049: return new MonetaryLimit(ASN1Sequence.getInstance(obj));
050: }
051:
052: throw new IllegalArgumentException(
053: "unknown object in getInstance");
054: }
055:
056: private MonetaryLimit(ASN1Sequence seq) {
057: if (seq.size() != 3) {
058: throw new IllegalArgumentException("Bad sequence size: "
059: + seq.size());
060: }
061: Enumeration e = seq.getObjects();
062: currency = DERPrintableString.getInstance(e.nextElement());
063: amount = DERInteger.getInstance(e.nextElement());
064: exponent = DERInteger.getInstance(e.nextElement());
065: }
066:
067: /**
068: * Constructor from a given details.
069: * <p/>
070: * <p/>
071: * value = amount�10^exponent
072: *
073: * @param currency The currency. Must be the ISO code.
074: * @param amount The amount
075: * @param exponent The exponent
076: */
077: public MonetaryLimit(String currency, int amount, int exponent) {
078: this .currency = new DERPrintableString(currency, true);
079: this .amount = new DERInteger(amount);
080: this .exponent = new DERInteger(exponent);
081: }
082:
083: public String getCurrency() {
084: return currency.getString();
085: }
086:
087: public BigInteger getAmount() {
088: return amount.getValue();
089: }
090:
091: public BigInteger getExponent() {
092: return exponent.getValue();
093: }
094:
095: /**
096: * Produce an object suitable for an ASN1OutputStream.
097: * <p/>
098: * Returns:
099: * <p/>
100: * <pre>
101: * MonetaryLimitSyntax ::= SEQUENCE
102: * {
103: * currency PrintableString (SIZE(3)),
104: * amount INTEGER,
105: * exponent INTEGER
106: * }
107: * </pre>
108: *
109: * @return a DERObject
110: */
111: public DERObject toASN1Object() {
112: ASN1EncodableVector seq = new ASN1EncodableVector();
113: seq.add(currency);
114: seq.add(amount);
115: seq.add(exponent);
116:
117: return new DERSequence(seq);
118: }
119:
120: }
|