��Pc@s�dZddlZddlZddlZddlmZmZmZmZddlm Z
ddlmZiZ
eje
�ZdZdefd��YZd �Zd
�Zd�Zedged
��d��Zedged��d��Zd�Zedddded�fddded�fddded�fddded�ed �fd!d"ded#�ed$�fgejed%��d&��Zd'�ZdS((s&commands to sign and verify changesetsi�N(tutiltcommandstmatchtcmdutil(tnode(t_tinternaltgpgcBs&eZdd�Zd�Zd�ZRS(cCs&||_|rd|pd|_dS(Ns --local-user "%s"t(tpathtkey(tselfR R
((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyt__init__s cCs&d|j|jf}tj||�S(Ns%s --sign --detach-sign%s(R R
Rtfilter(Rtdatatgpgcmd((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytsignsc CsSd }}z�tjdddd�\}}tj|d�}|j|�|j�tjdddd�\}}tj|d�}|j|�|j�d|j||f}tj d|�}Wd xB||fD]4} y| r�j
| �nWq�tk
rq�Xq�WXg}
d\}}d}
x�j�D]�|j
d
�sMq2n|d}|j
d�rvtd
�}
Pq2|j
d�r�|j�d}q2|j
d�s�|j
d�s�|j
d�s�|j
d�r2|d k r�j||g�n|jdd�}d }q2q2W|
r&|
gfS|d k rI|
j||g�n|
|
fS(s' returns of the good and bad signaturestprefixshg-gpg-tsuffixs.sigtwbs.txts1%s --logger-fd 1 --status-fd 1 --verify "%s" "%s"RNs[GNUPG:]i tERRSIGserror while verifying signaturetVALIDSIGi
tGOODSIGtEXPSIGt EXPKEYSIGtBADSIGt i(NN(tNonettempfiletmkstemptostfdopentwritetcloseR RR
tunlinktOSErrort
splitlinest
startswithRtsplittappend(RRtsigtsigfiletdatafiletfdtfpRtrettftkeysR
tfingerprintterrtl((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytverifysX
N(t__name__t
__module__RRRR3(((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyRs cKsO|jddd�}|jd�}|sB|jddd�}nt||�S(screate a new gpg instanceRtcmdR
N(tconfigtgetRR(tuitoptstgpgpathtgpgkey((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytnewgpgNs
ccs�d�}|jd�}x[t|j��D]G}dtj|�}x+||j|�j�|�D]}|VqcWq+Wy2d}x%||j|�|�D]}|Vq�WWntk
r�nXdS(sb
walk over every sigs, yields a couple
((node, version, sig), (filename, linenumber))
cssNd}xA|D]9}|sq
n|jdd�||ffV|d7}q
WdS(NiRi(R&(tfileitertcontexttlnR2((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyt parsefile[s
s.hgsigss
.hgsigs|%st localsigsN( tfiletreversedtheadsthgnodetshorttreadR$topenertIOError(trepoRAtfltrtfntitem((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytsigwalkVs %
cCss|\}}|\}}} d||f}
tj|�}t|||�}tj| �} |j|| �\}}
|r�|jd|||f�d
Sg}x�|
D]�}|ddkr�jt d�|
|df�q�n|ddkr|jt d�|
|df�n4|dd krI|jt d
�|
|df�n|j
|d|d|df�q�W|S(sget the keys who signed a datas%s:%ds %s:%d %s
iRs%s Bad signature from "%s"
iRs1%s Note: Signature has expired (signed by: "%s")
Rs0%s Note: This key has expired (signed by: "%s")
iiN(RFtbintnode2txttbinasciit
a2b_base64R3twarnRR RR'(R9RKtmygpgtsigdataR?RNR@RtversionR(RRR1R/t validkeysR
((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytgetkeysqs.
!&tsigsshg sigscCsct|�}i}x�t|�D]�\}}|\}}}|\} }
y|j|�}Wn1tk
r�|jtd�| |
f�qnX|jj|�}t|||||�}
|
s�qn|j |g�||j
|
�qWxtt|dt�D]`}xW||D]K}d|t
j|jj|��f}|jdt||�|f�qWq�S(slist signed changesetss%s:%d node does not exist
treverses%5d:%ss %-30s %s
N(R=RPtlookuptKeyErrorRURt changelogtrevRZt
setdefaulttextendtsortedtTrueRFthexRR tkeystr(R9RKRVtrevsRR?RRXR(RNR@tnRMR/R`tk((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyR[�s(
%tsigcheckshg sigcheck REVc
Cst|�}|j|�}tj|�}g}xft|�D]X\}}|\}} }
||kr=t|||||�}|r�|j|�q�q=q=W|s�|jtd�tj |��dS|jdtj |��x(|D] }|jdt
||��q�dS(s@verify all the signatures there may be for a particular revisionsno valid signature for %s
Ns%s is signed by:
s %s
(R=R]RFReRPRZRbR RRGRf(
R9RKR`RVthexrevR/RR?RRXR(RiR
((s-/sys/lib/python2.7/site-packages/hgext/gpg.pytcheck�s
cCs@|\}}}|jd|d�}|r8d||fS|SdS(s/associate a string to a key (username, comment)Rs%s (%s)N(R7R(R9R
tkeyidtuserR0tcomment((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyRf�s
RR2tlocalsmake the signature localR.tforces$sign even if the sigfile is modifiedRs no-commits'do not commit the sigfile after signingRiR
sthe key id to sign withtIDtmtmessagescommit messagetTEXTshg sign [OPTION]... [REV]...cOs3t||�}d}d}|jd�}|rFtj|�|d<n|rqg|D]}|j|�^qS} nvg|jj�D]}
|
tjkr�|
^q�} t | �dkr�tj
td���n| s�jj
�g} nx�| D]�}tj|�}|jtd�|jj|�tj|�f�t|||�}|j|�}
|
sttj
td���ntj|
�}
|
jdd�}
|d |||
f7}q�|d
r�|jjd|�dStj|jdd
g�}|jd|dtdt�d }tj|�r@|dr@tj
td���n|jd
d�}|j|�|j �d
|jkr�|dj"d
g�n|dr�dS|d}|s�dj#g| D]}dtj|�^q��}ny%|j$||d|dd|�Wn(t%k
r.}tj
t&|���nXdS(s�add a signature for the current or given revision
If no revision is given, the parent of the working directory is used,
or tip if no revision is checked out.
See :hg:`help dates` for a list of formats valid for -d/--date.
t0Rtdateis6uncommitted merge - please provide a specific revisionssigning %d:%s
serror while signings
s %s %s %s
RpRBNs.hgsigsRtunknowntignorediRqsRworking copy of .hgsigs is changed (please commit .hgsigs manually or use --force)tabt no_commitRts Added signature for changeset %sRn('R=R8Rt parsedateR]tdirstatetparentsRFtnullidtlentAbortRR_ttipReR R`RGRRRRSt
b2a_base64treplaceRIR'RtexacttroottstatusRdtanytwfileR!Rtaddtjointcommitt
ValueErrortstr(R9RKRgR:RVtsigvert
sigmessageRwRhtnodesRthexnodeRR(tmsigststsigsfileRttinst((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyR�s^%
"
)%cCs6|dkrdtj|�Stjtd���dS(smap a manifest into some textRvs%s
sunknown signature versionN(RFReRR�R(RKRtver((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyRRs(t__doc__RRRSt mercurialRRRRRRFtmercurial.i18nRtcmdtabletcommandt
testedwithtobjectRR=RPRZR[RlRfRtcommitopts2RRR(((s-/sys/lib/python2.7/site-packages/hgext/gpg.pyt<module>s2$"= !! K
|