
    >wg                        d Z ddlmZmZmZmZ ddlZddlZddlm	Z	m
Z
 ddlmZmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# dd	l$m%Z%m&Z&  G d
 de!      Z' G d de"      Z( G d de      Z) G d de!      Z* G d de!      Z+ G d de!      Z, G d d      Z- G d dee-      Z. G d dee-      Z/ G d de      Z0 G d de      Z1 G d  d!e      Z2 G d" d#e!      Z3 G d$ d%e!      Z4 G d& d'e!      Z5 G d( d)e!      Z6 G d* d+e!      Z7 G d, d-e      Z8 G d. d/e      Z9 G d0 d1e      Z: G d2 d3e!      Z; G d4 d5e!      Z< G d6 d7e!      Z= G d8 d9e#      Z> G d: d;e      Z? G d< d=ee!      Z@ G d> d?e!      ZA G d@ dAe!      ZB G dB dCe!      ZC G dD dEe!      ZD G dF dGe      ZE G dH dIee!      ZF G dJ dKe!      ZGy)La'  
ASN.1 type classes for public and private keys. Exports the following items:

 - DSAPrivateKey()
 - ECPrivateKey()
 - EncryptedPrivateKeyInfo()
 - PrivateKeyInfo()
 - PublicKeyInfo()
 - RSAPrivateKey()
 - RSAPublicKey()

Other type classes are defined that help compose the types listed above.
    )unicode_literalsdivisionabsolute_importprint_functionN   )unwrapAPIException)	type_namebyte_cls)_ForceNullParametersDigestAlgorithmEncryptionAlgorithmRSAESOAEPParamsRSASSAPSSParams)Any	Asn1Value	BitStringChoiceIntegerIntegerOctetStringNullObjectIdentifierOctetBitStringOctetStringParsableOctetStringParsableOctetBitStringSequence
SequenceOfSetOf)int_from_bytesint_to_bytesc                   &    e Zd ZdZdefdefdefgZy)OtherPrimeInfo=
    Source: https://tools.ietf.org/html/rfc3447#page-46
    primeexponentcoefficientN__name__
__module____qualname____doc__r   _fields     F/var/www/horilla/myenv/lib/python3.12/site-packages/asn1crypto/keys.pyr#   r#   -   s(    
 
'	W	 Gr/   r#   c                       e Zd ZdZeZy)OtherPrimeInfosr$   N)r)   r*   r+   r,   r#   _child_specr.   r/   r0   r2   r2   9   s     !Kr/   r2   c                       e Zd ZdZdddZy)RSAPrivateKeyVersionzX
    Original Name: Version
    Source: https://tools.ietf.org/html/rfc3447#page-45
    z	two-primemulti)r   r   Nr)   r*   r+   r,   _mapr.   r/   r0   r5   r5   A   s     Dr/   r5   c                   V    e Zd ZdZdefdefdefdefdefdefdefd	efd
efdeddifg
Zy)RSAPrivateKeyz=
    Source: https://tools.ietf.org/html/rfc3447#page-45
    versionmoduluspublic_exponentprivate_exponentprime1prime2	exponent1	exponent2r'   other_prime_infosoptionalTN)r)   r*   r+   r,   r5   r   r2   r-   r.   r/   r0   r:   r:   M   sh    
 
()	G	G$	W%	7	7	g	g	 	o
D/ABGr/   r:   c                        e Zd ZdZdefdefgZy)RSAPublicKeyz=
    Source: https://tools.ietf.org/html/rfc3447#page-44
    r<   r=   Nr(   r.   r/   r0   rF   rF   `   s     
 
G	G$Gr/   rF   c                   8    e Zd ZdZdefdefdefdefdefdefgZy)	DSAPrivateKeya&  
    The ASN.1 structure that OpenSSL uses to store a DSA private key that is
    not part of a PKCS#8 structure. Reversed engineered from english-language
    description on linked OpenSSL documentation page.

    Original Name: None
    Source: https://www.openssl.org/docs/apps/dsa.html
    r;   pqg
public_keyprivate_keyNr(   r.   r/   r0   rH   rH   k   s=     
G	g	g	g	w	 Gr/   rH   c                   &    e Zd ZdZed        Zd Zy)_ECPointa
  
    In both PublicKeyInfo and PrivateKeyInfo, the EC public key is a byte
    string that is encoded as a bit string. This class adds convenience
    methods for converting to and from the byte string to a pair of integers
    that are the X and Y coordinates.
    c                 B   t        t        j                  t        j                  |d      dz              }t        t        j                  t        j                  |d      dz              }t	        ||      }d}|t        ||      z  }|t        ||      z  } | |      S )a  
        Creates an ECPoint object from the X and Y integer coordinates of the
        point

        :param x:
            The X coordinate, as an integer

        :param y:
            The Y coordinate, as an integer

        :return:
            An ECPoint object
                  @   )width)intmathceillogmaxr!   )clsxyx_bytesy_bytes	num_bytesbyte_strings          r0   from_coordsz_ECPoint.from_coords   s      diiA 456diiA 456)	|AY77|AY77;r/   c                    | j                   }|dd }|dk(  r3|dd }t        |      dz  }t        |d|       }t        ||d       }||fS |t        ddg      vrt	        t        d            t	        t        d	            )
z
        Returns the X and Y coordinates for this EC point, as native Python
        integers

        :return:
            A 2-element tuple containing integers (X, Y)
        r   r   rS   NrQ         zQ
                Invalid EC public key - first byte is incorrect
                z|
            Compressed representations of EC public keys are not supported due
            to patent US6252960
            )nativelenr    set
ValueErrorr   )selfdata
first_byte	remaining	field_lenr[   r\   s          r0   	to_coordsz_ECPoint.to_coords   s     {{!AY
  QRII!+Iy956Ay45Aq6MS'7!344V   
  	r/   N)r)   r*   r+   r,   classmethodra   rn   r.   r/   r0   rO   rO      s         4 r/   rO   c                       e Zd Zy)ECPointNr)   r*   r+   r.   r/   r0   rq   rq          r/   rq   c                       e Zd Zy)ECPointBitStringNrr   r.   r/   r0   ru   ru      rs   r/   ru   c                       e Zd ZdZddddZy)SpecifiedECDomainVersion:
    Source: http://www.secg.org/sec1-v2.pdf page 104
    ecdpVer1ecdpVer2ecdpVer3)r   rQ      Nr7   r.   r/   r0   rw   rw      s     Dr/   rw   c                       e Zd ZdZdddZy)	FieldTypezR
    Original Name: None
    Source: http://www.secg.org/sec1-v2.pdf page 101
    prime_fieldcharacteristic_two_field)z1.2.840.10045.1.1z1.2.840.10045.1.2Nr7   r.   r/   r0   r~   r~      s     +7Dr/   r~   c                       e Zd ZdZddddZy)CharacteristicTwoBasiszR
    Original Name: None
    Source: http://www.secg.org/sec1-v2.pdf page 102
    gn_basistp_basispp_basis)z1.2.840.10045.1.2.1.1z1.2.840.10045.1.2.1.2z1.2.840.10045.1.2.1.3Nr7   r.   r/   r0   r   r      s     ",!+!+Dr/   r   c                   &    e Zd ZdZdefdefdefgZy)Pentanomial:
    Source: http://www.secg.org/sec1-v2.pdf page 102
    k1k2k3Nr(   r.   r/   r0   r   r      s%    
 
w	w	wGr/   r   c                   6    e Zd ZdZdefdefdefgZdZe	ee
dZy)CharacteristicTwoz`
    Original Name: Characteristic-two
    Source: http://www.secg.org/sec1-v2.pdf page 101
    mbasis
parameters)r   r   )r   r   r   N)r)   r*   r+   r,   r   r   r   r-   	_oid_pairr   r   
_oid_specsr.   r/   r0   r   r      s?     
g	()	sG (IJr/   r   c                   .    e Zd ZdZdefdefgZdZee	dZ
y)FieldIDz:
    Source: http://www.secg.org/sec1-v2.pdf page 100
    
field_typer   )r   r   )r   r   N)r)   r*   r+   r,   r~   r   r-   r   r   r   r   r.   r/   r0   r   r     s4    
 
y!	sG
 -I$5Jr/   r   c                   ,    e Zd ZdZdefdefdeddifgZy)Curverx   abseedrD   TN)r)   r*   r+   r,   r   r   r-   r.   r/   r0   r   r   $  s/    
 
k	k	*d!34Gr/   r   c            
       J    e Zd ZdZdefdefdefdefdefdedd	ifd
e	dd	ifgZ
y)SpecifiedECDomainz:
    Source: http://www.secg.org/sec1-v2.pdf page 103
    r;   field_idcurvebaseordercofactorrD   ThashN)r)   r*   r+   r,   rw   r   r   rq   r   r   r-   r.   r/   r0   r   r   0  sW    
 
,-	W	%		'	Wz401	:t"45Gr/   r   c                      e Zd ZdZi dddddddd	d
dddddddddddddddddddddd d!d"d#i d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEi dFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgi dhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddZi ddddddddd
dddddddddddddddddddddd dd"di d$dd&dd(dd*dd,dd.dd0dd2dd4dd6dd8dd:dd<dd>dd@ddBddDdi dFddHddJddLddNddPddRddTddVddXddZdd\dd^dd`ddbdddddfdi dhddjddlddnddpddrddtddvddxddzdd|dd~ddddddddddddddddZed        Zy)
NamedCurvez
    Various named curves

    Original Name: None
    Source: https://tools.ietf.org/html/rfc3279#page-23,
            https://tools.ietf.org/html/rfc5480#page-5
    z1.2.840.10045.3.0.1
c2pnb163v1z1.2.840.10045.3.0.2
c2pnb163v2z1.2.840.10045.3.0.3
c2pnb163v3z1.2.840.10045.3.0.4
c2pnb176w1z1.2.840.10045.3.0.5
c2tnb191v1z1.2.840.10045.3.0.6
c2tnb191v2z1.2.840.10045.3.0.7
c2tnb191v3z1.2.840.10045.3.0.8
c2onb191v4z1.2.840.10045.3.0.9
c2onb191v5z1.2.840.10045.3.0.10
c2pnb208w1z1.2.840.10045.3.0.11
c2tnb239v1z1.2.840.10045.3.0.12
c2tnb239v2z1.2.840.10045.3.0.13
c2tnb239v3z1.2.840.10045.3.0.14
c2onb239v4z1.2.840.10045.3.0.15
c2onb239v5z1.2.840.10045.3.0.16
c2pnb272w1z1.2.840.10045.3.0.17
c2pnb304w1z1.2.840.10045.3.0.18
c2tnb359v1z1.2.840.10045.3.0.19
c2pnb368w1z1.2.840.10045.3.0.20
c2tnb431r1z1.2.840.10045.3.1.2
prime192v2z1.2.840.10045.3.1.3
prime192v3z1.2.840.10045.3.1.4
prime239v1z1.2.840.10045.3.1.5
prime239v2z1.2.840.10045.3.1.6
prime239v3z1.2.840.10045.3.1.1	secp192r1z1.2.840.10045.3.1.7	secp256r1z1.3.132.0.1	sect163k1z1.3.132.0.2	sect163r1z1.3.132.0.3	sect239k1z1.3.132.0.4	sect113r1z1.3.132.0.5	sect113r2z1.3.132.0.6	secp112r1z1.3.132.0.7	secp112r2z1.3.132.0.8	secp160r1z1.3.132.0.9	secp160k1z1.3.132.0.10	secp256k1z1.3.132.0.15	sect163r2z1.3.132.0.16	sect283k1z1.3.132.0.17	sect283r1z1.3.132.0.22	sect131r1z1.3.132.0.23	sect131r2z1.3.132.0.24	sect193r1z1.3.132.0.25	sect193r2z1.3.132.0.26	sect233k1z1.3.132.0.27	sect233r1z1.3.132.0.28	secp128r1z1.3.132.0.29	secp128r2z1.3.132.0.30	secp160r2z1.3.132.0.31	secp192k1z1.3.132.0.32	secp224k1z1.3.132.0.33	secp224r1z1.3.132.0.34	secp384r1z1.3.132.0.35	secp521r1z1.3.132.0.36	sect409k1z1.3.132.0.37	sect409r1z1.3.132.0.38	sect571k1z1.3.132.0.39	sect571r1z1.3.36.3.3.2.8.1.1.1brainpoolp160r1z1.3.36.3.3.2.8.1.1.2brainpoolp160t1z1.3.36.3.3.2.8.1.1.3brainpoolp192r1z1.3.36.3.3.2.8.1.1.4brainpoolp192t1z1.3.36.3.3.2.8.1.1.5brainpoolp224r1z1.3.36.3.3.2.8.1.1.6brainpoolp224t1z1.3.36.3.3.2.8.1.1.7brainpoolp256r1z1.3.36.3.3.2.8.1.1.8brainpoolp256t1z1.3.36.3.3.2.8.1.1.9brainpoolp320r1z1.3.36.3.3.2.8.1.1.10brainpoolp320t1brainpoolp384r1brainpoolp384t1brainpoolp512r1brainpoolp512t1)z1.3.36.3.3.2.8.1.1.11z1.3.36.3.3.2.8.1.1.12z1.3.36.3.3.2.8.1.1.13z1.3.36.3.3.2.8.1.1.14            !   %   -   5             $               0   B   3   4   H      (   @   c                 v    || j                   |<   | j                  || j                  |<   || j                  |<   y)a  
        Registers a new named elliptic curve that is not included in the
        default list of named curves

        :param name:
            A unicode string of the curve name

        :param oid:
            A unicode string of the dotted format OID

        :param key_size:
            An integer of the number of bytes the private key should be
            encoded to
        N)r8   _reverse_map
_key_sizes)rZ   nameoidkey_sizes       r0   registerzNamedCurve.register  s;    " '%(CT"&sr/   N)r)   r*   r+   r,   r8   r  ro   r  r.   r/   r0   r   r   @  s   M|M 	|M 	|	M
 	|M 	|M 	|M 	|M 	|M 	|M 	M 	M 	M 	M 	M  	!M" 	#M$ 	%M& 	'M( 	)M* 	+M, 	|-M. 	|/M0 	|1M2 	|3M4 	|5M: 	{;M< 	{=M> 	{?M@ 	{AMB 	{CMD 	{EMF 	{GMH 	{IMJ 	{KML 	{MMN 	{OMP 	QMR 	SMT 	UMV 	WMX 	YMZ 	[M\ 	]M^ 	_M` 	aMb 	cMd 	eMf 	gMh 	iMj 	kMl 	mMn 	oMp 	qMr 	sMt 	uMv 	wMx 	yMz 	{M~ 	 1M@ 	 1AMB 	 1CMD 	 1EMF 	 1GMH 	 1IMJ 	 1KML 	 1MMN 	 1OMP 	 !2QMR "3!2!2!2YMD^Q 	rQ 	r	Q
 	rQ 	rQ 	rQ 	rQ 	rQ 	rQ 	rQ 	Q 	Q 	Q 	Q  	!Q" 	#Q$ 	%Q& 	'Q( 	)Q* 	+Q, 	-Q. 	r/Q0 	r1Q2 	r3Q4 	r5Q6 	r7Q> 	r?Q@ 	rAQB 	rCQD 	rEQF 	rGQH 	rIQJ 	rKQL 	rMQN 	rOQP 	rQQR 	rSQT 	UQV 	WQX 	YQZ 	[Q\ 	]Q^ 	_Q` 	aQb 	cQd 	eQf 	gQh 	iQj 	kQl 	mQn 	oQp 	qQr 	sQt 	uQv 	wQx 	yQz 	{Q| 	}Q~ 	QF 	GQH 	IQJ 	KQL 	MQN 	OQP 	QQR 	SQT 	UQV 	WQX 	 YQZ "$!#!#!#aQJf ' 'r/   r   c                   6    e Zd ZdZdefdefdefgZed        Z	y)ECDomainParametersr   	specifiednamedimplicit_cac                    | j                   dk(  rt        t        d            | j                   dk(  rE| j                  d   j                  }t        j                  t        j                  |d      dz        S | j                  j                  }|t        j                  vrt        t        dt        |                  t        j                  |   S )Nr  z
                Unable to calculate key_size from ECDomainParameters
                that are implicitly defined by the CA key
                r  r   g       @rR   z
                The asn1crypto.keys.NamedCurve %s does not have a registered key length,
                please call asn1crypto.keys.NamedCurve.register()
                )r  rh   r   chosenre   rV   rW   rX   dottedr   r  repr)ri   r   r	  s      r0   r
  zECDomainParameters.key_size  s    99%V   99#KK(//E99TXXeS1C788kk  j+++V S	   $$S))r/   N)
r)   r*   r+   r,   r   r   r   _alternativespropertyr
  r.   r/   r0   r  r    s=    
 
'(	*	M * *r/   r  c                       e Zd ZdZddiZy)ECPrivateKeyVersionzR
    Original Name: None
    Source: http://www.secg.org/sec1-v2.pdf page 108
    r   ecPrivkeyVer1Nr7   r.   r/   r0   r  r  '  s     	
?Dr/   r  c                   ^     e Zd ZdZdefdefdedddfded	ddfgZd
Z	 fdZ
d Zd Z xZS )ECPrivateKeyz:
    Source: http://www.secg.org/sec1-v2.pdf page 108
    r;   rM   r   r   T)explicitrD   rL   r   Nc                    t         t        |   ||      }|dk(  r| j                  V| d   j                  }t        |t              rSt        |      dkD  rE| j                  t        | d   j                               |S | j                  | j                          |S |dk(  rCt        | d   t              r0| d   j                  dk7  r| j                  | d   j                         |S )NrM   r   r   r  )superr  __setitem__	_key_sizecontents
isinstancer   rf   set_key_size_update_key_sizer  r  r
  )ri   keyvaluerespkey_contents	__class__s        r0   r  zECPrivateKey.__setitem__B  s    L$3C?-~~% $] 3 < <mX63};MPQ;Q%%c$}*=*F*F&GH 
 +%%' 
	 L Z\0BDV%W\"''=8d<099:
r/   c                 2    || _         | j                          y)z
        Sets the key_size to ensure the private key is encoded to the proper length

        :param key_size:
            An integer byte length to encode the private_key to
        N)r   r$  )ri   r
  s     r0   r#  zECPrivateKey.set_key_sizeU  s     "r/   c                     | j                   3t        | d   t              r| d   j                  | j                          yyy)zG
        Ensure the private_key explicit encoding width is set
        NrM   )r   r"  r   set_encoded_widthri   s    r0   r$  zECPrivateKey._update_key_size`  s=    
 >>%*T-5HJ\*]11$..A +^%r/   )r)   r*   r+   r,   r  r   r  ru   r-   r   r  r#  r$  __classcell__r)  s   @r0   r  r  2  sZ    
 
'(	*+	)t+LM	'aT)JK	G I&	 Br/   r  c                   &    e Zd ZdZdefdefdefgZy)	DSAParamsz
    Parameters for a DSA public or private key

    Original Name: Dss-Parms
    Source: https://tools.ietf.org/html/rfc3279#page-9
    rI   rJ   rK   Nr(   r.   r/   r0   r1  r1  i  s%     
g	g	gGr/   r1  c                   &    e Zd ZdZdefdedeifgZy)	Attributezq
    Source: https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-X.501-198811-S!!PDF-E&type=items page 8
    typevaluesspecN)r)   r*   r+   r,   r   r   r   r-   r.   r/   r0   r3  r3  x  s'    
 
!"	563-(Gr/   r3  c                       e Zd ZdZeZy)
Attributes<
    Source: https://tools.ietf.org/html/rfc5208#page-3
    N)r)   r*   r+   r,   r3  r3   r.   r/   r0   r8  r8    s     Kr/   r8  c            	       &    e Zd ZdZdddddddd	d
Zy)PrivateKeyAlgorithmIdz
    These OIDs for various public keys are reused when storing private keys
    inside of a PKCS#8 structure

    Original Name: None
    Source: https://tools.ietf.org/html/rfc3279
    rsa
rsassa_pssdsaecx25519x448ed25519ed448)1.2.840.113549.1.1.11.2.840.113549.1.1.101.2.840.10040.4.11.2.840.10045.2.11.3.101.1101.3.101.1111.3.101.1121.3.101.113Nr7   r.   r/   r0   r;  r;    s(     !&!-"! Dr/   r;  c                   6    e Zd ZdZdefdeddifgZdZee	e
dZy)	PrivateKeyAlgorithmzm
    Original Name: PrivateKeyAlgorithmIdentifier
    Source: https://tools.ietf.org/html/rfc5208#page-3
    	algorithmr   rD   TrN  r   )r>  r?  r=  N)r)   r*   r+   r,   r;  r   r-   r   r1  r  r   r   r.   r/   r0   rM  rM    s?     
+,	sZ./G
 ,I %Jr/   rM  c                        e Zd ZdZdefdefdefdedddfgZd	 Z	de	iZ
d
Zd
Zd
Zd
Zed        Z fdZd Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z xZS )PrivateKeyInfor9  r;   private_key_algorithmrM   
attributesr   T)implicitrD   c           	          | d   d   j                   }t        t        t        t        t        t        t        t        d|   S )NrR  rN  )r<  r=  r>  r?  r@  rA  rB  rC  )re   r:   r   r  r   ri   rN  s     r0   _private_key_specz PrivateKeyInfo._private_key_spec  sF    01+>EE	 ' "" 
  	r/   Nc                    t        |t              s.t        |t              st        t	        dt        |                  |dk(  s|dk(  r0t        |t              st        j                  |      }t               }n|dk(  rRt        |t              st        j                  |      }t               }|d   |d<   |d   |d<   |d   |d<   |d   }|d	   }nb|d
k(  r?t        |t              st        j                  |      }n|j                         }|d   }|d= nt        t	        dt        |                  t               }t!        |      |d<   ||d<    |        }||_        t%        d      |d<   ||d<   ||d	<   |dk(  r|_        |S )a'  
        Wraps a private key in a PrivateKeyInfo structure

        :param private_key:
            A byte string or Asn1Value object of the private key

        :param algorithm:
            A unicode string of "rsa", "dsa" or "ec"

        :return:
            A PrivateKeyInfo object
        zX
                private_key must be a byte string or Asn1Value, not %s
                r<  r=  r>  rI   rJ   rK   rL   rM   r?  r   zU
                algorithm must be one of "rsa", "dsa", "ec", not %s
                rN  r   r;   rR  )r"  r   r   	TypeErrorr   r
   r:   loadr   rH   r1  r  copyrh   r  rM  r;  
_algorithmr   _public_key)rZ   rM   rN  paramsrL   private_key_algo	containers          r0   wrapzPrivateKeyInfo.wrap  s    +x0KQZ9[F +&	   l!:k=9+00=VF%k=9+00=[F%c*F3K%c*F3K%c*F3K$\2J%m4K$k<8*//<)..0 .FL)V Y	   /0(=i(H%)/&E	(	&qz	)-=	)*#.	-  $.I!r/   c                 r   t         t        |   ||      }| d   }|dk(  s|dk(  r|d   j                  dk(  rt	        |d   t
              rm|d   j                  dk7  r[t	        | d   t              rHt	        | d   j                  t              r+| d   j                  j                  |d   j                         |S )NrR  rM   rN  r?  r   r  )r  rQ  r  re   r"  r  r  r   parsedr  r#  r
  )ri   r%  r&  r'  rN  r)  s        r0   r  zPrivateKeyInfo.__setitem__"  s    ND5c5A01	 **c].B+&--59\24FG,',,=4.0CD4.55|D&&33Il4K4T4TU
r/   c                     t        d      )z
        Unwraps the private key into an RSAPrivateKey, DSAPrivateKey or
        ECPrivateKey object

        :return:
            An RSAPrivateKey, DSAPrivateKey or ECPrivateKey object
        zxasn1crypto.keys.PrivateKeyInfo().unwrap() has been removed, please use oscrypto.asymmetric.PrivateKey().unwrap() insteadr	   r-  s    r0   r   zPrivateKeyInfo.unwrap3  s     KL 	Lr/   c                     | j                   dk7  r-t        t        d| j                   j                                     | d   d   }|j                  }|j
                  dk(  rd}n|j                  }|j
                  |fS )#  
        Returns information about the curve used for an EC key

        :raises:
            ValueError - when the key is not an EC key

        :return:
            A two-element tuple, with the first element being a unicode string
            of "implicit_ca", "specified" or "named". If the first element is
            "implicit_ca", the second is None. If "specified", the second is
            an OrderedDict that is the native version of SpecifiedECDomain. If
            "named", the second is a unicode string of the curve name.
        r?  K
                Only EC keys have a curve, this key is %s
                rR  r   r  NrN  rh   r   upperr  r  re   ri   r^  r  r&  s       r0   r   zPrivateKeyInfo.curve@  s      >>T!V $$&	   -.|<;;-'EMMEU##r/   c                     | j                   dk7  r-t        t        d| j                   j                                     t	        j
                  | d   d   d   j                  d      dz  }|dk  rd	S d
S )z
        Returns the name of the family of hash algorithms used to generate a
        DSA key

        :raises:
            ValueError - when the key is not a DSA key

        :return:
            A unicode string of "sha1" or "sha2"
        r>  t
                Only DSA keys are generated using a hash algorithm, this key is
                %s
                rR  r   rJ   rQ      r  sha1sha2)rN  rh   r   rj  rV   rX   re   )ri   byte_lens     r0   	hash_algozPrivateKeyInfo.hash_algob  s{     >>U"V $$&   88D!89,GLSSUVWZ[[!Rv3V3r/   c                 `    | j                   | d   d   j                  | _         | j                   S )]
        :return:
            A unicode string of "rsa", "rsassa_pss", "dsa" or "ec"
        rR  rN  r\  re   r-  s    r0   rN  zPrivateKeyInfo.algorithm|  s0     ??""#:;KHOODOr/   c                    | j                   | j                  dk(  s| j                  dk(  r| d   j                  d   j                  }nP| j                  dk(  r| d   d   d   j                  }n+| j                  d	k(  r| d   j                  d   j                  }t	        t        j                  t        j                  d
                  | _         | j                   dz  }|dk7  r| xj                   d|z
  z  c_         | j                   S )zU
        :return:
            The bit size of the private key, as an integer
        r<  r=  rM   r<   r>  rR  r   rI   r?  rQ   rn  r   )	_bit_sizerN  rc  re   rU   rV   rW   rX   ri   r%   r<   s      r0   bit_sizezPrivateKeyInfo.bit_size  s     >>!~~&$..L*H]+229=DD5(45lCCHOO4']+22=AHH 488E1+=!>?DNnnq(G!|!g+-~~r/   c                 X    t        t        j                  | j                  dz              S )zV
        :return:
            The byte size of the private key, as an integer
        rn  rU   rV   rW   ry  r-  s    r0   	byte_sizezPrivateKeyInfo.byte_size  !     499T]]Q./00r/   c                     t        d      )z
        :return:
            If an RSA key, an RSAPublicKey object. If a DSA key, an Integer
            object. If an EC key, an ECPointBitString object.
        zasn1crypto.keys.PrivateKeyInfo().public_key has been removed, please use oscrypto.asymmetric.PrivateKey().public_key.unwrap() insteadre  r-  s    r0   rL   zPrivateKeyInfo.public_key  s     VW 	Wr/   c                     t        d      )z\
        :return:
            A PublicKeyInfo object derived from this private key.
        zasn1crypto.keys.PrivateKeyInfo().public_key_info has been removed, please use oscrypto.asymmetric.PrivateKey().public_key.asn1 insteadre  r-  s    r0   public_key_infozPrivateKeyInfo.public_key_info  s     RS 	Sr/   c                     t        d      )aY  
        Creates a fingerprint that can be compared with a public key to see if
        the two form a pair.

        This fingerprint is not compatible with fingerprints generated by any
        other software.

        :return:
            A byte string that is a sha256 hash of selected components (based
            on the key type)
        z~asn1crypto.keys.PrivateKeyInfo().fingerprint has been removed, please use oscrypto.asymmetric.PrivateKey().fingerprint insteadre  r-  s    r0   fingerprintzPrivateKeyInfo.fingerprint  s     NO 	Or/   )r)   r*   r+   r,   r   rM  r   r8  r-   rW  _spec_callbacksr\  rw  r]  _fingerprintro   ra  r  r   r  r   rr  rN  ry  r|  rL   r  r  r.  r/  s   @r0   rQ  rQ    s+   
 
G	 "56	+,	zt#DE	G  	(O JIKLA AJ"L $ $B 4 42    & 1 1 	W 	W S S O Or/   rQ  c                        e Zd ZdZdefdefgZy)EncryptedPrivateKeyInfoz<
    Source: https://tools.ietf.org/html/rfc5208#page-4
    encryption_algorithmencrypted_dataN)r)   r*   r+   r,   r   r   r-   r.   r/   r0   r  r    s!    
 
 !45	;'Gr/   r  c                        e Zd ZdZdefdefgZy)ValidationParms=
    Source: https://tools.ietf.org/html/rfc3279#page-10
    r   pgen_counterN)r)   r*   r+   r,   r   r   r-   r.   r/   r0   r  r    s     
 
	!Gr/   r  c                   >    e Zd ZdZdefdefdefdeddifdeddifgZy	)
DomainParametersr  rI   rK   rJ   jrD   Tvalidation_paramsN)r)   r*   r+   r,   r   r  r-   r.   r/   r0   r  r    sC    
 
g	g	g	g
D)*	o
D/ABGr/   r  c                   *    e Zd ZdZdddddddd	d
dd
Zy)PublicKeyAlgorithmIdzM
    Original Name: None
    Source: https://tools.ietf.org/html/rfc3279
    r<  
rsaes_oaepr=  r>  r?  dhr@  rA  rB  rC  )
rD  z1.2.840.113549.1.1.7rE  rF  rG  z1.2.840.10046.2.1rH  rI  rJ  rK  Nr7   r.   r/   r0   r  r    s.     !& ,!-"!! #Dr/   r  c                   :    e Zd ZdZdefdeddifgZdZee	e
eedZy)	PublicKeyAlgorithmzd
    Original Name: AlgorithmIdentifier
    Source: https://tools.ietf.org/html/rfc5280#page-18
    rN  r   rD   TrO  )r>  r?  r  r  r=  N)r)   r*   r+   r,   r  r   r-   r   r1  r  r  r   r   r   r.   r/   r0   r  r    sE     
*+	sZ./G
 ,I %%Jr/   r  c                       e Zd ZdZdefdefgZd ZdeiZdZ	dZ
dZdZdZed        Zd Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zy)PublicKeyInfoze
    Original Name: SubjectPublicKeyInfo
    Source: https://tools.ietf.org/html/rfc5280#page-17
    rN  rL   c                     | d   d   j                   }t        t        t        t        t        d ft        t        d ft        d ft        d ft        d fd
|   S )NrN  )
r<  r  r=  r>  r?  r  r@  rA  rB  rC  )re   rF   r   ru   r   rV  s     r0   _public_key_speczPublicKeyInfo._public_key_spec/  sf    %k299	&& $T* &t,#T*&-$d+
  	r/   Nc                    t        |t              s.t        |t              st        t	        dt        |                  |dk7  r#|dk7  rt        t	        dt        |                  t               }t        |      |d<   t               |d<    |        }||d<   t        |t              r|j                         j                         }t        |      |d<   |S )a  
        Wraps a public key in a PublicKeyInfo structure

        :param public_key:
            A byte string or Asn1Value object of the public key

        :param algorithm:
            A unicode string of "rsa"

        :return:
            A PublicKeyInfo object
        zW
                public_key must be a byte string or Asn1Value, not %s
                r<  r=  z>
                algorithm must "rsa", not %s
                rN  r   rL   )r"  r   r   rY  r   r
   rh   r  r  r  r   untagdumpr   )rZ   rL   rN  algor`  s        r0   ra  zPublicKeyInfo.wrapL  s     *h/
:y8YF *%	   )|";V Y	   "#0;[!V\E	!%	+j),#))+002J"8"D	,r/   c                     t        d      )z
        Unwraps an RSA public key into an RSAPublicKey object. Does not support
        DSA or EC public keys since they do not have an unwrapped form.

        :return:
            An RSAPublicKey object
        zvasn1crypto.keys.PublicKeyInfo().unwrap() has been removed, please use oscrypto.asymmetric.PublicKey().unwrap() insteadre  r-  s    r0   r   zPublicKeyInfo.unwrapw  s     JK 	Kr/   c                     | j                   dk7  r-t        t        d| j                   j                                     | d   d   }|j                  }|j
                  dk(  rd}n|j                  }|j
                  |fS )rg  r?  rh  rN  r   r  Nri  rk  s       r0   r   zPublicKeyInfo.curve  s~      >>T!V $$&	   k"<0;;-'EMMEU##r/   c                    | j                   dk7  r-t        t        d| j                   j                                     | d   d   }|j                  yt        j                  |d   j                  d      dz  }|d	k  rd
S dS )a#  
        Returns the name of the family of hash algorithms used to generate a
        DSA key

        :raises:
            ValueError - when the key is not a DSA key

        :return:
            A unicode string of "sha1" or "sha2" or None if no parameters are
            present
        r>  rm  rN  r   NrJ   rQ   rn  r  ro  rp  )rN  rh   r   rj  re   rV   rX   )ri   r   rq  s      r0   rr  zPublicKeyInfo.hash_algo  s     >>U"V $$&   +&|4
$88JsO22A6:!Rv3V3r/   c                 `    | j                   | d   d   j                  | _         | j                   S )rt  rN  ru  r-  s    r0   rN  zPublicKeyInfo.algorithm  s/     ??"";/<CCDOr/   c                 L   | j                   | j                  dk(  r;t        t        | d   j                        dz
  dz  dz        | _         | j                   S | j                  dk(  s| j                  dk(  r| d   j
                  d   j                  }n$| j                  d	k(  r| d
   d   d   j                  }t        t        j                  t        j                  d                  | _         | j                   dz  }|dk7  r| xj                   d|z
  z  c_         | j                   S )zT
        :return:
            The bit size of the public key, as an integer
        r?  rL   r   rQ   rn  r<  r=  r<   r>  rN  r   rI   r   )	rw  rN  rU   rf   re   rc  rV   rW   rX   rx  s      r0   ry  zPublicKeyInfo.bit_size  s     >>!~~%!$s4+=+D+D'E'IQ&NRS%S!T ~~ >>U*dnn.L .55i@GGE^^u, -l;C@GGE!$TYYtxxq/A%B!C..1,a<NNa'k1N~~r/   c                 X    t        t        j                  | j                  dz              S )zU
        :return:
            The byte size of the public key, as an integer
        rn  r{  r-  s    r0   r|  zPublicKeyInfo.byte_size  r}  r/   c                     | j                   4t        j                  t        | d               j	                         | _         | j                   S )ze
        :return:
            The SHA1 hash of the DER-encoded bytes of this public key info
        rL   )_sha1hashlibro  r   digestr-  s    r0   ro  zPublicKeyInfo.sha1  s;     :: htL/A&BCJJLDJzzr/   c                     | j                   4t        j                  t        | d               j	                         | _         | j                   S )zh
        :return:
            The SHA-256 hash of the DER-encoded bytes of this public key info
        rL   )_sha256r  sha256r   r  r-  s    r0   r  zPublicKeyInfo.sha256  s;     <<">>(43E*FGNNPDL||r/   c                     t        d      )aZ  
        Creates a fingerprint that can be compared with a private key to see if
        the two form a pair.

        This fingerprint is not compatible with fingerprints generated by any
        other software.

        :return:
            A byte string that is a sha256 hash of selected components (based
            on the key type)
        z|asn1crypto.keys.PublicKeyInfo().fingerprint has been removed, please use oscrypto.asymmetric.PublicKey().fingerprint insteadre  r-  s    r0   r  zPublicKeyInfo.fingerprint  s     MN 	Nr/   )r)   r*   r+   r,   r  r   r-   r  r  r\  rw  r  r  r  ro   ra  r   r  r   rr  rN  ry  r|  ro  r  r  r.   r/   r0   r  r  $  s    
()	-.G
( 	&O JILEG( (TK $ $B 4 4<    * 1 1     N Nr/   r  )Hr,   
__future__r   r   r   r   r  rV   _errorsr   r	   _typesr
   r   algosr   r   r   r   r   corer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   utilr    r!   r#   r2   r5   r:   rF   rH   rO   rq   ru   rw   r~   r   r   r   r   r   r   r   r  r  r  r1  r3  r8  r;  rM  rQ  r  r  r  r  r  r  r.   r/   r0   <module>r     s   S R   ) ' o o    " /	X 	!j !	7 	H &8 H (C CL	k8 	
	~x 	
w 	  	
- 
	( 	 (h "	H 	  '! 'D"* "*J' 4B8 4Bn   , 4. &SOX SOlh h x + 6-x *qNH qNr/   