otupy.types.targets.artifact.Artifact
- class Artifact(mime_type=None, payload=None, hashes=None)
Bases:
RecordOpenC2 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
Builds instance from dictionary
Converts to dictionary
Validate this instance
Attributes
Hashes of the payload content
Permitted values specified in the IANA Media Types registry, [RFC6838]
Choice of literal content or URL
Validate the mime_type value is present in the IANA Media Types registry
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
Encoderinstance that is used to recursively build instances of the inner objects (theEncoderprovides 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
Encoderthat is being used.
- Returns:
An instance of this class initialized from the dictionary values.
- todict(e)
Converts to dictionary
It is used to convert this object to an intermediary representation during serialization. It takes an
Encoderargument that is used to recursively serialize inner data and structures (the Encoder provides standard methods for converting base types to dictionaries)..- Parameters:
e – The
Encoderthat 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).