Java Code Examples for org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode

The following are top voted examples for showing how to use org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: irma_future_id   File: MonetaryValueUnitTest.java   View source code 6 votes vote down vote up
private void checkValues(
    MonetaryValue mv,
    int           amount,
    int           exponent)
{
    if (mv.getAmount().intValue() != amount)
    {
        fail("amounts don't match.");
    }
    
    if (mv.getExponent().intValue() != exponent)
    {
        fail("exponents don't match.");
    }
    
    Iso4217CurrencyCode cc = mv.getCurrency();
    
    if (!cc.getAlphabetic().equals(CURRENCY_CODE))
    {
        fail("currency code wrong");
    }
}
 
Example 2
Project: bc-java   File: MonetaryValueUnitTest.java   View source code 6 votes vote down vote up
private void checkValues(
    MonetaryValue mv,
    int           amount,
    int           exponent)
{
    if (mv.getAmount().intValue() != amount)
    {
        fail("amounts don't match.");
    }
    
    if (mv.getExponent().intValue() != exponent)
    {
        fail("exponents don't match.");
    }
    
    Iso4217CurrencyCode cc = mv.getCurrency();
    
    if (!cc.getAlphabetic().equals(CURRENCY_CODE))
    {
        fail("currency code wrong");
    }
}
 
Example 3
Project: xipki   File: MonetaryValueOption.java   View source code 5 votes vote down vote up
public MonetaryValueOption(Iso4217CurrencyCode currency, Range2Type amountRange,
        Range2Type exponentRange) {
    this.currency = ParamUtil.requireNonNull("currency", currency);
    this.amountRange = ParamUtil.requireNonNull("amountRange", amountRange);
    this.exponentRange = ParamUtil.requireNonNull("exponentRange", exponentRange);

    this.currencyString = currency.isAlphabetic() ? currency.getAlphabetic().toUpperCase()
            : Integer.toString(currency.getNumeric());
}
 
Example 4
Project: irma_future_id   File: MonetaryValueUnitTest.java   View source code 5 votes vote down vote up
public void performTest() 
    throws Exception
{
    MonetaryValue mv = new MonetaryValue(new Iso4217CurrencyCode(CURRENCY_CODE), TEST_AMOUNT, ZERO_EXPONENT);

    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    mv = MonetaryValue.getInstance(mv);
    
    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Object().getEncoded());

    ASN1Sequence seq = (ASN1Sequence)aIn.readObject();
    
    mv = MonetaryValue.getInstance(seq);
    
    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    mv = MonetaryValue.getInstance(null);
    
    if (mv != null)
    {
        fail("null getInstance() failed.");
    }
    
    try
    {
        MonetaryValue.getInstance(new Object());
        
        fail("getInstance() failed to detect bad object.");
    }
    catch (IllegalArgumentException e)
    {
        // expected
    }
}
 
Example 5
Project: irma_future_id   File: Iso4217CurrencyCodeUnitTest.java   View source code 5 votes vote down vote up
private void checkNumeric(
    Iso4217CurrencyCode cc,
    String              code)
{
    if (!cc.isAlphabetic())
    {
        fail("non-alphabetic code found when one expected.");
    }
    
    if (!cc.getAlphabetic().equals(code))
    {
        fail("string codes don't match.");
    }
}
 
Example 6
Project: irma_future_id   File: Iso4217CurrencyCodeUnitTest.java   View source code 5 votes vote down vote up
private void checkNumeric(
    Iso4217CurrencyCode cc,
    int                 code)
{
    if (cc.isAlphabetic())
    {
        fail("alphabetic code found when one not expected.");
    }
    
    if (cc.getNumeric() != code)
    {
        fail("numeric codes don't match.");
    }
}
 
Example 7
Project: bc-java   File: MonetaryValueUnitTest.java   View source code 5 votes vote down vote up
public void performTest() 
    throws Exception
{
    MonetaryValue mv = new MonetaryValue(new Iso4217CurrencyCode(CURRENCY_CODE), TEST_AMOUNT, ZERO_EXPONENT);

    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    mv = MonetaryValue.getInstance(mv);
    
    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Object().getEncoded());

    ASN1Sequence seq = (ASN1Sequence)aIn.readObject();
    
    mv = MonetaryValue.getInstance(seq);
    
    checkValues(mv, TEST_AMOUNT, ZERO_EXPONENT);
    
    mv = MonetaryValue.getInstance(null);
    
    if (mv != null)
    {
        fail("null getInstance() failed.");
    }
    
    try
    {
        MonetaryValue.getInstance(new Object());
        
        fail("getInstance() failed to detect bad object.");
    }
    catch (IllegalArgumentException e)
    {
        // expected
    }
}
 
Example 8
Project: bc-java   File: Iso4217CurrencyCodeUnitTest.java   View source code 5 votes vote down vote up
private void checkNumeric(
    Iso4217CurrencyCode cc,
    String              code)
{
    if (!cc.isAlphabetic())
    {
        fail("non-alphabetic code found when one expected.");
    }
    
    if (!cc.getAlphabetic().equals(code))
    {
        fail("string codes don't match.");
    }
}
 
Example 9
Project: bc-java   File: Iso4217CurrencyCodeUnitTest.java   View source code 5 votes vote down vote up
private void checkNumeric(
    Iso4217CurrencyCode cc,
    int                 code)
{
    if (cc.isAlphabetic())
    {
        fail("alphabetic code found when one not expected.");
    }
    
    if (cc.getNumeric() != code)
    {
        fail("numeric codes don't match.");
    }
}
 
Example 10
Project: keystore-explorer   File: X509Ext.java   View source code 4 votes vote down vote up
private String getMonetaryValueStringValue(ASN1Encodable asn1Encodable, int baseIndentLevel) {

		// @formatter:off

		/*
		    MonetaryValue ::= SEQUENCE
		    {
		        currency Iso4217CurrencyCode,
		        amount INTEGER,
		        exponent INTEGER
		    }
		    Iso4217CurrencyCode ::= CHOICE
		    {
		        alphabetic PrintableString,
		        numeric INTEGER(1..999)
		    }
		 */

		// @formatter:on

		StringBuilder sb = new StringBuilder();

		MonetaryValue monetaryValue = MonetaryValue.getInstance(asn1Encodable);
		BigInteger amount = monetaryValue.getAmount();
		Iso4217CurrencyCode currency = monetaryValue.getCurrency();
		BigInteger exponent = monetaryValue.getExponent();

		if (currency != null) {
			String currencyString = currency.isAlphabetic() ? currency.getAlphabetic() : "" + currency.getNumeric();
			sb.append(INDENT.toString(baseIndentLevel));
			sb.append(MessageFormat.format(res.getString("QCEuLimitValue.Currency"), currencyString));
			sb.append(NEWLINE);
		}

		if (amount != null) {
			sb.append(INDENT.toString(baseIndentLevel));
			sb.append(MessageFormat.format(res.getString("QCEuLimitValue.Amount"), amount.toString()));
			sb.append(NEWLINE);
		}

		if (exponent != null) {
			sb.append(INDENT.toString(baseIndentLevel));
			sb.append(MessageFormat.format(res.getString("QCEuLimitValue.Exponent"), exponent.toString()));
			sb.append(NEWLINE);
		}

		return sb.toString();
	}
 
Example 11
Project: xipki   File: MonetaryValueOption.java   View source code 4 votes vote down vote up
public Iso4217CurrencyCode currency() {
    return currency;
}