pyrit.models.BinaryPathDataTypeSerializer#

class BinaryPathDataTypeSerializer(*, category: str, prompt_text: str | None = None, extension: str | None = None)[source]#

Bases: DataTypeSerializer

__init__(*, category: str, prompt_text: str | None = None, extension: str | None = None)[source]#

Serializer for arbitrary binary data paths.

This serializer handles generic binary data that doesn’t fit into specific categories like images, audio, or video. Useful for XPIA attacks and storing files like PDFs, documents, or other binary formats.

Parameters:
  • category (str) – The category or context for the data.

  • prompt_text (Optional[str]) – The binary file path or identifier.

  • extension (Optional[str]) – The file extension, defaults to ‘bin’.

Methods

__init__(*, category[, prompt_text, extension])

Serializer for arbitrary binary data paths.

data_on_disk()

Returns True if the data is stored on disk.

get_data_filename([file_name])

Generates or retrieves a unique filename for the data file.

get_extension(file_path)

Get the file extension from the file path.

get_mime_type(file_path)

Get the MIME type of the file path.

get_sha256()

read_data()

Reads the data from the storage.

read_data_base64()

Reads the data from the storage.

save_b64_image(data[, output_filename])

Saves the base64 encoded image to storage.

save_data(data[, output_filename])

Saves the data to storage.

save_formatted_audio(data[, num_channels, ...])

Saves the PCM16 of other specially formatted audio data to storage.

Attributes

category: str#
data_on_disk() bool[source]#

Returns True if the data is stored on disk.

data_sub_directory: str#
data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output']#
file_extension: str#
value: str#