Please review the following problem and let me know incase I am wrong in
understanding. This is very much needed for me to solve the problem
which I am currently facing.
Problem:
I have a char *buffer to which I need to encode lrsn which is a 4
byte ASN int. The lrsn value to be encoded is greater than 127. Here I
am trying to encode the lrsn value manuaaly.(just like the way the
encoding routines does).
Solution:
Assuming lrsn value to be encoded is 222.
buffer[0] = Tag-----> In the first byte I encode the Tag.
buffer[1] = 0x81----> Since lrsn value is 128(>127), set MSB bit
to 1 and the remaining bits
indicates how many bytes contain the length of
contents length.Since 1 byte is sufficient to
hold 222 LSB bit is also set to 1. Hence 0x81.
buffer[2] = 1-------> this byte indicates the actual length
buffer[3] == 222.
Both your first and second examples are incorrectly encoded. For
LRSN ::= INTEGER
lrsn LRSN ::= 222
the encoding of the value would be 0x00DE. Note that it is two octets
long, not one. The value is encoded as a two's-complement integer, so the
first bit is the sign. If it were 0xDE, since the first bit is a 1, it's
negative and would be the encoding for -34.
Thus we would have
TT the tag
02 the length of the value
00DE the value
For lrsn > 256
buffer[0] = Tag;
buffer[1] = 0x81---> since 1 byte is required to say the actual
length of contents which is 2 bytes.
buffer[2] = 2;----> since 2 bytes are required to hold 256 value.
buffer[3] and buffer[4] ---> contains 256 value.
TT the tag
02 the length of the value
0100 the value
Please review my above understanding and give me u'r comments as I have
to understand this to solve the original problem which I have.
=====================================================================
Conrad Sigona Voice Mail : 1-732-302-9669 x400
OSS Nokalva Fax : 1-614-388-4156
[EMAIL PROTECTED] My direct line : 1-315-845-1773
_______________________________________________
Asn1 mailing list
[email protected]
http://lists.asn1.org/mailman/listinfo/asn1