001package org.apache.commons.ssl.org.bouncycastle.asn1.eac;
002
003import java.io.UnsupportedEncodingException;
004
005public class CertificateHolderReference
006{
007    private static final String ReferenceEncoding = "ISO-8859-1";
008
009    private String countryCode;
010    private String holderMnemonic;
011    private String sequenceNumber;
012
013    public CertificateHolderReference(String countryCode, String holderMnemonic, String sequenceNumber)
014    {
015        this.countryCode = countryCode;
016        this.holderMnemonic = holderMnemonic;
017        this.sequenceNumber = sequenceNumber;
018    }
019
020    CertificateHolderReference(byte[] contents)
021    {
022        try
023        {
024            String concat = new String(contents, ReferenceEncoding);
025
026            this.countryCode = concat.substring(0, 2);
027            this.holderMnemonic = concat.substring(2, concat.length() - 5);
028
029            this.sequenceNumber = concat.substring(concat.length() - 5);
030        }
031        catch (UnsupportedEncodingException e)
032        {
033            throw new IllegalStateException(e.toString());
034        }
035    }
036
037    public String getCountryCode()
038    {
039        return countryCode;
040    }
041
042    public String getHolderMnemonic()
043    {
044        return holderMnemonic;
045    }
046
047    public String getSequenceNumber()
048    {
049        return sequenceNumber;
050    }
051
052
053    public byte[] getEncoded()
054    {
055        String ref = countryCode + holderMnemonic + sequenceNumber;
056
057        try
058        {
059            return ref.getBytes(ReferenceEncoding);
060        }
061        catch (UnsupportedEncodingException e)
062        {
063            throw new IllegalStateException(e.toString());
064        }
065    }
066}