CGI-SE-Trusted-Services / c2c-common

http://pvendil.github.io/c2c-common/
GNU Affero General Public License v3.0
45 stars 19 forks source link

questions of COERBitString #11

Open wolf-hunter404 opened 4 years ago

wolf-hunter404 commented 4 years ago

I don't have experience is this field, and I have some questions ,when COERBitString init during the testing process,look at the details as followings: 'org.certificateservices.custom.c2x.asn1.coer.COERBitStringSpec' when "encoded" is "1001" value is 0x1001 how did you get length as "16"? when "encoded" is "00" value is 0L how did you get length as "8"? if i have a string "abc" ,how i can calculate length and value? look at my code follwing ,is there anything wrong with that, help me check please. image

glmax commented 4 years ago

When decoding (C)OER bitstrings, you need to know in advance whether the bitstring has a fixed size or not. In case it's a fixed-size bitstring, you need to know its length. You cannot derive that information purely from the encoded data.

There is one COERBitString decoding constructor for fixed-size bitstrings and one for variable-size bitstrings.

Length and value of your string "abc" depend on how you want to represent it as one single number/sequence of bits. However, if you want to encode strings anyway, you would be better off using COERUTF8String.