3 l_o@sddlmZmZmZddlZddlZddlmZddlm Z ddl m Z ej ej GdddeZdd Zd d Zd d ZddZddZGdddeZejeGdddeZejeGdddeZGdddeZejeGdddeZejeGdddeZdS))absolute_importdivisionprint_functionN)utils)AlreadyFinalized)libc@s(eZdZejddZejddZdS)PaddingContextcCsdS)zR Pads the provided bytes and returns any available data as bytes. N)selfdatar r /usr/lib64/python3.6/padding.pyupdateszPaddingContext.updatecCsdS)z6 Finalize the padding, returns bytes. Nr )r r r r finalizeszPaddingContext.finalizeN)__name__ __module__ __qualname__abcabstractmethodr rr r r r rsrcCs8d|kodkns td|ddkr4tddS)Nriz%block_size must be in range(0, 2041).z#block_size must be a multiple of 8.) ValueError) block_sizer r r _byte_padding_checks rcCsh|dkrtdtjd||t|7}t||d}|d||d}|||dd}||fS)NzContext was already finalized.r r)rr_check_byteslikebyteslen)buffer_r rfinished_blocksresultr r r _byte_padding_update's  rcCs,|dkrtd|dt|}|||S)NzContext was already finalized.r)rr)rrZ paddingfnpad_sizer r r _byte_padding_pad7sr cCsr|dkrtdtjd||t|7}tt||ddd}|d||d}|||dd}||fS)NzContext was already finalized.r rr)rrrrmaxr)rr rrrr r r _byte_unpadding_update?s  r#cCs\|dkrtdt||dkr(td|||d}|sBtdtj|d}|d| S)NzContext was already finalized.rzInvalid padding bytes.r!)rrrsixZ indexbytes)rrZcheckfnZvalidrr r r _byte_unpadding_checkOs r&c@s$eZdZddZddZddZdS)PKCS7cCst|||_dS)N)rr)r rr r r __init__`szPKCS7.__init__cCs t|jS)N)_PKCS7PaddingContextr)r r r r padderdsz PKCS7.paddercCs t|jS)N)_PKCS7UnpaddingContextr)r r r r unpaddergszPKCS7.unpadderN)rrrr(r*r,r r r r r'_sr'c@s,eZdZddZddZddZddZd S) r)cCs||_d|_dS)N)r_buffer)r rr r r r(msz_PKCS7PaddingContext.__init__cCst|j||j\|_}|S)N)rr.r)r r rr r r r rsz_PKCS7PaddingContext.updatecCstj||S)N)r%int2byte)r sizer r r _paddingxsz_PKCS7PaddingContext._paddingcCst|j|j|j}d|_|S)N)r r.rr1)r rr r r r{sz_PKCS7PaddingContext.finalizeN)rrrr(r r1rr r r r r)ksr)c@s$eZdZddZddZddZdS)r+cCs||_d|_dS)Nr-)rr.)r rr r r r(sz_PKCS7UnpaddingContext.__init__cCst|j||j\|_}|S)N)r#r.r)r r rr r r r sz_PKCS7UnpaddingContext.updatecCst|j|jtj}d|_|S)N)r&r.rrZ Cryptography_check_pkcs7_padding)r rr r r rsz_PKCS7UnpaddingContext.finalizeN)rrrr(r rr r r r r+sr+c@s$eZdZddZddZddZdS)ANSIX923cCst|||_dS)N)rr)r rr r r r(szANSIX923.__init__cCs t|jS)N)_ANSIX923PaddingContextr)r r r r r*szANSIX923.paddercCs t|jS)N)_ANSIX923UnpaddingContextr)r r r r r,szANSIX923.unpadderN)rrrr(r*r,r r r r r2sr2c@s,eZdZddZddZddZddZd S) r3cCs||_d|_dS)Nr-)rr.)r rr r r r(sz _ANSIX923PaddingContext.__init__cCst|j||j\|_}|S)N)rr.r)r r rr r r r sz_ANSIX923PaddingContext.updatecCstjd|dtj|S)Nrr!)r%r/)r r0r r r r1sz _ANSIX923PaddingContext._paddingcCst|j|j|j}d|_|S)N)r r.rr1)r rr r r rsz _ANSIX923PaddingContext.finalizeN)rrrr(r r1rr r r r r3sr3c@s$eZdZddZddZddZdS)r4cCs||_d|_dS)Nr-)rr.)r rr r r r(sz"_ANSIX923UnpaddingContext.__init__cCst|j||j\|_}|S)N)r#r.r)r r rr r r r sz _ANSIX923UnpaddingContext.updatecCst|j|jtj}d|_|S)N)r&r.rrZ#Cryptography_check_ansix923_padding)r rr r r rs z"_ANSIX923UnpaddingContext.finalizeN)rrrr(r rr r r r r4sr4)Z __future__rrrrr%Z cryptographyrZcryptography.exceptionsrZ%cryptography.hazmat.bindings._paddingrZ add_metaclassABCMetaobjectrrrr r#r&r'Zregister_interfacer)r+r2r3r4r r r r s,