The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CSAF::Parser - Parse a CSAF document

SYNOPSIS

    use CSAF::Parser;

    my $parser = eval { CSAF::Parser->new(file => 'csaf-2023-01.json') };

    Carp::croak "Failed to parse CSAF document" if ($@);

    my $csaf = $parser->parse;

    $csaf->document->title('CSAF Document');

    $csaf->to_string;

DESCRIPTION

CSAF document parser.

ATTRIBUTES

data

CSAF document hash.

file

CSAF document file.

content

CSAF document string.

METHODS

new ([file => ($path | <FH>) | content => $json_string | data => $hash])

CSAF document file:

    my $parser = CSAF::Parser->new(file => 'csaf-2023-01.json');

    open (my $fh, '<', 'csaf-2023-01.json') or die $!;
    my $parser = CSAF::Parser->new(file => $fh);

CSAF document in JSON string format:

    my $parser = CSAF::Parser->new(content => <<JSON);
    {
      "document": {
        "category": "csaf_base",
        "csaf_version": "2.0",
        "publisher": {
          "category": "other",
          "name": "OASIS CSAF TC",
          "namespace": "https://csaf.io"
        },
        "title": "Template for generating CSAF files for Validator examples",
        "tracking": {
          "current_release_date": "2021-07-21T10:00:00.000Z",
          "id": "OASIS_CSAF_TC-CSAF_2.0-2021-TEMPLATE",
          "initial_release_date": "2021-07-21T10:00:00.000Z",
          "revision_history": [
            {
              "date": "2021-07-21T10:00:00.000Z",
              "number": "1",
              "summary": "Initial version."
            }
          ],
          "status": "final",
          "version": "1"
        }
      }
    }
    JSON

CSAF document hash:

    my $parser = CSAF::Parser->new(data => {
      "document" => {
        "category" => "csaf_base",
        "csaf_version" => "2.0",
        "publisher" => {
          "category" => "other",
          "name" => "OASIS CSAF TC",
          "namespace" => "https://csaf.io"
        },
        "title" => "Template for generating CSAF files for Validator examples",
        "tracking" => {
          "current_release_date" => "2021-07-21T10:00:00.000Z",
          "id" => "OASIS_CSAF_TC-CSAF_2.0-2021-TEMPLATE",
          "initial_release_date" => "2021-07-21T10:00:00.000Z",
          "revision_history" => [
            {
              "date" => "2021-07-21T10:00:00.000Z",
              "number" => 1,
              "summary" => "Initial version."
            }
          ],
          "status" => "final",
          "version" => 1
        }
      }
    });
parse

Parse the provided CSAF document and return CSAF.

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://github.com/giterlizzi/perl-CSAF/issues. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/giterlizzi/perl-CSAF

    git clone https://github.com/giterlizzi/perl-CSAF.git

AUTHOR

  • Giuseppe Di Terlizzi <gdt@cpan.org>

LICENSE AND COPYRIGHT

This software is copyright (c) 2023-2024 by Giuseppe Di Terlizzi.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.