Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input stream reader to read parts from another stream #40

Closed
stcarrez opened this issue Apr 15, 2023 · 0 comments
Closed

Input stream reader to read parts from another stream #40

stcarrez opened this issue Apr 15, 2023 · 0 comments

Comments

@stcarrez
Copy link
Owner

Some files are composed of mime multi-part sections as described in the RFC 1341. Each multi-part section is separated by boundaries.

We can take the advantages of the stream composing framework available in Ada Utility Library to allow reading such multi-part files.

We could use such new Input_Part_Stream type as follows:

SEP     : constant String := "" & ASCII.LF;
File    : aliased Util.Streams.Files.File_Stream;
Parts   : Util.Streams.Buffered.Parts.Input_Part_Stream;
Head, Msg, sign : Ada.Strings.Unbounded.Unbounded_String;

  File.Open (Ada.Streams.Stream_IO.In_File, Path);
  Parts.Initialize (Input => File'Unchecked_Access, Size => 4096);
  Parts.Set_Boundary (SEP & "-----BEGIN PGP SIGNED MESSAGE-----" & SEP);
  Parts.Read (Head);
  Parts.Set_Boundary (SEP & "-----BEGIN PGP SIGNATURE-----" & SEP);
  Parts.Read (Msg);
  Parts.Set_Boundary (SEP & "-----END PGP SIGNATURE-----" & SEP);
  Parts.Read (Sign);
stcarrez added a commit that referenced this issue Apr 15, 2023
- add a new simple test, register it for execution, verify
  each part that is extracted
- add a simple text with several parts and different boundaries
stcarrez added a commit that referenced this issue Apr 15, 2023
- provide the Input_Part_Stream type and override the necessary
  operation to mark the end of buffer according to the boundary.
stcarrez added a commit that referenced this issue Apr 15, 2023
- add eob marker
- use a dispatching call for Fill so that we can override it
  and implement the boundary part identification
stcarrez added a commit that referenced this issue Apr 16, 2023
- extract the parts using several buffer sizes
stcarrez added a commit that referenced this issue Apr 16, 2023
- declare Test_Parts_3 procedure, register new test for execution
stcarrez added a commit that referenced this issue Apr 16, 2023
- add new parts extraction test to extract a public key from a PEM file
- add the public key test example
stcarrez added a commit that referenced this issue Apr 16, 2023
- add Next_Part to restart for the next part extraction
- when calling Is_Eob we must look if we reached the boundary
  and in some cases we may need to fill again the buffer for the check
stcarrez added a commit that referenced this issue Apr 16, 2023
- add multipart to extract a certificat part and dump it as is,
- add another multi-part that directs the part to the Base64 decoder
  and analyzes the ASN1 certificate byte stream
stcarrez added a commit that referenced this issue Apr 22, 2023
- fix the XML serializer to support multipart stream,
- fix Read procedure to stop when we reached end of stream,
- when filling the multi-part buffer, we must clear the
  Real_Write_Pos otherwise we re-use some past data
@stcarrez stcarrez closed this as completed Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant