ASN.1 String Types¶
ASN.1 defines a variety of string types used to represent textual data.
All generated Python classes for these string types will wrap the native
Python str type. This applies to the following ASN.1 string types:
IA5String
PrintableString
VisibleString
ISO646String
NumericString
UniversalString
BMPString
UTF8String
GeneralString
GraphicString
TeletexString (T61String)
VideotexString
ObjectDescriptor
UTCTime
GeneralizedTime
Example ASN.1 definition:
MyUTF8String ::= UTF8String
MyPrintable ::= PrintableString
which generate Python classes roughly equivalent to:
class MyUTF8String(_Asn1BasicType[str]):
pass
class MyPrintable(_Asn1BasicType[str]):
pass
Conceptual Representation¶
- class _Asn1BasicType[str]
Represents an ASN.1 string type.
- __init__(self, value: str | None = None) None
Initializes the string type instance with an optional initial value.
The value must be a Python
strorNone.
- property value: str
Gets or sets the string value.
Setting the value accepts any Python object coercible to
str, such as string literals or other string-like objects.Important
The string is expected to conform to the ASN.1 string type’s character repertoire and constraints; however, validation is performed by the constraint checking methods.
Character Sets and Constraints
Each ASN.1 string type restricts the allowed characters differently. For example:
PrintableStringallows a limited set of printable characters.IA5Stringcorresponds roughly to ASCII.UTF8Stringsupports the full Unicode set.
The generated classes enforce these constraints via validation and raise exceptions if invalid data is assigned and packed.
Note
Mutating the returned string is not possible since Python strings are immutable. To change the value, assign a new string explicitly.