otupy.types.targets.artifact.Artifact

class Artifact(mime_type=None, payload=None, hashes=None)

Bases: Record

OpenC2 Artifact

Implements the artifact target (Section 3.4.1.1). An array of bytes representing a file-like object or a link to that object.

Mime types, if used, may be validated for valid syntax or registered types in IANA. Both options are disabled by default, but can be enabled by setting the validate_syntax and validate_iana options, respectively. Mind that IANA registry validation needs to download the updated IANA registry, hence this option may take some time the first time it is used. Validation is enabled at the class level, so once enabled, it applies to all objects. Validation, if enabled, is automatically applied when instantiating an object, but can also be explicitly invoked at a later stage.

Methods

fromdict

Builds instance from dictionary

todict

Converts to dictionary

validate

Validate this instance

Attributes

hashes

Hashes of the payload content

mime_type

Permitted values specified in the IANA Media Types registry, [RFC6838]

payload

Choice of literal content or URL

validate_iana

Validate the mime_type value is present in the IANA Media Types registry

validate_syntax

Validate the syntax of mime_type according to IANA media types rules

__init__(mime_type=None, payload=None, hashes=None)

Initialize Artifact

Initializes an Artifact and optionally performs validation on valid mime_types. Validation can include both basic syntax validation as well as verification that the mime_type is registered in the IANA Media Types register. :param mime_type: Media Type :param payload: Payload :param hashes: Hashes value :param syntax_validation: Enable validation of media type syntax (Default: False). :param iana_validation: Check if the media type is registered in the IANA registry (Default: False)

classmethod fromdict(dic, e)

Builds instance from dictionary

It is used during deserialization to create an otupy instance from the text message. It takes an Encoder instance that is used to recursively build instances of the inner objects (the Encoder provides standard methods to create instances of base objects like strings, integers, boolean).

Parameters:
  • dic – The intermediary dictionary representation from which the object is built.

  • e – The Encoder that is being used.

Returns:

An instance of this class initialized from the dictionary values.

hashes: Hashes = None

Hashes of the payload content

mime_type: str = None

Permitted values specified in the IANA Media Types registry, [RFC6838]

payload: Payload = None

Choice of literal content or URL

todict(e)

Converts to dictionary

It is used to convert this object to an intermediary representation during serialization. It takes an Encoder argument that is used to recursively serialize inner data and structures (the Encoder provides standard methods for converting base types to dictionaries)..

Parameters:

e – The Encoder that is being used.

Returns:

A dictionary compliants to the Language Specification’s serialization rules.

validate()

Validate this instance

Validation includes two options: validate the syntax and validate the presence of the media type in the IANA registry. Both these options are optional, and must be enabled explicitely by setting the validate_syntax and validate_iana class attributes.

Validation also ensures the object includes at least one field, as required by the Specification. :return: True, if the fields are compliant to the Specification (according to selected validation options).

validate_iana: bool = False

Validate the mime_type value is present in the IANA Media Types registry

validate_syntax: bool = False

Validate the syntax of mime_type according to IANA media types rules