Search code examples
asn.1der

Can ASN.1 *STRING field have zero length?


Does ASN.1 standard allow UTF8String or PrintableString to have zero length? I've been looking for this information in ASN.1 specs but can't seem to find it. I'm using DER encoding.


Solution

  • Yes

    Consider following specification

    Example DEFINITIONS AUTOMATIC TAGS ::= 
    BEGIN
      Name ::= PrintableString                       
    END
    

    and following value

    value Name::= ""
    

    BER (and DER) encoding is

    > ASN1STEP: Encoding of value notation  for PDU #1:
    > 
    > Encoding to the file 'data.ber' using BER encoding rule... Name
    > PrintableString: tag = [UNIVERSAL 19] primitive; length = 0   ""
    > Encoded successfully in 2 bytes: 1300
    

    Tested on https://asn1.io/asn1playground/