Spade

Mini Shell

Directory:~$ /proc/self/root/lib/python2.7/site-packages/josepy/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/lib/python2.7/site-packages/josepy/jws.pyo

�
�t0^c@s
dZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZde
fd��YZde	jfd��YZde	jfd	��YZd
e	jfd��YZde
fd
��YZedkreej��ndS(sJSON Web
Signature.i����N(tb64terrorst	json_utiltjwatjwktutilt	MediaTypecBs2eZdZdZed��Zed��ZRS(s
MediaType field
encoder/decoder.sapplication/cCs9d|kr5d|kr*tjd��n|j|S|S(sDecoder.t/t;sUnexpected
semi-colon(RtDeserializationErrortPREFIX(tclstvalue((s./usr/lib/python2.7/site-packages/josepy/jws.pytdecodes
cCs!d|kr|t|j�S|S(sEncoder.R(tlenR
(RR((s./usr/lib/python2.7/site-packages/josepy/jws.pytencodes(t__name__t
__module__t__doc__R
tclassmethodR
R(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRs
tHeadercBs�eZdZejddejjde�Z	ejdde�Z
ejddejjde�Zejdde�Z
ejdde�Zejdded	d�Zejd
dejde�Zejddejde�Zejdd
ejdejde�Zejdd
ejdejde�Zejdded	d�Zd�Zd�Zd�Zejd��Zejd��Zejd��ZRS(s6JOSE
Header.

    .. warning:: This class supports **only** Registered Header
        Parameter Names (as defined in section 4.1 of the
        protocol). If you need Public Header Parameter Names (4.2)
        or Private Header Parameter Names (4.3), you must subclass
        and override :meth:`from_json` and :meth:`to_partial_json`
        appropriately.

    .. warning:: This class does not support any extensions through
        the "crit" (Critical) Header Parameter (4.1.11) and as a
        conforming implementation, :meth:`from_json` treats its
        occurrence as an error. Please subclass if you seek for
        a different behaviour.

    :ivar x5tS256: "x5t#S256"
    :ivar str typ: MIME Media Type, inc. :const:`MediaType.PREFIX`.
    :ivar str cty: Content-Type, inc. :const:`MediaType.PREFIX`.

   
talgtdecodert	omitemptytjkuRtkidtx5utx5ctdefaulttx5tsx5t#S256ttyptencodertctytcritcs&t�fd�tj�j�D��S(s4Fields
that would not be omitted in the JSON
object.c3sB|]8\}}|jt�|��s|t�|�fVqdS(N(tomittgetattr(t.0tnametfield(tself(s./usr/lib/python2.7/site-packages/josepy/jws.pys	<genexpr>Ns	(tdicttsixt	iteritemst_fields(R'((R's./usr/lib/python2.7/site-packages/josepy/jws.pytnot_omittedLscCs�t|t|��s3tdjt|����n|j�}|j�}t|�j|�rotd��n|j|�t|�|�S(NsHeader
cannot be added to: {0}s+Addition of overlapping headers not defined(t
isinstancettypet	TypeErrortformatR,tsettintersectiontupdate(R'tothertnot_omitted_selftnot_omitted_other((s./usr/lib/python2.7/site-packages/josepy/jws.pyt__add__Rs	
cCs(|jdkr!tjd��n|jS(s�Find
key based on header.

        .. todo:: Supports only "jwk" header parameter lookup.

        :returns: (Public) key found in the header.
        :rtype: .JWK

        :raises josepy.errors.Error: if key could not be found

        sNo key
foundN(RtNoneRtError(R'((s./usr/lib/python2.7/site-packages/josepy/jws.pytfind_key`scCstjd��dS(Ns("crit"
is not supported, please
subclass(RR	(tunused_value((s./usr/lib/python2.7/site-packages/josepy/jws.pyR!oscCs8g|D]-}tjtjjtjj|j��^qS(N(tbase64t	b64encodetOpenSSLtcryptotdump_certificatet
FILETYPE_ASN1twrapped(Rtcert((s./usr/lib/python2.7/site-packages/josepy/jws.pyRwscCsGytd�|D��SWn(tjjk
rB}tj|��nXdS(Ncss<|]2}tjtjjtjjtj|���VqdS(N(RtComparableX509R>R?tload_certificateRAR<t	b64decode(R$RC((s./usr/lib/python2.7/site-packages/josepy/jws.pys	<genexpr>s(ttupleR>R?R9RR	(Rterror((s./usr/lib/python2.7/site-packages/josepy/jws.pyR|s
	(((RRRRtFieldRtJWASignaturet	from_jsontTrueRRRtJWKRRRtdecode_b64joseRtx5tS256RRR
RR
R!R,R7R:RR(((s./usr/lib/python2.7/site-packages/josepy/jws.pyR&s.!			t	SignaturecBseZdZeZdZejddedd�Z	ejddede�dej
�Zejddejd	ej
�Ze	jd
��Z	e	jd��Z	d�Zed
��Zed��Zdd�Zeee�d��Zd�Zed��ZRS(sJWS
Signature.

    :ivar combined: Combined Header (protected and unprotected,
        :class:`Header`).
    :ivar unicode protected: JWS protected header (Jose Base-64 decoded).
    :ivar header: JWS Unprotected Header (:class:`Header`).
    :ivar str signature: The signature.

   
tcombinedt	protectedRRttheaderRt	signatureRcCstj|jd��S(Nsutf-8(Rtencode_b64joseR(R((s./usr/lib/python2.7/site-packages/josepy/jws.pyRR�scCstj|�jd�S(Nsutf-8(RRNR
(R((s./usr/lib/python2.7/site-packages/josepy/jws.pyRR�scKs8d|kr|j|�}ntt|�j|�dS(NRQ(t_with_combinedtsuperRPt__init__(R'tkwargs((s./usr/lib/python2.7/site-packages/josepy/jws.pyRY�scCsk|jd|jdj�}|jd|jdj�}|rW||jj|�}n|}||d<|S(NRTRRRQ(tgetR+Rt
header_clst
json_loads(RRZRTRRRQ((s./usr/lib/python2.7/site-packages/josepy/jws.pyRW�s
cCs'tj|jd��dtj|�S(Nsutf-8t.(RR=R(RRRtpayload((s./usr/lib/python2.7/site-packages/josepy/jws.pyt_msg�sc	CsX|dkr|jj�n|}|jjjd|jd|jd|j|j|��S(sEVerify.

        :param JWK key: Key used for verification.

       
tkeytsigtmsgN(	R8RQR:RtverifyRaRUR`RR(R'R_Ra((s./usr/lib/python2.7/site-packages/josepy/jws.pyRd�s!cKs�|}||d<|r)|j�|d<ni}x0|D](}	|	|kr6|j|	�||	<q6q6W|r�|j|�j�}
nd}
|j|�}	|j|j|j|
|��}|d|
d|	d|�S(s;Sign.

        :param JWK key: Key for signature.

        RRRSRRRTRU(t
public_keytpopR\t
json_dumpstsignRaR`(RR_RaRtinclude_jwktprotectRZt
header_paramstprotected_paramsRTRRRU((s./usr/lib/python2.7/site-packages/josepy/jws.pyRh�s


!cCs3tt|�j�}|dj�s/|d=n|S(NRT(RXRPtfields_to_partial_jsonR,(R'tfields((s./usr/lib/python2.7/site-packages/josepy/jws.pyRm�s
cCsStt|�j|�}|j|�}d|dj�krOtjd��n|S(NRRQsalg
not
present(RXRPtfields_from_jsonRWR,RR	(RtjobjRntfields_with_combined((s./usr/lib/python2.7/site-packages/josepy/jws.pyRo�s
(scombinedN(RRRRR\t	__slots__RRIRLRRRKRTRNRVRURRRYRRWR`R8Rdt	frozensetRhRmRo(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRP�s*			tJWScBsweZdZd
ZeZdd�Zed��Z	e
d��Zd�Zed��Z
ed�Zed	��ZRS(sgJSON Web
Signature.

    :ivar str payload: JWS Payload.
    :ivar str signature: JWS Signatures.

    R_t
signaturescs
t��fd��jD��S(sVerify.c3s$|]}|j�j��VqdS(N(RdR_(R$Rb(RaR'(s./usr/lib/python2.7/site-packages/josepy/jws.pys	<genexpr>s(tallRu(R'Ra((RaR's./usr/lib/python2.7/site-packages/josepy/jws.pyRdscKs(|d|d|jjd||�f�S(sSign.R_Ru(t
signature_clsRh(RR_RZ((s./usr/lib/python2.7/site-packages/josepy/jws.pyRhscCs|jdS(sPGet
a singleton signature.

        :rtype: :class:`JWS.signature_cls`

       
i(Ru(R'((s./usr/lib/python2.7/site-packages/josepy/jws.pyRU
scCsGtj|jjjd��dtj|j�dtj|jj�S(s7Compact
serialization.

        :rtype: bytes

       
sutf-8R^(RR=RURRRR_(R'((s./usr/lib/python2.7/site-packages/josepy/jws.pyt
to_compacts3cCs�y|jd�\}}}Wn tk
r>tjd��nX|jdtj|�jd�dtj|��}|dtj|�d|f�S(sACompact
deserialization.

        :param bytes compact:

        R^sOCompact JWS serialization should comprise of exactly 3
dot-separated componentsRRsutf-8RUR_Ru(tsplitt
ValueErrorRR	RwRRFR
(RtcompactRRR_RURb((s./usr/lib/python2.7/site-packages/josepy/jws.pytfrom_compact)s

	cCsgtj|j�}|rNt|j�dkrN|jdj�}||d<|Si|d6|jd6SdS(NiiR_Ru(RRVR_RRutto_partial_json(R'tflatR_tret((s./usr/lib/python2.7/site-packages/josepy/jws.pyR}<s
c	s�d|kr*d|kr*tjd��nzd|krj�dtj|jd��d�jj|�f�S�dtj|d�dt�fd�|dD���SdS(NRURusFlat
mixed with
non-flatR_c3s!|]}�jj|�VqdS(N(RwRK(R$Rb(R(s./usr/lib/python2.7/site-packages/josepy/jws.pys	<genexpr>Ss(RR	RRNRfRwRKRG(RRp((Rs./usr/lib/python2.7/site-packages/josepy/jws.pyRKJs(spayloads
signaturesN(RRRRrRPRwR8RdRRhtpropertyRURxR|RLR}RK(((s./usr/lib/python2.7/site-packages/josepy/jws.pyRt�s
	tCLIcBskeZdZed��Zed��Zed��Zed��Zed��Zedd��Z
RS(sJWS CLI.c
Cs�|jjj|jj��}|jj�|jdkrFg|_n|jrb|jj	d�nt
jdtj
j�j�d|d|jdt|j��}|jr�tj|j�jd��ntj|j��dS(sSign.RR_RaRjsutf-8N(RtktytloadRatreadtcloseRjR8R{tappendRtRhtsyststdinRR1R)tprint_RxR
tjson_dumps_pretty(RtargsRaRb((s./usr/lib/python2.7/site-packages/josepy/jws.pyRhZs
	-	cCs�|jr*tjtjj�j��}nCytjtjj��}Wn$tj	k
rl}t
j|�dSX|jdk	r�|jj|jj��j�}|jj�nd}tjj|j�|jd|�S(sVerify.i����RaN(R{RtR|R�R�R�RR]RR9R)R�RaR8R�R�ReR�tstdouttwriteR_Rd(RR�RbRHRa((s./usr/lib/python2.7/site-packages/josepy/jws.pyRdls	!
!cCstjj|�S(N(RRJRK(Rtarg((s./usr/lib/python2.7/site-packages/josepy/jws.pyt	_alg_type�scCs|S(N((RR�((s./usr/lib/python2.7/site-packages/josepy/jws.pyt_header_type�scCstjj|S(N(RRMtTYPES(RR�((s./usr/lib/python2.7/site-packages/josepy/jws.pyt	_kty_type�scCsN|dkrtjd}ntj�}|jddd�|j�}|jd�}|jd|j	�|jddd	tj
d
�dt�|jdd
d	|jdt
j�|jddddd	|j�|jd�}|jd|j�|jddd	tj
d
�dt�|jdd	|jdt�|j|�}|j|�S(s Parse
arguments and sign/verify.is	--compacttactiont
store_trueRhtfuncs-ks--keyR.trbtrequireds-as--algRs-ps	--protectR�Rds--ktyN(R8R�targvtargparsetArgumentParsertadd_argumenttadd_subparserst
add_parsertset_defaultsRhtFileTypeRLR�RtRS256R�RdtFalseR�t
parse_argsR�(RR�tparsert
subparserstparser_signt
parser_verifytparsed((s./usr/lib/python2.7/site-packages/josepy/jws.pytrun�s*N(RRRRRhRdR�R�R�R8R�(((s./usr/lib/python2.7/site-packages/josepy/jws.pyR�Wst__main__(RR�R<R�R>R)tjosepyRRRRRRtobjectRtJSONObjectWithFieldsRRPRtR�RtexitR�(((s./usr/lib/python2.7/site-packages/josepy/jws.pyt<module>s.`r_V