
    5da              
         d Z ddlmZ ddlmZmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ d	Zeeeeeee ed
          gZddgZ G d de          Z G d de          Z G d de          Z  G d de          Z!d Z"d Z#d Z$ G d d          Z% G d de%ej&                  Z' G d de%ej(                  Z)d^d"Z*eZ+d_d$Z,d`d&Z-dad(Z.dbd*Z/eZ0dcd,Z1 G d- d.e          Z2ddd0Z3ded3Z4dfd6Z5dgd9Z6e+Z7dhd;Z8did>Z9djd@Z:dkdBZ;e7Z<dldDZ=dmdFZ>eZ?dndHZ@dodJZAeZBdpdLZCeZDdqdOZEdrdRZFe0ZGdsdUZHdtdWZIdX ZJdY ZKdud\ZLd] ZMd
S )va  
This module contains functions that provide format validation, serialization,
and some key transformations for the pyca/cryptography library.  These are used
across conda_content_trust modules.

Function Manifest for this Module, by Category

Encoding:
  x  canonserialize

Formats and Validation:
     PrivateKey  -- extends cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey
     PublicKey   -- extends cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey
     checkformat_string
  x  is_hex_string
  x  is_hex_signature
  r  is_hex_key
  r  checkformat_hex_key
  r  checkformat_list_of_hex_keys
  x  is_signable
  x  checkformat_byteslike
  x  checkformat_natural_int
  x  checkformat_expiration_distance
  x  checkformat_utc_isoformat
  x  checkformat_gpg_fingerprint
     is_gpg_fingerprint
  x  checkformat_gpg_signature
     is_gpg_signature
     checkformat_any_signature
     checkformat_delegation
     checkformat_delegations
     checkformat_delegating_metadata
  x  iso8601_time_plus_delta

Crypto Utility:
   x sha512256
   x keyfiles_to_keys
   x keyfiles_to_bytes

Exceptions:
    CCT_Error
        SignatureError
        MetadataVerificationError
        UnknownRoleError
    )annotations)hexlify	unhexlify)datetime	timedelta)dumpsload)AnyProtocol)serialization)ed25519z0.6.0Nrootkey_mgrc                      e Zd ZdZdS )	CCT_Errorz
    All errors we raise that are not ValueErrors, TypeErrors, or
    certain errors from securesystemslib should be instances of this class or
    of subclasses of this class.
    N__name__
__module____qualname____doc__     :lib/python3.11/site-packages/conda_content_trust/common.pyr   r   Q              r   r   c                      e Zd ZdZdS )SignatureErrorzi
    Indicates that a signable cannot be verified due to issues with the
    signature(s) inside it.
    Nr   r   r   r   r   r   Y              r   r   c                      e Zd ZdZdS )MetadataVerificationErrorz
    Indicates that a chain of authority metadata cannot be verified (e.g.
    a metadata update is found on the repository, but could not be
    authenticated).
    Nr   r   r   r   r   r   `   r   r   r   c                      e Zd ZdZdS )UnknownRoleErrorzs
    Indicates that a piece of role metadata (like root.json, or key_mgr.json)
    was expected but not found.
    Nr   r   r   r   r!   r!   h   r   r   r!   c                r    	 t          | dd          }n# t          $ r  w xY w|                    d          S )u  
    Given a JSON-compatible object, does the following:
     - serializes the dictionary as utf-8-encoded JSON, lazy-canonicalized
       such that any dictionary keys in any dictionaries inside <dictionary>
       are sorted and indentation is used and set to 2 spaces (using json lib)

    TODO: ✅ Implement the serialization checks from serialization document.

    Note that if the provided object includes a dictionary that is *indexed*
    by both strings and integers, a TypeError will be raised complaining about
    comparing strings and integers during the sort.  (Each dictionary in an
    object must be indexed only by strings or only by integers.)
       T)indent	sort_keysutf-8)r   	TypeErrorencode)objjson_strings     r   canonserializer+   o   sS      CT:::    g&&&s    !c                t    t          | d          5 }t          |          }d d d            n# 1 swxY w Y   |S )Nrb)openr	   )fnamefobjmetadatas      r   load_metadata_from_filer2      sx     
eT		 d::              
 Os   -11c                    t          |           } t          |d          5 }|                    |            ddd           dS # 1 swxY w Y   dS )zi
    Canonicalizes and serializes JSON-friendly metadata, and writes that to the
    given filename.
    wbN)r+   r.   write)r1   filenamer0   s      r   write_metadata_to_filer7      s     h''H	h		 

8                 s   AA
Ac                  T    e Zd ZdZed             Zed             Zed             ZdS )MixinKeyz
    This is a mix-in (https://www.ianlewis.org/en/mixins-and-python) for the
    PrivateKey and PublicKey classes, specifically.  It provides some
    convenience functions.
    c                l    t          |                     |                                        d          S )Nr&   )r   to_bytesdecodeclskeys     r   to_hexzMixinKey.to_hex   s*    s||C(())00999r   c                    t          |           t          |          t          |          urdS |                     |          |                     |          k    S )z
        Given Ed25519PrivateKey or Ed25519PublicKey objects, determines if the
        underlying key data is identical.
        F)checkformat_keytyper;   )r>   k1k2s      r   is_equivalent_tozMixinKey.is_equivalent_to   sQ     	88488##5||B3<<#3#333r   c                    t          |           t          |          }|                     |          }t          |           |S N)checkformat_hex_keyr   
from_bytesrB   )r>   key_value_in_hexkey_value_in_bytes
new_objects       r   from_hexzMixinKey.from_hex   sH    
 	,---&'788^^$677

###r   N)r   r   r   r   classmethodr@   rF   rN   r   r   r   r9   r9      so          : : [: 4 4 [4   [  r   r9   c                  H     e Zd ZdZed             Ze fd            Z xZS )
PrivateKeya	  
    This class expands the class
    cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey
    very slightly, adding some functionality from MixinKey.

    Note on the sign() method:
        We preserve Ed25519PrivateKey's sign method unchanged.  The sign()
        method is deterministic and does not depend at any point on the ability
        to generate random data (unlike the key generation).  The returned
        value for sign() is a length 64 bytes() object, a raw ed25519
        signature.
    c                    |                     t          j        j        t          j        j        t          j                              S )N)encodingformatencryption_algorithm)private_bytesr   EncodingRawPrivateFormatNoEncryptionr=   s     r   r;   zPrivateKey.to_bytes   s=      "+/ .2!.!;!=!= ! 
 
 	
r   c                d    t          |           t                                          |          S a  
        Constructs an object of the class based on the given key value.
        The "cryptography" library provides from_public_bytes() and
        from_private_bytes() class methods for Ed25519PublicKey and
        Ed25519PrivateKey classes in place of constructors.  We extend provide
        a single API for those, and make the created objects objects of the
        subclass using this mix-in.
        )checkformat_byteslikesuperfrom_private_bytesr>   rL   	__class__s     r   rJ   zPrivateKey.from_bytes   s-     	0111ww))*<===r   r   r   r   r   rO   r;   rJ   __classcell__ra   s   @r   rQ   rQ      si          
 
 [
 > > > > [> > > > >r   rQ   c                  H     e Zd ZdZed             Ze fd            Z xZS )	PublicKeyz
    This class expands the class
    cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey
    very slightly, adding some functionality from MixinKey.

    We preserve Ed25519PublicKey's verify() method unchanged.
    c                j    |                     t          j        j        t          j        j                  S )zi
        Pops out the nice, tidy bytes of a given ed25519 key object, public or
        private.
        )public_bytesr   rW   rX   PublicFormatr=   s     r   r;   zPublicKey.to_bytes   s-     "&(B(F
 
 	
r   c                d    t          |           t                                          |          S r\   )r]   r^   from_public_bytesr`   s     r   rJ   zPublicKey.from_bytes  s-     	0111ww(();<<<r   rb   rd   s   @r   rf   rf      si          
 
 [
 = = = = [= = = = =r   rf   
hex_stringr
   returnboolc                V    	 t          |            dS # t          t          f$ r Y dS w xY w)zm
    Returns True if hex is a hex string with no uppercase characters, no spaces,
    etc.  Else, False.
    TF)checkformat_hex_string
ValueErrorr'   rl   s    r   is_hex_stringrs     sA    
z***t	"   uu    ((	HexStringc                    t                               |            |                                 r|                                 | k    rt	          d          | S )z
    Throws TypeError if s is not a string.
    Throws ValueError if the given string is not a string of hexadecimal
    characters (upper-case not allowed to prevent redundancy).
    EExpected a hex string; non-hexadecimal or upper-case character found.)bytesfromhexisalnumlowerrq   rr   s    r   rp   rp   ,  s]     
MM* 
:#3#3#5#5#C#CS
 
 	
 r   hex_signaturec                N    t          |           rt          |           dk    rdS dS )a&  
    Returns True if key is a hex string with no uppercase characters, no
    spaces, no '0x' prefix(es), etc., and is 128 hexadecimal characters (the
    correct length for an ed25519 signature, 64 bytes of raw data represented
    as 128 hexadecimal characters).
    Else, returns False.
       TF)rs   len)r|   s    r   is_hex_signaturer   <  s0     ]## M(:(:c(A(At5r   hex_keyc                V    	 t          |            dS # t          t          f$ r Y dS w xY w)a  
    Returns True if key is a hex string with no uppercase characters, no
    spaces, no '0x' prefix(es), etc., and is 64 hexadecimal characters (the
    correct length for an ed25519 key, 32 bytes of raw data represented as 64
    hexadecimal characters).
    Else, returns False.
    TF)rI   r'   rq   r   s    r   
is_hex_keyr   J  sA    G$$$tz"   uurt   signablec                    t          | t                    oKt          |           ddhk    o6t          | d         t                    ot          | d                   t          v S )ar  
    Returns True if the given dictionary is a signable dictionary as produced
    by wrap_as_signable.  Note that there MUST be no additional elements beyond
    'signed' and 'signable' in the dictionary.  (The only data in the envelope
    outside the signed portion of the data should be the signatures; what's
    outside of 'signed' is under attacker control.)
    
signaturessigned)
isinstancedictsetrC   SUPPORTED_SERIALIZABLE_TYPESr   s    r   is_signabler   Y  se     	8T"" 	EMMlH55	Ex-t44	E (#$$(DD	r   Signablec                r    t          |           s't          dt          t                    z   dz             | S )Na#  Expected a signable dictionary, but the given argument does not match expectations for a signable dictionary (must be a dictionary containing only keys "signatures" and "signed", where the value for key "signatures" is a dict and the value for key "signed" is a supported serializable type ())r   r'   strr   r   s    r   checkformat_signabler   n  sM    x   

 7889
 <??
 
 	
 Or   c                      e Zd ZddZdS )	BytesLikerm   r   c                    d S rH   r   )selfargskwargss      r   r<   zBytesLike.decode}  s    r   N)rm   r   )r   r   r   r<   r   r   r   r   r   |  s(             r   r   	byteslikec                D    t          | d          st          d          | S )Nr<   z2Expected a bytes-like object with a decode method.)hasattrr'   )r   s    r   r]   r]     s*    9h'' NLMMMr   natural_intintc                V    t          |           | k    s| dk     rt          d          | S )N   zExpected an integer >= 1.)r   rq   )r   s    r   checkformat_natural_intr     s2    
;;&&+//4555r   stringr   c                N    t          | t                    st          d          | S )NzExpecting a string)r   r   r'   )r   s    r   checkformat_stringr     s(    fc"" .,---Mr   expiration_distancer   c                    t          | t                    s,t          dt          t	          |                     z             | S )NzLExpiration distance must be a datetime.timedelta object. Instead received a )r   r   r'   r   rC   )r   s    r   checkformat_expiration_distancer     sN    )955 
"$'-@(A(A$B$BC
 
 	

 r   HexKeyc                h    t          |            dt          |           k    rt          d          | S )N@   z<Expected a 64-character hex string representing a key value.)rp   r   rq   r   s    r   rI   rI     s5    7###	S\\WXXXNr   list_of_hex_keyslist[HexKey]c                    t          | t                    st          d          | D ]}t          |           t	          t          |                     t	          |           k    rt          d          | S )zU
    Note that this rejects any list of keys that includes any exact duplicates.
    z>Expected a list of 64-character hex strings representing keys.z]The given list of keys in hex string form contains duplicates.  Duplicates are not permitted.)r   listr'   rI   r   r   rq   )r   r   s     r   checkformat_list_of_hex_keysr     s     &-- 
L
 
 	
 $ % %G$$$$
3  !!S)9%:%:::,
 
 	

 r   date_stringc                p    	 t          j        | d           n# t          $ r t          d          d w xY w| S )Nz%Y-%m-%dT%H:%M:%SZzThe provided string appears not to be a datetime string formatted as an ISO8601 UTC-specific datetime (e.g. "1999-12-31T23:59:59Z").)r   strptimerq   r'   )r   s    r   checkformat_utc_isoformatr     s]    +';<<<<   '
 
 		 s    3gpg_fingerprintc                V    	 t          |            dS # t          t          f$ r Y dS w xY w)z
    True if the given value is a hex string of length 40 (representing a
    20-byte SHA-1 value, which is what OpenPGP/GPG uses as a key fingerprint).
    TF)checkformat_gpg_fingerprintr'   rq   r   s    r   is_gpg_fingerprintr     sA    
#O444tz"   uurt   GPGFingerprintc                   t          |           dk    r"t          dt          |           z   dz             t                              |            |                                 r|                                 | k    rt          d          | S )z\
    See is_gpg_fingerprint.  Raises a TypeError if is_gpg_fingerprint is not
    True.
    (   zThe given value, "z5", is not a full GPG fingerprint (40 hex characters).rw   )r   rq   r   rx   ry   rz   r{   r   s    r   r   r     s    
 ?r!! 3#7#77 ;3 3
 
 	
 
MM/"""""$$ 
(=(=(?(??(R(RS
 
 	
 r   gpg_signaturec                V    	 t          |            dS # t          t          f$ r Y dS w xY w)NTF)checkformat_gpg_signaturerq   r'   r   s    r   is_gpg_signaturer     sA    !-000t	"   uurt   GPGSignaturec                   t          | t                    s/t          dt          t	          |                     z   dz             t          t          |                                                     ddgg dfvrt          d          t          | d                   st          d          t          | d                   st          d          d	| v rt          | d	                    | S )
a  
    Raises a TypeError if the given object is not a dictionary representing a
    signature in a format that we expect.

    This is similar to BUT NOT THE SAME AS that produced by
    securesystemslib.gpg.functions.create_signature(), conforming to
    securesystemslib.formats.GPG_SIGNATURE_SCHEMA.

    We use a slightly different format in order to include the raw ed25519
    public key value. This is the format we expect for Root signatures.

    If the given object matches the format, returns silently.
    z@OpenPGP signatures objects must be dictionaries.  Received type 	 instead.other_headers	signature)r   see_alsor   zOpenPGP signature objects must include a "signature" and an "other_headers" entry, and may include a "see_also" entry.  No other entries are permitted.zG"other_headers" entry in OpenPGP signature object must be a hex string.z"signature" entry in OpenPGP signature obj must be a hex string representing an ed25519 signature, 128 hex characters representing 64 bytes of data.r   )r   r   r'   r   rC   sortedr   keysrq   rs   r   r   r   s    r   r   r   	  s'    mT** 
$}--../1<=
 
 	

 d=%%''(())	+&2222   +
 
 	
 788 
X
 
 	
 M+677 
-
 
 	
 ]""#M*$=>>>r   r   c                V    	 t          |            dS # t          t          f$ r Y dS w xY w)a  
    Returns True if signature_obj is a dictionary representing an ed25519
    signature, either in the conda-content-trust normal format, or
    the format for a GPG signature.

    See conda_content_trust.common.checkformat_signature() docstring for more details.
    TF)checkformat_signaturer'   rq   r   s    r   is_signaturer   <  sA    i(((tz"   uurt   	Signaturec                   t          | t                    st          d          d| v rt          | d                   st	          d          t          |           dk    r| S t          |           r| S t	          d          )ab  
    Raises a TypeError if the given object is not a dictionary.
    Raises a ValueError if the given object is a dictionary, but is not in
    our generalized signature format (supports both raw ed25519 signatures
    OpenPGP/GPG signatures).

    If the given object matches the format, returns silently.

    The generalized signature format is:
    {
     (REQUIRED)      'signature': <64-byte value ed25519 signature, as 128 hex chars>,
     (GPG SIGS ONLY) 'other_headers': <hex string of irrelevant OpenPGP data hashed in the signature digest>,
     (OPTIONAL)      'see_also': <40-hex-character SHA1 OpenPGP/GPG key identifier, for diagnostic purposes>
    }
    Examples:
        { 'signature': 'deadbeef'*32}      # normal ed25519 signature (no OpenPGP)

        { 'signature': 'deadbeef'*32,      # OpenPGP ed25519 signature
          'other_headers': 'deadbeef'*??}  # extra info OpenPGP insists on signing over

        { 'signature': 'deadbeef'*32,      # OpenPGP ed25519 signature
          'other_headers': 'deadbeef'*??,
          'see_also': 'deadbeef'*10}}      # listing an OpenPGP key fingerprint
    z*Expected a signature object, of type dict.r   zExpected a dictionary representing an ed25519 signature as a 128-character hex string.  This requires at least key "signature", with value a 128-character hexadecimal string representing a (64-byte) ed25519 signature.r   zProvided signature does not have the correct format for a signature object (neither simple ed25519 sig nor OpenPGP ed25519 sig).)r   r   r'   r   rq   r   r   r   s    r   r   r   N  s    2 i&& 
DEEEY&&+;Ik<R+S+S&:
 
 	
 
Y1		  
)	$	$ 
 
 
 	
r   
delegation
Delegationc                v   t          | t                    st          d          t          |           ddhk    rF| d         dk    r:t          | d         t                    rt          d | d         D                       st          d          t          | d                    t          | d                    | S )aO  
    A dictionary specifying public key values and threshold of keys
    e.g.
        {   'pubkeys': ['ff'*32, '1e'*32],
            'threshold': 1}
    threshold must be an integer >= 1. pubkeys must be a list of hexadecimal
    representations of ed25519 public keys.

    Note that because drafts are allowed, we do not demand here that the list
    of pubkeys include enough keys to meet threshold.  Not listing pubkeys yet
    is okay during writing, but when verifying metadata, one should not accept
    delegations with impossible-to-meet requirements (len(pubkeys) < threshold)
    zZDelegation information must be a dictionary specifying "pubkeys" and "threshold" elements.	thresholdpubkeysr   c                ,    g | ]}t          |          S r   )r   ).0ks     r   
<listcomp>z*checkformat_delegation.<locals>.<listcomp>  s    >>>1A>>>r   zDelegation information must be a dictionary specifying exactly two elements: "pubkeys" (assigned a list of 64-character hex strings representing individual ed25519 public keys) and "threshold", assigned an integer >= 1.)	r   r   r'   r   r   allrq   r   r   )r   s    r   checkformat_delegationr     s     j$'' 
2
 
 	

 	JK333{#q((z),d33 )>>
9(=>>>?? ) F
 
 	
 !I!6777J{3444r   delegationsdict[str, Delegation]c                    t          | t                    st          d          | D ]&}t          |           t	          | |                    '| S )a  
    A dictionary specifying a delegation for any number of role names.
    Index: rolename.  Value: delegation (see checkformat_delegation).
    e.g.
        {   'root.json':
                {'pubkeys': ['01'*32, '02'*32, '03'*32], # each is a lower-case hex string w/ length 64
                 'threshold': 2},                        # integer >= 1
            'channeler.json':
                {'pubkeys': ['04'*32], 'threshold': 1}}
    z"Delegations" information must be a dictionary indexed by role names, with values equal to dictionaries that each specify elements "pubkeys" and "threshold".)r   r   r'   r   r   )r   indexs     r   checkformat_delegationsr     sh     k4(( 
:
 
 	
  3 35!!!{512222r   r1   DelegatingMetadatac                   t          |            | d         D ]}t          | d         |                    | d         }dD ](}||vr"t          dt          |          z   dz             )t	          |d                    |d         t
          vrt          d|d         z   dz             t	          |d	                    t          |d
                    t          |d                    d|vrd|vrt          d          |d         dk    rd|vrt          d          dt
          v sJ d|v rt          |d                    d|v rt          |d                    dS dS )a
  
    Validates argument "metadata" as delegating metadata.  Passes if it is,
    raises a TypeError or ValueError if it is not.

    The required format is a dictionary containing all contents of a delegating
    metadata file, like root.json or key_mgr.json.  (This includes both the
    signatures portion and the signed contents portion, in the usual envelope
    -- see also checkformat_signable.)

    The required structure:
        {
          'signatures': {}, # for each entry in the 'signatures' dict:
                            #  - the key must pass checkformat_hex_key
                            #  - the value must pass checkformat_signature()
                            #    or checkformat_gpg_signature()
          'signed': {
            'type': <type>: # must match a string in SUPPORTED_DELEGATING_METADATA_TYPES (e.g. 'root')
            'metadata_spec_version': <SemVer string>,
            'delegations': {}, # value must pass checkformat_delegations()
            'expiration': <date>, # date must pass checkformat_utc_isoformat()

            # The 'signed' dict must always include either a 'timestamp' entry,
            # a 'version' entry, or both.  Further, in root metadata the
            # 'signed' dict must always include a 'version' entry (to support
            # root chaining).

            'timestamp': <date>, # if included, must pass checkformat_utc_isoformat()
            'version': <integer> # if included, must pass checkformat_natural_int(), i.e. be an integer >= 1
          }
        }

    e.g.
        {
          "signatures": {       # 0 or more signatures over the signed contents
            <public key>: {
              "other_headers": "04001608001d162104f075dd2f6f4cb3bd76134bbb81b6ca16ef9cd58905025f0bf546",
              "signature": "ab3e03385f757da74e08b46f1bf82709fbc2ce21823c28e2f0e3452415e2a9f1e2c82e418cc44e2908618cf0c7375f32fe0a5a75494909a59a82875ebc703c02",
            },
            ...
          },
          "signed": {           # signed contents
            "delegations": {
              "key_mgr.json": {
                "pubkeys": [
                  "013ddd714962866d12ba5bae273f14d48c89cf0773dee2dbf6d4561e521c83f7"
                ],
                "threshold": 1
              },
              "root.json": {
                "pubkeys": [
                  "bfbeb6554fca9558da7aa05c5e9952b7a1aa3995dede93f3bb89f0abecc7dc07"
                ],
                "threshold": 1
              }
            },
            "expiration": "2021-07-13T05:46:45Z",
            "metadata_spec_version": "0.1.0",
            "timestamp": "2020-07-13T05:46:45Z",
            "type": "root",
            "version": 1
          }
        }
    r   r   )rC   metadata_spec_versionr   
expirationzExpected a "z)" entry in the given delegating metadata.rC   zGiven type entry ("z<") is not one of the supported types of delegating metadata.r   r   r   	timestampversionzMAll metadata must include a "version" entry, or a "timestamp" entry, or both.r   z.Root metadata must specify its version number.N)	r   checkformat_any_signaturerq   r   r   #SUPPORTED_DELEGATING_METADATA_TYPESr   r   r   )r1   r   contentsentrys       r   checkformat_delegating_metadatar     s   B """l# = =!(<"8";<<<<!H 
 
   U+ /' '   ! x'(((BBB!HV$44 8A A
 
 	

 x 78999
 H]3444h|4555 (""y'@'@*
 
 	

 6!!ix&?&?IJJJ 88888h!(;"7888H 344444 r   Signature | GPGSignaturec                `    t          |           st          |           st          d          | S )NzExpected either a hex string representing a raw ed25519 signature (see checkformat_signature) or a dictionary representing an OpenPGP/GPG signature (see checkformat_gpg_signature).)r   r   rq   r   s    r   r   r   E  sA    	"" 
+;I+F+F 
/
 
 	
 r   c                   t          | dz   d          5 }|                                }ddd           n# 1 swxY w Y   t          | dz   d          5 }|                                }ddd           n# 1 swxY w Y   ||fS )aZ  
    Toy function.  Import an ed25519 key pair, in the forms of raw public and
    raw private keys, from name.pub and name.pri respectively.

    Cavalier about private key bytes.
    Does not perform input validation ('/'...).

    Return the 32 bytes of the private key object and the 32 bytes of the
    public key object, in that order.
    z.prir-   Nz.pub)r.   read)namer0   rV   rh   s       r   keyfiles_to_bytesr   Q  s     
dVmT	"	" $d		$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
dVmT	"	" #dyy{{# # # # # # # # # # # # # # # ,&&s   599A44A8;A8c                    t          |           \  }}t                              |          }t                              |          }||fS )a$  
    Doesn't perform input validation.
    Import an ed25519 key pair, in the forms of raw public key
    bytes and raw private key bytes, from name.pub and name.pri respectively.
    Cavalier about private key bytes.
    Return a private key object and public key object, in that order.
    )r   rQ   rJ   rf   )r   rV   rh   privatepublics        r   keyfiles_to_keysr   e  sF     #4D"9"9M<##M22G!!,//FF?r   r?   4ed25519.Ed25519PublicKey | ed25519.Ed25519PrivateKeyc                    t          | t          j        t          j        f          s/t	          dt          t          |                     z   dz             | S )z
    Enforces expectation that argument is an object of type
    cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey or
    cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey.
    zsExpected an Ed25519PublicKey or Ed25519PrivateKey object from the "cryptography" library.  Received object of type r   )r   r   Ed25519PublicKeyEd25519PrivateKeyr'   r   rC   )r?   s    r   rB   rB   u  s^     cG4g6OPQQ 
I$s))nn 
 
 	
 Jr   c                    t          |            t          j                                        d          | z   }|                                dz   S )a  
    Applies a datetime.timedelta to the current time in UTC with microseconds
    stripped, then converts to ISO8601 format and appends a 'Z' indicating that
    it is UTC time, not local time.  We only deal with UTC times!

    This is used for two purposes:
     - get current time in ISO8601 format, by passing in a 0 timedelta
     - get ISO8601 UTC timestamp for expiration dates

    regex for time: '^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$'
    r   )microsecondZ)r   r   utcnowreplace	isoformat)deltaunix_expirys     r   iso8601_time_plus_deltar     sL     $E***/##+++::UBK  ""S((r   )rl   r
   rm   rn   )rl   r
   rm   ru   )r|   r
   rm   rn   )r   r
   rm   rn   )r   r
   rm   rn   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   rn   )r   r
   rm   r   )r   r
   rm   rn   )r   r
   rm   r   )r   r
   rm   rn   )r   r
   rm   r   )r   r
   rm   r   )r   r
   rm   r   )r1   r
   rm   r   )r   r
   rm   r   )r?   r
   rm   r   )Nr   
__future__r   binasciir   r   r   r   jsonr   r	   typingr
   r   cryptography.hazmat.primitivesr   )cryptography.hazmat.primitives.asymmetricr   SECURITY_METADATA_SPEC_VERSIONr   r   tupler   r   floatrn   rC   r   r   	Exceptionr   r   r   r!   r+   r2   r7   r9   r   rQ   r   rf   rs   ru   rp   r   r   r   r   r   r   r]   r   r   r   r   rI   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   r   r   r   r   <module>r     s  , ,Z # " " " " " ' ' ' ' ' ' ' ' ( ( ( ( ( ( ( (                         8 8 8 8 8 8 = = = = = = ") 
 !%dE3UD$$t**U  (.y&9 #    	       Y       	       y   ' ' '6	 	 	          D$> $> $> $> $>74 $> $> $>N!= != != != !='2 != != !=\	 	 	 	 	               
          
             
      *   	 	 	 	    6    0 0 0 0f    	5
 5
 5
 5
p 
$ $ $ $N   2  t5 t5 t5 t5r	 	 	 	' ' '(      ") ) ) ) )r   