Class GenericValueConverter

  • All Implemented Interfaces:
    AVAValueConverter

    public class GenericValueConverter
    extends java.lang.Object
    implements AVAValueConverter
    A GenericValueConverter converts a string that is not associated with a particular attribute to a DER encoded ASN.1 character string type. Currently supports PrintableString, IA5String, BMPString T.61String and Universal String.

    The conversion is done as follows. An encoder is obtained for the all the character sets from the global default ASN1CharStrConvMap. The encoders are then used to convert the string to the smallest character set first -- printableString. If the string contains characters outside of that character set, it is converted to the next character set -- IA5String character set. If that is not enough it is converted to a BMPString, then Universal String which contains all characters.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAsString​(DerValue avaValue)
      Converts a DerValue of ASN1 Character string type to a java string (the string is not encoded in any form).
      DerValue getValue​(byte[] berByteStream)
      Creates a DerValue from the byte array of BER encoded value.
      DerValue getValue​(java.lang.String s)
      Converts a string to a DER encoded ASN.1 primtable string, defined here as a PrintableString, IA5String, T.61String, BMPString or UniversalString.
      DerValue getValue​(java.lang.String valueString, byte[] tags)
      Converts a string to a DER encoded attribute value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GenericValueConverter

        public GenericValueConverter()
    • Method Detail

      • getValue

        public DerValue getValue​(java.lang.String s)
                          throws java.io.IOException
        Converts a string to a DER encoded ASN.1 primtable string, defined here as a PrintableString, IA5String, T.61String, BMPString or UniversalString. The string is not expected to be encoded in any form.

        If an encoder is not available for a character set that is needed to convert the string, the string cannot be converted and an IOException is thrown. For example, if the string contains characters outside the PrintableString character and only a PrintableString encoder is available then an IOException is thrown.

        Specified by:
        getValue in interface AVAValueConverter
        Parameters:
        s - A string representing a generic attribute string value.
        Returns:
        The DER value of the attribute.
        Throws:
        java.io.IOException - if the string cannot be converted, such as when an encoder needed is unavailable.
      • getValue

        public DerValue getValue​(java.lang.String valueString,
                                 byte[] tags)
                          throws java.io.IOException
        Description copied from interface: AVAValueConverter
        Converts a string to a DER encoded attribute value. Specify the order of DER tags to use if more than one encoding is possible. Currently Directory Strings can have different order for backwards compatibility. By 2003 all should be UTF8String.
        Specified by:
        getValue in interface AVAValueConverter
        Parameters:
        valueString - An AVA value string not encoded in any form.
        Returns:
        A DerValue object.
        Throws:
        java.io.IOException - if an error occurs during the conversion.
      • getValue

        public DerValue getValue​(byte[] berByteStream)
                          throws java.io.IOException
        Creates a DerValue from the byte array of BER encoded value. NOTE: currently only supports DER encoding (a form of BER) on input .
        Specified by:
        getValue in interface AVAValueConverter
        Parameters:
        berByteStream - Byte array of a BER encoded value.
        Returns:
        DerValue object.
        Throws:
        java.io.IOException - If the BER value cannot be converted to a valid Directory String DER value.
      • getAsString

        public java.lang.String getAsString​(DerValue avaValue)
                                     throws java.io.IOException
        Converts a DerValue of ASN1 Character string type to a java string (the string is not encoded in any form).
        Specified by:
        getAsString in interface AVAValueConverter
        Parameters:
        avaValue - A DerValue
        Returns:
        A string representing the attribute value.
        Throws:
        java.io.IOException - if a decoder needed for the conversion is not available or if BER value is not one of the ASN1 character string types here.