def _EMSA_PKCS1_V1_5_ENCODE(msg_hash, emLen, with_hash_parameters=True):
 digestAlgo = DerSequence([DerObjectId(msg_hash.oid).encode()])
 if with_hash_parameters:
  digestAlgo.append(DerNull().encode())
 digest = DerOctetString(msg_hash.digest())
 digestInfo = DerSequence([digestAlgo.encode(), digest.encode()]).encode()
 if (emLen < (len(digestInfo) + 11)):
  raise TypeError(('Selected hash algorith has a too long digest (%d bytes).' % len(digest)))
 PS = (bchr(255) * ((emLen - len(digestInfo)) - 3))
 return (((b('\x00\x01') + PS) + bchr(0)) + digestInfo)

def _EMSA_PKCS1_V1_5_ENCODE ( msg_hash , emLen , with_hash_parameters = True ) : digestAlgo = DerSequence ( [ DerObjectId ( msg_hash . oid ) . encode ( ) ] ) if with_hash_parameters : digestAlgo . append ( DerNull ( ) . encode ( ) ) digest = DerOctetString ( msg_hash . digest ( ) ) digestInfo = DerSequence ( [ digestAlgo . encode ( ) , digest . encode ( ) ] ) . encode ( ) if ( emLen < ( len ( digestInfo ) + 11 ) ) : raise TypeError ( ( 'Selected hash algorith has a too long digest (%d bytes).' % len ( digest ) ) ) PS = ( bchr ( 255 ) * ( ( emLen - len ( digestInfo ) ) - 3 ) ) return ( ( ( b ( '\x00\x01' ) + PS ) + bchr ( 0 ) ) + digestInfo )
implement the emsa-pkcs1-v1_5-encode function .