help-libtasn1
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: streaming decoding


From: Dmitriy Anisimkov
Subject: Re: streaming decoding
Date: Tue, 20 Sep 2011 16:55:14 +0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.22) Gecko/20110907 SUSE/3.1.14 Thunderbird/3.1.14

On 08/12/2011 11:41 AM, Dmitriy Anisimkov wrote:
Is there way to decode binary stream with indefinite number of ASN.1 defined records ?


To know the record length I have to use asn1_get_tag_der and asn1_get_length_ber.
I made it in Ada.
------------------------------------------------
   function Get_Length
     (Data : Stream_Element_Array) return Stream_Element_Count
   is
      use type C.long;

      subtype Offset is Stream_Element_Offset;

      Tag_Len, BER_Len : aliased C.int;
      cls : aliased C.unsigned_char;
      tag : aliased C.unsigned_long;
      RC : constant C.int :=
        asn1_get_tag_der
          (Data (Data'First)'Unrestricted_Access, Data'Length, cls'Access,
           Tag_Len'Access, tag'Access);
      RL : C.long;

   begin
      if RC /= ASN1_SUCCESS then
         raise Constraint_Error with Error_Message (RC);
      end if;

      if Tag_Len >= Data'Length then
         return 0;
      end if;

      RL := asn1_get_length_ber
              (Data (Data'First + Offset (Tag_Len))'Unrestricted_Access,
               Data'Length - Tag_Len, BER_Len'Access);

      if RL < 0 then
         raise Constraint_Error with Error_Message (C.int (RL));
      end if;

      RL := RL + C.long (Tag_Len + BER_Len);

      if RL > Data'Length then
         return 0;
      end if;

      return Stream_Element_Count (RL);
   end Get_Length;
--------------------------------------------------

The better way would be if function asn1_der_decoding (or any similar new one) returned the decoded record length.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]