public class PrintableString extends ASN1String
An ASN.1 PrintableString object may represent any arbitrary string of printable characters (A,B,...,Z; a,b,...,z; 0,1,...,9; space ' () + , - . / : = ?)
When creating a new PrintableString
object the value to be
represented has to be supplied as Java String
type:
String s = ...; PrintableString printableString = new PrintableString(s);Attention: When supplying the string value to be represented, no check is performed if it actually is composed only of characters belonging to PrintableString character set! An application itself has to take care for supplying a proper PrintableString value.
When calling the getValue
method for getting the inherent
string value from an ASN.1 PrintableString instance, a Java object of type
String
is returned:
String s = (String) printableString.getValue();DER en/decoding generally is done by means of the several methods of the
DerCoder
class; decoding alternatively may be
performed by using the DerInputStream
utility.value
asnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode
Modifier | Constructor and Description |
---|---|
protected |
PrintableString()
Creates an empty PrintableString object.
|
|
PrintableString(java.lang.String value)
Creates a new ASN.1 PrintableString object for the given String value.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkCaseInsensitive(boolean insensitive)
Decide whether to compare PrintableStrings case in sensitive or not
(default: no).
|
boolean |
equals(java.lang.Object obj)
Compares two PrintableStrings.
|
java.lang.Object |
getValue()
Returns the value of this PrintableString as a String object.
|
int |
hashCode()
Returns a hash code for this object.
|
static boolean |
isPrintableString(java.lang.String s)
Checks is the supplied String is a PrintableString.
|
void |
setValue(java.lang.Object object)
Sets the value of this PrintableString.
|
clone, decode, encode, getByteValue, setIgnoreConstructedEncodingForSimpleTypes, setIndefiniteLength, toString
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType
protected PrintableString()
public PrintableString(java.lang.String value)
Attention: No check is performed if the supplied String value actually is composed only of characters belonging to the PrintableString character set! An application itself has to take care for supplying a proper PrintableString value.
value
- the String value this PrintableString object should be initialized
withpublic java.lang.Object getValue()
getValue
in class ASN1Object
public void setValue(java.lang.Object object)
The supplied value has to be a Java object of type String
.
Attention: No check is performed if the supplied String value actually is
composed only of characters belonging to PrintableString character set! An
application itself has to take care for supplying a proper PrintableString
value.
setValue
in class ASN1Object
object
- the Java String value to be set for this PrintableStringpublic int hashCode()
hashCode
in class ASN1String
public boolean equals(java.lang.Object obj)
X.509 applies the following rules for comparing PrintableStrings; item (c) and (d):
(a) attribute values encoded in different types (e.g., PrintableString and BMPString) MAY be assumed to represent different strings; (b) attribute values in types other than PrintableString are case sensitive (this permits matching of attribute values as binary objects); (c) attribute values in PrintableString are not case sensitive (e.g., "Marianne Swanson" is the same as "MARIANNE SWANSON"); and (d) attribute values in PrintableString are compared after removing leading and trailing white space and converting internal substrings of one or more consecutive white space characters to a single space.For providing backwards compatibility to former IAIK PrintableString versions, for performance reasons and because PrintableStrings may not differ only case/space based in typical applications the case insensitive and space ignoring checking is turned off by default. Case insensitive and space ignoring checking may be turned on by calling static method
checkCaseInsensitive
. When case
insensitive and space ignoring checking is turned on the PrintableString
byte value representation immediately to avoid String object creation and
comparison and returns true
if the two PrintableStrings are
exactly identical or differ only in spaces or lower-upper case
representation of printable characters 'A'...'Z', 'a'...'z'. So this method
anytime will give the correct result of the two PrintableStrings to be
compared are actually PrintableStrings (having characters belonging to the
PrintableString character set only). This method may fail (give an
uncorrect comparison result) if any of the two PrintableStrings to be
compared have some non-printable character represented by more than one
byte and any of these bytes "case-in-sensitive" matches to the byte at the
same-position byte of the other PrintableString. However, it might be
unlikely that having two PrintableStrings with wrong characters that only
compare successfully because of the one assumption above.equals
in class ASN1String
obj
- the other PrintableStringtrue
if the two PrintableStrings are exactly identical
or differ only in spaces or lower-upper case representation of
printable characters 'A'...'Z', 'a'...'z', otherwise falsepublic static boolean isPrintableString(java.lang.String s)
This method checks if the supplied String only contains printable characters (A,B,...,Z; a,b,...,z; 0,1,...,9; space ' () + , - . / : = ?).
s
- the string to be checkedtrue
if the string is a printable string,
false
if notpublic static void checkCaseInsensitive(boolean insensitive)
X.509 applies the following rules for comparing PrintableStrings; item (c) and (d):
(a) attribute values encoded in different types (e.g., PrintableString and BMPString) MAY be assumed to represent different strings; (b) attribute values in types other than PrintableString are case sensitive (this permits matching of attribute values as binary objects); (c) attribute values in PrintableString are not case sensitive (e.g., "Marianne Swanson" is the same as "MARIANNE SWANSON"); and (d) attribute values in PrintableString are compared after removing leading and trailing white space and converting internal substrings of one or more consecutive white space characters to a single space.For providing backwards compatibility to former IAIK PrintableString versions, for performance reasons and because PrintableStrings may not differ only case/space based in typical applications the case insensitive and space ignoring checking is turned off by default.
insensitive
- true
for checking case insensitive and space
ignoring; false
if not (default)