readLength
private long readLength()
throws java.io.IOException
8.1.3.3 For the definite form, the length octets shall consist of one or
more octets, and shall represent the number of octets in the contents
octets using either the short form (see 8.1.3.4) or the long form (see
8.1.3.5) as a sender's option. NOTE – The short form can only be used if
the number of octets in the contents octets is less than or equal to 127.
8.1.3.4 In the short form, the length octets shall consist of a single
octet in which bit 8 is zero and bits 7 to 1 encode the number of octets
in the contents octets (which may be zero), as an unsigned binary integer
with bit 7 as the most significant bit. EXAMPLE L = 38 can be encoded as
001001102 8.1.3.5 In the long form, the length octets shall consist of an
initial octet and one or more subsequent octets. The initial octet shall
be encoded as follows: a) bit 8 shall be one; b) bits 7 to 1 shall encode
the number of subsequent octets in the length octets, as an unsigned
binary integer with bit 7 as the most significant bit; c) the value
111111112 shall not be used. ISO/IEC 8825-1:2003 (E) NOTE 1 – This
restriction is introduced for possible future extension. Bits 8 to 1 of
the first subsequent octet, followed by bits 8 to 1 of the second
subsequent octet, followed in turn by bits 8 to 1 of each further octet
up to and including the last subsequent octet, shall be the encoding of
an unsigned binary integer equal to the number of octets in the contents
octets, with bit 8 of the first subsequent octet as the most significant
bit. EXAMPLE L = 201 can be encoded as: 100000012 110010012 NOTE 2 – In
the long form, it is a sender's option whether to use more length octets
than the minimum necessary. 8.1.3.6 For the indefinite form, the length
octets indicate that the contents octets are terminated by
end-of-contents octets (see 8.1.5), and shall consist of a single octet.
8.1.3.6.1 The single octet shall have bit 8 set to one, and bits 7 to 1
set to zero. 8.1.3.6.2 If this form of length is used, then
end-of-contents octets (see 8.1.5) shall be present in the encoding
following the contents octets. 8.1.4 Contents octets The contents octets
shall consist of zero, one or more octets, and shall encode the data
value as specified in subsequent clauses. NOTE – The contents octets
depend on the type of the data value; subsequent clauses follow the same
sequence as the definition of types in ASN.1. 8.1.5 End-of-contents
octets The end-of-contents octets shall be present if the length is
encoded as specified in 8.1.3.6, otherwise they shall not be present. The
end-of-contents octets shall consist of two zero octets. NOTE – The
end-of-contents octets can be considered as the encoding of a value whose
tag is universal class, whose form is primitive, whose number of the tag
is zero, and whose contents are absent, thus: End-of-contents Length
Contents 0016 0016 Absent
- Throws:
java.io.IOException