NPc@sdZddlZddlZddlZddlZddlZddlZdZdefdYZ de fdYZ de fd YZ d e fd YZ d e fd YZ dS(sm A Reader supports reading metadata and key info for key sets. @author: arkajit.dey@gmail.com (Arkajit Dey) iNcCsQtjx-tjD]}|j|}|r|SqWtjd|dS(sFactory function for Reader's @param location: where (file, uri, etc) the reader should read from @type location: string s:Unable to create a reader for %s. Does the location exist?N(tutiltImportBackendstReadert__subclasses__t CreateReaderterrorst KeyczarError(tlocationtsctreader((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRs RcBs\eZdZejZejdZejdZejdZ e dZ RS(s:Interface providing supported methods (no implementation).cCsdS(s Return the KeyMetadata for the key set being read. @return: JSON string representation of KeyMetadata object @rtype: string @raise KeyczarError: if unable to read metadata (e.g. IOError) N((tself((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyt GetMetadata3s cCsdS(s= Return the key corresponding to the given version. @param version_number: the version number of the desired key @type version_number: integer @return: JSON string representation of a Key object @rtype: string @raise KeyczarError: if unable to read key info (e.g. IOError) N((R tversion_number((s3/usr/lib/python2.7/site-packages/keyczar/readers.pytGetKey?s cCsdS(sR Clean up this reader @raise KeyczarError: if error during close N((R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pytCloseNscCstd|dS(s Return an instance of this class if it handles the location @param location: where (file, uri, etc) the reader should read from @type location: string s6CreateReader() class method MUST be implemented for:%sN(tNotImplementedError(tclsR((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRWs( t__name__t __module__t__doc__RtABCMetat __metaclass__tabstractmethodR R Rt classmethodR(((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR.s    t FileReadercBsAeZdZdZdZdZdZedZRS(s&Reader that reads key data from files.cCs ||_dS(N(t _location(R R((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyt__init__dscCstjtjj|jdS(Ntmeta(RtReadFiletostpathtjoinR(R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR gscCs%tjtjj|jt|S(N(RRRRRRtstr(R R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR jscCsdS(N((R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRmscCs+d}tjj|r't|}n|S(N(tNoneRRtexistsR(RRtresult((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRqs( RRRRR R RRR(((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRas     tStaticKeyReadercBsAeZdZdZdZdZdZedZRS(s Reader that returns a static keycCsJ||_tjd||j|_|jjtjdtjt dS(NtImportedi( t_keytkeydatat KeyMetadatattypet_metat AddVersiont KeyVersiontkeyinfotPRIMARYtFalse(R tkeytpurpose((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR{s cCs t|jS(N(R R*(R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR scCs t|jS(N(R R&(R R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR scCsdS(N((R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRscCsdS(N((RR((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRs( RRRRR R RRR(((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR$xs     tEncryptedReadercBsAeZdZdZdZdZdZedZRS(s0Reader that reads encrypted key data from files.cCs||_||_dS(N(t_readert_crypter(R R tcrypter((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRs cCs |jjS(N(R3R (R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR scCs|jj|jj|S(N(R4tDecryptR3R (R R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR scCsdS(N((R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRscCsdS(N((RR((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRs( RRRRR R RRR(((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR2s     t MockReadercBseZdZedZedZdZdZdZ dZ dZ dZ dd Zd Zd Zd Zd ZedZRS(s&Mock reader used for testing Keyczart.cCs:tj|||||_d|_i|_i|_dS(N(R'R(tkmdR!tpubkmdtkeystpubkeys(R tnameR1tkey_typet encrypted((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRs  cCs t|jS(N(tlenR:(R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pytnumkeysscCs t|jS(N(R R8(R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR scCs<yt|j|SWn tk r7tjdnXdS(NsUnrecognized Version Number(R R:tKeyErrorRR(R R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyR s cCs|jj|jS(N(R8t GetVersiontstatus(R R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyt GetStatusscCsdS(N((R ((s3/usr/lib/python2.7/site-packages/keyczar/readers.pyRscCs||j|s       3