Class GenericValueConverter

java.lang.Object
org.mozilla.jss.netscape.security.x509.GenericValueConverter
All Implemented Interfaces:
AVAValueConverter

public class GenericValueConverter extends 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.

  • Field Details

    • DefEncodingTags

      private static byte[] DefEncodingTags
  • Constructor Details

    • GenericValueConverter

      public GenericValueConverter()
  • Method Details

    • getValue

      public DerValue getValue(String s) throws 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:
      IOException - if the string cannot be converted, such as when an encoder needed is unavailable.
    • getValue

      public DerValue getValue(String valueString, byte[] tags) throws 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:
      IOException - if an error occurs during the conversion.
    • getValue

      public DerValue getValue(byte[] berByteStream) throws 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:
      IOException - If the BER value cannot be converted to a valid Directory String DER value.
    • getAsString

      public String getAsString(DerValue avaValue) throws 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:
      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.