
    ܖi                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZ d	d
lmZ  ej0                  e      Z	 	 	 	 ddZ G d de      Zy)zU
Functionality for formatting vulnerability results using the CycloneDX SBOM format.
    )annotationsN)cast)output)Bom)	Component)	BomTargetVulnerability   )VulnerabilityFormatc                   g }g }| j                         D ]  \  }}|j                         rt        t        j                  |      }t        |j                  t        |j                              }|D ]I  }|j                  t        |j                  |j                  dt        |j                        g             K |j                  |        t        ||      S )N)nameversionUpgrade)ref)iddescriptionrecommendationaffects)
componentsvulnerabilities)items
is_skippedr   serviceResolvedDependencyr   r   strr   appendr	   r   r   r   bom_refr   )resultr   r   depvulnscvulns          _/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_format/cyclonedx.py_pip_audit_result_to_bomr$      s     OJlln 
U >>7--s3388S-=> 		D""ww $ 0 0#,&19956		 	!'* *oFF    c                      e Zd ZdZej
                   G d dej                               ZddZe	d	d       Z
	 	 	 	 	 	 d
dZy)CycloneDxFormatz
    An implementation of `VulnerabilityFormat` that formats vulnerability results using CycloneDX.
    The container format used by CycloneDX can be additionally configured.
    c                  h    e Zd ZdZej
                  j                  Zej
                  j                  Z	y)CycloneDxFormat.InnerFormatz8
        Valid container formats for CycloneDX.
        N)
__name__
__module____qualname____doc__r   OutputFormatJSONJsonXMLXml r%   r#   InnerFormatr)   <   s+    	 ""''!!%%r%   r4   c                    || _         y)z|
        Create a new `CycloneDxFormat`.

        `inner_format` determines the container format used by CycloneDX.
        N)_inner_format)selfinner_formats     r#   __init__zCycloneDxFormat.__init__E   s     *r%   c                     y)z8
        See `VulnerabilityFormat.is_manifest`.
        Tr3   )r7   s    r#   is_manifestzCycloneDxFormat.is_manifestN   s    
 r%   c                    |rt         j                  d       t        |      }t        j                  || j
                  j                  t        j                  j                        }|j                         S )z
        Returns a CycloneDX formatted string for a given mapping of dependencies to vulnerability
        results.

        See `VulnerabilityFormat.format`.
        z0--fix output is unsupported by CycloneDX formats)bomoutput_formatschema_version)
loggerwarningr$   r   make_outputterr6   valueSchemaVersionV1_4output_as_string)r7   r   fixesr=   	formatters        r#   formatzCycloneDxFormat.formatU   s`     NNMN&v.)),,22!//44
	 ))++r%   N)r8   r)   )returnbool)r   ;dict[service.Dependency, list[service.VulnerabilityResult]]rG   zlist[fix.FixVersion]rJ   r   )r*   r+   r,   r-   enumuniqueEnumr4   r9   propertyr;   rI   r3   r%   r#   r'   r'   6   sd    
 
[[&dii & &*  ,K, $, 
	,r%   r'   )r   rL   rJ   r   )r-   
__future__r   rM   loggingtypingr   	cyclonedxr   cyclonedx.model.bomr   cyclonedx.model.componentr   cyclonedx.model.vulnerabilityr   r	   pip_audit._fix_fixfixpip_audit._service_servicer   	interfacer   	getLoggerr*   r@   r$   r'   r3   r%   r#   <module>r_      sd    #     # / B  $ *			8	$GGGG<4,) 4,r%   