@binding.ffi_callback('int (char *, int, int, void *)', name='Cryptography_pem_password_cb')
def _pem_password_cb(buf, size, writing, userdata_handle):
 ud = _ffi.from_handle(userdata_handle)
 ud.called += 1
 if (not ud.password):
  ud.exception = TypeError('Password was not given but private key is encrypted.')
  return (-1)
 elif (len(ud.password) < size):
  pw_buf = _ffi.buffer(buf, size)
  pw_buf[:len(ud.password)] = ud.password
  return len(ud.password)
 else:
  ud.exception = ValueError('Passwords longer than {0} bytes are not supported by this backend.'.format((size - 1)))
  return 0

@ binding . ffi_callback ( 'int (char *, int, int, void *)' , name = 'Cryptography_pem_password_cb' ) def _pem_password_cb ( buf , size , writing , userdata_handle ) : ud = _ffi . from_handle ( userdata_handle ) ud . called += 1 if ( not ud . password ) : ud . exception = TypeError ( 'Password was not given but private key is encrypted.' ) return ( - 1 ) elif ( len ( ud . password ) < size ) : pw_buf = _ffi . buffer ( buf , size ) pw_buf [ : len ( ud . password ) ] = ud . password return len ( ud . password ) else : ud . exception = ValueError ( 'Passwords longer than {0} bytes are not supported by this backend.' . format ( ( size - 1 ) ) ) return 0
a pem_password_cb function pointer that copied the password to openssl as required and returns the number of bytes copied .