
    5dU(                         d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZ  ed          Z ed          Z	 dd	Z	 	 dd
Zd Zd ZdS )a  
This module contains functions that construct metadata and generate signing
keys.

Function Manifest for this Module

Key Creation:
  gen_keys
  gen_and_write_keys

Metadata Construction:
  build_delegating_metadata
  build_root_metadata         (wraps build_delegating_metadata)
    )	timedelta   )SECURITY_METADATA_SPEC_VERSION
PrivateKey	PublicKeycheckformat_delegationscheckformat_natural_intcheckformat_stringcheckformat_utc_isoformatiso8601_time_plus_delta   )daysim  Nc                 (   |i }|t          t          d                    }|t          t                    }t          |            t	          |           t	          |           t          |           t          |           | |t          |||d}|S )uy  
    # ✅ TODO: Docstring

    Builds delegating metadata, e.g. root.json, key_mgr.json.

    See metadata specification at:
    anaconda.atlassian.net/wiki/spaces/AD/pages/285147281/Conda+Security+Metadata+Specification

    Arguments:
        metadata_type:
            The type of this metadata (e.g. root or key_mgr).  This should
            match the intended filename (without .json)

        delegations (default {} )
            a dictionary defining the delegations this metadata makes.
            Each key is the role delegated to, with the value equal to a
            dictionary listing the acceptable public keys and threshold
            (number of signatures from distinct acceptable public keys) for the
            delegated role.  e.g.
            {   'root.json':
                    {'pubkeys': ['01'*32, '02'*32, '03'*32], 'threshold': 2},
                'key_mgr.json':
                    {'pubkeys': ['04'*32], 'threshold': 1}}

            If not provided, an empty dictionary (no delegations) will be used.

        version (default 1)
            the version of the metadata; root metadata must advance one version
            at a time (root chaining).  For other types of metadata, versions
            are advisory.

        timestamp (default: current system time)
            UTC time associated with the production of this metadata, in
            ISO8601 format (e.g. '2020-10-31T14:45:19Z')

        expiration (default: current system time plus ROOT_MD_EXPIRY_DISTANCE)
            UTC time beyond which this metadata should be considered expired
            and not verifiable by any client seeking new metadata
    Nr   )typeversionmetadata_spec_version	timestamp
expirationdelegations)r   r   ROOT_MD_EXPIRY_DISTANCEr
   r   r	   r   r   )metadata_typer   r   r   r   mds         Ilib/python3.11/site-packages/conda_content_trust/metadata_construction.pybuild_delegating_metadatar   #   s    X +IaLL99	,-DEE
 }%%% i(((j)))G$$$K((( !? "
 
B I    c                 p    |t          t                    }||d||dd}t          d|| ||          }|S )u#  
    Wrapper for build_delegating_metadata().  Helpfully requires root to list
    itself and key_mgr in its delegations.

    # ✅ TODO: Docstring

    # ✅ TODO: Expand build_root_metadata flexibility for
    #          directly-root-delegated roles (i.e. in addition to channeler).
    N)pubkeys	threshold)rootkey_mgrr   )r   r   r   r   r   )r   r   r   )	root_versionroot_pubkeysroot_thresholdkey_mgr_pubkeyskey_mgr_thresholdroot_timestamproot_expirationr   root_mds	            r   build_root_metadatar)   s   si    8 12IJJ )~FF.=NOO K
 ( "  G Nr   c                 t   t                      \  }}t          | dz   d          5 }|                    t          j        |                     ddd           n# 1 swxY w Y   t          | dz   d          5 }|                    t          j        |                     ddd           n# 1 swxY w Y   ||fS )a  
    Generate an ed25519 key pair, then write the key files to disk.

    Given fname, write the private key to fname.pri, and the public key to
    fname.pub. Performs no filename validation, etc.  Also returns the private
    key object and the public key object, in that order.
    z.priwbNz.pub)gen_keysopenwriter   to_bytesr   )fnameprivatepublicfobjs       r   gen_and_write_keysr4      s%    jjOGV
 
efnd	#	# 1t

:&w//0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	efnd	#	# /t

9%f--.../ / / / / / / / / / / / / / / F?s#   (AA A7(B++B/2B/c                  X    t          j                    } |                                 }| |fS )a}  
    Generate an ed25519 key pair and return it (private key, public key).

    Returns two objects:
      - a conda_content_trust.common.PrivateKey, a subclass of
        cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey
      - a conda_content_trust.common.PublicKey, a subclass of
        cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey
    )r   generate
public_key)r1   r2   s     r   r,   r,      s-     !##G!!FF?r   )Nr   NN)NN)__doc__datetimer   commonr   r   r   r   r	   r
   r   r   !REPODATA_VERIF_MD_EXPIRY_DISTANCEr   r   r)   r4   r,    r   r   <module>r=      s         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 %.I2$6$6$6 !#)---  LPM M M Ml 0 0 0 0f  2    r   